Skip to Content
0
Jul 09, 2020 at 07:37 AM

SAP Cloud Platform - Get Application destinations with Java

217 Views Last edit Jul 09, 2020 at 08:30 AM 2 rev

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.