How to add multiple destinations for a java applic

2019-08-21 13:30发布

问题:

I developed a Java application using S4Hana SDK. After deploying the application to SAP Cloud platform, I set the destinations as an environment variable with below command.

cf set-env firstapp destinations '[{name: "ErpQueryEndpoint", url: "https://URL", username: "USER", password: "PASSWORD"}]'

Now, I would like to add a second destination for the same application. Can someone please help me?

Thanks, Sankeerth

回答1:

You can define multiple destinations in the environment variable. It is a JSON array.

cf set-env firstapp destinations '[{name: "ErpQueryEndpoint", url: "https://URL", username: "USER", password: "PASSWORD"},{name: "ErpQueryEndpoint2", url: "https://URL", username: "USER", password: "PASSWORD"}]'

In the execute method in the virtual data model you can define which destination to use:

BusinessPartnerService service = new DefaultBusinessPartnerService();

final List<BusinessPartner> businessPartners =
        service.getAllBusinessPartner().execute(new ErpConfigContext("ErpQueryEndpoint2"));

However, better than using the environment variables is to use the destination service.

Step 4 of the SDK tutorials explains how to use this service: https://blogs.sap.com/2017/05/21/step-4-with-sap-s4hana-cloud-sdk-calling-an-odata-service/

With that it is even possible to have destination configurations per tenant.