Skip to main content

Troubleshooting SDK Java

maven central

Solving Common Problems

Tenant or Principal Not Available

Symptoms

Tenant or principal information is not available or an incorrect tenant is used.

Possible causes:

  • A subscriber based JWT is passed in, but its validation fails, causing the SAP Cloud SDK to fall back to the provider account. See JWT validation fails.

  • An operation is performed in an asynchronous manner without propagating the ThreadContext. See Running Asynchronous Operations.

  • The SAP Cloud SDK components are not registered as listeners on incoming requests. See Framework Support.

  • There was no JWT in the authorization header.

  • A BAPI/RFC call was attempted while using resilience or multithreading capabilities of the SAP Cloud SDK. See Subscriber Tenant Is Not Found at Runtime

Provider Instead of Subscriber Account Used

Symptoms

Destinations are returned only for the provider account, but not for a subscriber account.

Possible causes:

JSON Web Token Validation Fails

Symptoms:

Logs show JWT validation exceptions, Tenant information is not available.

Possible causes:

Connecting to an ERP System fails

Symptoms:

The ERP system unexpectedly responds with 401: Unauthorized or 403: Forbidden.

Possible causes:

  • The SAP Client and Locale headers will be missing if the Destination is not an ErpHttpDestination. See Connecting to SAP S/4HANA.

Compilation Failures in the Generated OData Virtual Data Model Classes

Symptoms:

Compilation fails due to missing Getters and Setters on entity objects.

Possible causes:

  • Getters and Setters will be missing if Lombok is not present in the dependency tree of your project. See Using the OData Generator.
  • Getters and Setters will be shown red if your IDE does not support Lombok. Hence, install the Lombok plugin for your IDE.

Compilation or Runtime Failures After Updating the SAP Cloud SDK Version

Symptoms:

MethodNotFound, ClassDefNotFound or similar exceptions occur.

Possible causes:

The Java App Has Good Performance on Your Local Machine but Utilizes 100% CPU on SAP Business Technology Platform, Cloud Foundry Environment

Symptoms:
  • The Java app executes multiple threads and runs with good performance on a powerful local machine.
  • The performance significantly drops after the app is deployed to SAP Business Technology Platform - Cloud Foundry and CPU utilization is always around 100%.

Possible causes:

  • A powerful developer's machine usually has much better CPU and memory capacity than a standard cloud instance.
  • SAP BTP, Cloud Foundry environment provides 1/4 of CPU unit per every GB of memory. With maximum memory per instance of 8 GB, you can get a maximum of 2 CPU cores.
  • All the limitations are subject to change. Please check the latest details about SAP BTP, Cloud Foundry Environment quotas and limitations
  • If even after achieving the maximum vertical scale of your instance, your app doesn't reach the desired performance level, try to optimize it. Consider scaling it horizontally or different custom solutions to boost performance where it lags.

Request via Cloud Connector Fails with HTTP 407

Symptoms

In your application log you find the HTTP error code 407 and the request targets an On-Premise system via the SAP Cloud Connector.

Possible causes:

  • You are caching the HttpDestination instance in your application code instead of retrieving it for each request. Since the HttpDestination object stores the JWT needed for passing the SAP Cloud Connector, the JWT does not get refreshed after its expiration.

    To solve this issue, retrieve the HttpDestination for each request again with the DestinationAccessor API. There is no need to worry about performance, because the SAP Cloud SDK uses an optimized built-in cache for Destinations.

No Such Method: com.google.gson.JsonParser.parseReader

Symptoms

In your application log you find exception java.lang.NoSuchMethodError: com.google.gson.JsonParser.parseReader(Lcom/google/gson/stream/JsonReader;)Lcom/google/gson/JsonElement;.

Possible causes:

  • Your project uses the GSON library in version 2.8.5 or earlier. This could happen if you do not use the SAP Cloud SDK Bill-of-Material. To solve this issue, update GSON to at least version 2.8.6.

Class Not Found: JsonEncoder

Symptoms

Your application does not start and fails with the error message "Could not create component [encoder] of type [com.sap.hcp.cf.logback.encoder.JsonEncoder] java.lang.ClassNotFoundException: com.sap.hcp.cf.logback.encoder.JsonEncoder".

Possible causes:

  • Your project uses the Logback library for application logging. The required dependency com.sap.hcp.cf.logging:cf-java-logging-support-logback is missing. To solve this issue, add this dependency to your project. Also, use the SAP Cloud SDK Bill-Of-Material in your POM to manage the version of this dependency.

OData Request Rejected by or Failed in OData Service

Symptoms

Your OData request returns with a 400 (bad request) or 500 (server error) HTTP code.

Possible causes:

java.lang.IllegalArgumentException: JClass name empty

Symptoms

While generating a type-safe API client for an OData service, you encounter the exception message "java.lang.IllegalArgumentException: JClass name empty".

Possible causes:

  • The service specification (EDMX file) contains an entity that is named Type, Type_, or just _.

    By default, both the OData V2 and V4 VDM generators use the S4HanaNamingStrategy to generate valid Java names from the given service specification. Hereby, it removes pre- and suffixes that are commonly used in SAP service specifications, such as the suffixes Type and _ for entities. In special cases, where an entity name consist of those suffixes only, that logic leads to the generation of an empty class name, which, in turn, then results in the observed exception.

    To solve that issue, you can change the naming strategy used by the generator. The SAP Cloud SDK additionally includes the com.sap.cloud.sdk.datamodel.odata.utility.SimpleNamingStrategy out-of-the-box, which does not perform any unnecessary pre- and suffix removal.

DestinationAccessException: Failed to read authentication token. The destination service responded with an error: Could not verify the provided CSRF token because your session was not found

Symptoms

When running Destination#asHttp() you encounter an exception message like "DestinationAccessException: Failed to read authentication token. The destination service responded with an error: Could not verify the provided CSRF token because your session was not found".

Possible causes:

  • The Destination Service on Cloud Foundry is unable to generate an authentication token that will be used in later requests. In the service configuration, the destination entry references a token service endpoint that could not communicate correctly with the Destination Service.

    To solve that issue, please check every field in the destination configuration for valid input. Please find the official documentation from the Destination Service for more details. The value for field "Token Service URL" may require the full service endpoint path, including e.g. /oauth/token.

SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Symptoms

When accessing an On-Premise system from your local machine the HTTP client is unable to establish a secure connection to the target server. You may experience the follow-up error message: "ODataConnectionException: Connection was aborted."

Possible causes:

  • To validate the SSL connection your Java runtime would need to check the chain of trusted certificates. Please review your local Java trust store.

    To solve the issue there are many tutorials on how to register certificates. However, if you require a quick solution for your local development environmment, you can add a special flag to your "destinations" environment variable: "TrustAll" : "true". This will disable the certificate validation on your local runtime.

Olingo Dependency Conflicts

Symptoms

In your CAP based application you encounter exception messages like NoSuchMethodError or ClassDefNotFoundException on methods or classes of org.apache.olingo.odata2.

Possible causes:

  • The SAP Cloud SDK brings the dependency com.sap.cloud.servicesdk:odata-v2-lib which internally repackages Olingo. If you don't rely on any deprecated OData V2 functionality of the SAP Cloud SDK this dependency is not required and can be excluded.

    Add this exclusion in all places where odata-v2-lib is coming into your mvn dependency:tree:

    <exclusion>
    <groupId>com.sap.cloud.servicesdk</groupId>
    <artifactId>odata-v2-lib</artifactId>
    </exclusion>