0

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.

Ronit Nath
  • 41
  • 5
  • Can you motivate why you are getting the tenant and then setting it again? This seems unnecessary to me. Furthermore, do you have any additional log messages and/or a stack-trace? Otherwise it will be difficult to help. For example, is it possible that "after a few successful attempts" means something like after 5min precisely? – Alexander Dümont Sep 12 '22 at 12:13
  • @AlexanderDümont I have found a pattern. I tried to fetch the details of a destination which has authentication type of OAuth2ClientCredentials of a different sub account. After that, whenever I try to fetch the details of any destination of my 1st subaccount, I keep getting the error in the description. – Ronit Nath Sep 12 '22 at 14:07
  • When I try to access the destination with OAuth2ClientCredentials authentication type, I get the following error "com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException: Failed to read authentication token. The destination service responded with an error: 404 Not Found - {}" The authTokens object received for the destination is: "authTokens": [ { "type": "", "value": "", **"error": "404 Not Found - {}"**, "expires_in": "0" } ] – Ronit Nath Sep 12 '22 at 17:58
  • After around 10 minutes, if I try to access the destination details of a different subaccount, 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'** – Ronit Nath Sep 13 '22 at 04:21

1 Answers1

0

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.