I am trying to retrieve the details of a destination using the APIs provided by SAP Cloud SDK for JAVA. I have added the following annotations to our Spring Boot application:
@ComponentScan(basePackages = {"com.sap.cloud.sdk", "path to my package"}, excludeFilters = {@ComponentScan.Filter(type = CUSTOM, classes = TypeExcludeFilter.class)})
@ServletComponentScan({"com.sap.cloud.sdk", "path to my package"})
@SpringBootApplication()
public class ActionApplication {
public static void main(final String[] args) {
SpringApplication.run(ActionApplication.class, args);
}
}
The SpringBoot application internally uses a JAVA library developed by us. The code for fetching the destination details is present in this library:
public static Destination getDestination() {
Tenant consumerTenant = TenantAccessor.getCurrentTenant();
return TenantAccessor.executeWithTenant(consumerTenant,
() -> DestinationAccessor.getDestination(destinationName));
}
I am able to get the destination details EVERY TIME I run my application locally. However, when I run my application on cloud, after a few successful attempts, I get the following error:
"com.sap.cloud.sdk.cloudplatform.thread.exception.ThreadContextExecutionException: com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException: Failed to get destination with name 'name_of_the_destination'."
To resolve the issue, I have to re-deploy my Spring Boot application. Is anything wrong with the implementation? What I understand from the logs is, the threadcontext is not set correctly.
DefaultHttpDestination
should be used when building a destination instead of the MockUtil
test class. The built destination should also be registered in a DefaultDestinationLoader
, and this DefaultDestinationLoader
should be prepended in the DestinationAccessor
.