简体   繁体   中英

How to add multiple destinations for a java application in cloud foundry?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM