floste
floste

Reputation: 79

Java SDK ignores sap-client property of Destionation on metadata request

I am using the Java SAP Cloud SDK version 3.11.0 and have the following VDM request:

final Destination destination = DestinationAccessor.getDestination("MyDestination");

Try<OutbDeliveryHeader> deliveryHeaderTry = Try.of(() -> new DefaultOutboundDeliveryV2Service()
                    .getOutbDeliveryHeaderByKey(deliveryDocument)
                    .execute(destination.asHttp()))
                    .onFailure(e -> logger.error("Failed to read delivery header " + deliveryDocument
                            + ": " + e.getMessage(), e));

I need this request to be executed against the system configured in "MyDestination" with a specific SAP client. I therefore added the additional property sap-client with the corresponding value in my destination.

Unfortunately however, this request returns the following error:

Unable to fetch the metadata : Failed to execute OData Metadata request.

While debugging the SDK, I found that the method getEdm of com.sap.cloud.sdk.odatav2.connectivity.cache.metadata.GuavaMetadataCache never adds the sap-client information as either a HTTP header or URL parameter to the metadata request.(Using Postman, I was able to show that the metadata request indeed needs a sap-client, otherwise it fails. This is the explanation why the VDM request fails in the first place.)

Now my question is whether this is intended behavior or a bug in the SDK?

I figured that using .withHeader("sap-client","600").onRequestAndImplicitRequests() in my VDM request fixes my problem, but if I am supposed to add this information to every VDM request, then why should I set the sap-client in the destination?

Or is an OData metadata request designed to be "client agnostic" and that is the reason why the sap-client is not added to the metadata request in the SDK?

Upvotes: 1

Views: 272

Answers (1)

Alexander D&#252;mont
Alexander D&#252;mont

Reputation: 938

Since you are connecting to an S/4 OData service, the request expects additional HTTP headers. Custom values for sap-client and sap-locale can be either set manually (as you did, described in your question). Or you can use the following code:

HttpDestination destination =
  DestinationAccessor.getDestination("MyDestination").asHttp()
    .decorate(DefaultErpHttpDestination::new);

[...]
new DefaultOutboundDeliveryV2Service()
  .getOutbDeliveryHeaderByKey(deliveryDocument)
  .execute(destination));

By using this additional "decoration" step for type HttpDestination, the destination object is automatically provided the S/4 flavored properties as described above. For example, the value for sap-client saved in your destination service will be added by default, without needing to manually invoke .withHeader(...).onRequestAndImplicitRequests().

I described the context in the following SO response: https://stackoverflow.com/a/59969716/9350514

Upvotes: 2

Related Questions