Exercise: Deploying Java Spring Application to SAP BTP

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Deploying Java Spring application to SAP BTP

Deploying Java Spring 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:

  1. Execute the following exercises:
    • Creating your free trial account in SAP BTP
    • Complete the exercise Activating the APIs in SAP S/4HANA Cloud
  2. 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 snippet
    cd ~/projects
    git clone https://github.com/SAP-samples/cloud-sdk-learning-journey.git
    Expand
  3. Choose FileOpen Folder and open the /home/user/projects/cloud-sdk-learning-journey/ folder.

Steps

  1. Checkout the branch javaspring_v5.0_deploytocf .

    1. Checkout the javaspring_v5.0_deploytocf Git branch by running the following commands in the terminal:

      Code snippet
      cd ~/projects/cloud-sdk-learning-journey
      git checkout -f javaspring_v5.1_deploytocf
      Expand
  2. Create a destination named mydestination in the SAP BTP subaccount with the following values

    FieldValue
    Namemydestination
    TypeHTTP
    URLhttps://sandbox.api.sap.com/s4hanacloud
    Proxy TypeInternet
    AuthenticationNoAuthentication
    1. In the SAP BTP Cockpit, access your Subaccount overview and navigate to ConnectivityDestinations

    2. Create a new destination using the given info, as indicated in the following figure.

  3. Login to Cloud Foundry, iusing the terminal

    1. Make sure you have the API Endpoint, the email and the Password of your Cloud Foundry account.

    1. In the terminal, run

      Code snippet
      cf login
      Expand

      Enter the required information and make sure that login is successful.

  4. Build and push the project to SAP BTP

    1. 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 snippet
      cd 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 
      Expand
      Note
      Since the application depends on xsuaa and destination service, we need to create an instance of these services before deploying the application.
    2. Verify that the application is successfully deployed in SAP BTP and the myxsuaa and mydestination services are bound to the application

  5. Query the Business Partner API of SAP S/4HANA Cloud

    1. 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 FoundrySpacesDevbpstandardvdmApplication Routes

    2. Open a new tab and browse to https://APPLICATION_URL/businessPartners; APPLICATION_URL is the URL you copied after executing the cf push command

    3. 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
  6. Optional: Review code in the following source files

    1. Code walk-through

      File nameComments on code changes
      BusinessPartnerController.java

      Code logic is as follows...

      1. 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...

      1. Provide basic application information like name, memory, timeout, path etc.
      2. Specify that the application depends on myxsuaa and mydestination services
      requests.httpProvides various HTTP requests that can be submitted to query the Business Partner API
      commands.txtProvides various commands that can be run on the terminal

Log in to track your progress & complete quizzes