Deploying application to SAP BTP
In this exercise, you will learn how to deploy the application to SAP BTP.
Prerequisites
For the complete execution of current exercise, you must execute the following activities first, using SAP Business Application Studio:
- Execute the following exercises:
- Create your Pay-As-You-Go Account in SAP BTP
- Complete the exercise Activating the APIs in SAP S/4HANA Cloud
- Run the following commands in a terminal, in case you didn't do it already in previous exercises, to clone the Git repository for the course:Code snippetExpand
cd ~/projects git clone https://github.com/SAP-samples/cloud-sdk-learning-journey.git
- Choose File → Open Folder and open the
/home/user/projects/cloud-sdk-learning-journey/
folder.
Steps
Checkout the branch javaspring_v5.0_deploytocf .
Run the following commands in the terminal. Make sure current working directory is /home/user/projects/cloud-sdk-learning-journey.
Code snippetExpandcd ~/projects/cloud-sdk-learning-journey git checkout -f javaspring_v5.0_deploytocf
Login to Cloud Foundry, iusing the terminal
Make sure you have the API Endpoint, the email and the Password of your Cloud Foundry account.
In the terminal, run
Enter the required information and make sure that login is successful.
Build and push the project to SAP BTP
In the SAP BTP Cockpit, access your Subaccount overview and navigate to Connectivity → Destinations
Create a destination named mydestination in the SAP BTP subaccount with the following values
Build and push the application to SAP BTP by running the following commands in the terminal, replace YOUR_APIKEY_GOES_HERE with your API Key, eventually get your API Key at https://api.sap.com/api/API_BUSINESS_PARTNER/overview):
Code snippetExpandcd bpstandardvdm mvn clean install -Dmaven.test.skip=true cf create-service destination lite mydestination cf create-service xsuaa application myxsuaa cf push cf set-env bpstandardvdm API_KEY YOUR_APIKEY_GOES_HERE cf restage bpstandardvdm
Note
You will have to login to your SAP BTP Cloud Foundry account before running the cf commands. Since the application depends on xsuaa and destination service, we need to create an instance of these services before deploying the applicationVerify that the application is successfully deployed in SAP BTP and the myxsuaa and mydestination services are bound to the application
Query the Business Partner API of SAP S/4HANA Cloud
Find out the URL of the application. After successful completion of the command cf push, the URL is displayed on the screen
You can find the same URL in the subaccount overview, navigating to Cloud Foundry → Spaces → Dev → bpstandardvdm → Application Routes
Open a new tab and browse to https://<application URL>/businessPartners; <application URL> is the URL you copied after executing the cf push command
Verify that you are able to retrieve all the business partners
Note
The destination values can be modified to connect to an actual SAP S/4HANA Cloud system. Also, the SAP API Business Hub does not support CREATE, UPDATE operations
Optional: Review code in the following source files
Code walk-through
File name Comments on code changes BusinessPartnerController.java Code logic is as follows...
- Create a variable named destination of type HttpDestination using the getDestination static method of the DestinationAccessor class by passing the name of the destination
- GetBusinessPartnersCommand.java
- GetBusinessPartnerCommand.java
- CreateBusinessPartnerCommand.java
- UpdateBusinessPartnerCommand.java
- DeleteBusinessPartnerCommand.java
Read the APIKEY using an environment variable manifest.yml Configuration values are as follows...
- Provide basic application information like name, memory, timeout, path etc.
- Specify that the application depends on myxsuaa and mydestination services
requests.http Provides various HTTP requests that can be submitted to query the Business Partner API commands.txt Provides various commands that can be run on the terminal
Optional: Manually create the project. The following steps create an exact replica of the project you just checked out using Git.
Note
Before you execute this step, you must execute the corresponding optional step, described in the previous Implementing CRUD operations in a Java Spring application exercise.Create or update the following files in the table below
File name Type Contents BusinessPartnerController.java Path: ~/projects/bpstandardvdm/application/src/main/java/com/sap/cloud/sdk/tutorial/controllers
Modified Copy contents from here...
GetBusinessPartnersCommand.java Path: ~/projects/bpstandardvdm/application/src/main/java/com/sap/cloud/sdk/tutorial/utils
Modified Copy contents from here...
GetBusinessPartnerCommand.java Path: ~/projects/bpstandardvdm/application/src/main/java/com/sap/cloud/sdk/tutorial/utils
Modified Copy contents from here...
CreateBusinessPartnerCommand.java Path: ~/projects/bpstandardvdm/application/src/main/java/com/sap/cloud/sdk/tutorial/utils
Modified Copy contents from here...
UpdateBusinessPartnerCommand.java Path: ~/projects/bpstandardvdm/application/src/main/java/com/sap/cloud/sdk/tutorial/utils
Modified Copy contents from here...
DeleteBusinessPartnerCommand.java Path: ~/projects/bpstandardvdm/application/src/main/java/com/sap/cloud/sdk/tutorial/utils
Modified Copy contents from here...
manifest.yml Path: ~/projects/bpstandardvdm
Modified Copy contents from here...
Build and run the project in
projects/bpstandardvdm
in the same exact way you did in the previous steps with project inprojects/cloud-sdk-learning-journey/bpstandardvdm
.