cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Cloud Platform - Get Application destinations with Java

0 Kudos

Hi dear experts!

Our Java application deployed on SAP Cloud Platform. Destinations configured with Cockpit. There's a need to get destinations from subaccount level and from application level.

We figured out how to get destinations from subaccount level, like this:

Context ctx = new InitialContext();
ConnectivityConfiguration configuration = (ConnectivityConfiguration) ctx.lookup("java:comp/env/connectivityConfiguration");
				  
TenantContext tenantContext = (TenantContext) ctx.lookup("java:comp/env/TenantContext");
					  
String accountId = tenantContext.getTenant().getAccount().getId();
Map<String, DestinationConfiguration> destConfigurations = configuration.getConfigurations(accountId);

Resources are defined in web.xml, like this:

  <resource-ref>
    <res-ref-name>connectivityConfiguration</res-ref-name>
    <res-type>com.sap.core.connectivity.api.configuration.ConnectivityConfiguration</res-type>
  </resource-ref>
  <resource-ref>
    <res-ref-name>Account</res-ref-name>
    <res-type>com.sap.cloud.account.Account</res-type>
  </resource-ref>
  <resource-ref>
    <res-ref-name>TenantContext</res-ref-name>
    <res-type>com.sap.cloud.account.TenantContext</res-type>
  </resource-ref>

But how do I get destination list from application level?

Thank you!

UPD: I found that we can get the destination from application and subaccount by its name:

Context ctx = new InitialContext();
DestinationFactory destinationFactory =(DestinationFactory)ctx.lookup(DestinationFactory.JNDI_NAME);
HttpDestination destination = (HttpDestination) destinationFactory.getDestination("myBackend");

But in my case we don't know names of destinations. I still don't know the way we can get list of all destinations from subaccount and application level.

Accepted Solutions (1)

Accepted Solutions (1)

AntalP
Product and Topic Expert
Product and Topic Expert

Hi Inna,

The destination lookup order is described in the help :

https://help.sap.com/viewer/b865ed651e414196b39f8922db2122c7/Cloud/en-US/b068356dd7c34cf7ad6b6023dee...

The runtime tries to resolve a destination in the order: Subscription Level → Subaccount Level → Application Level. By using the optional "DestinationProvider" property, a destination can be limited to application level only, that is, the runtime tries to resolve the destination on application level.

Only the application level access can be defined.

Best regards,

Antal

Answers (0)