Java SDK 在元数据请求中忽略 Destionation 的 sap-client 属性



我正在使用Java SAP Cloud SDK版本3.11.0,并且有以下VDM请求:

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));

我需要针对使用特定SAP客户端在"MyDestination"中配置的系统执行此请求。因此,我在目标中添加了具有相应值的附加属性sap-client

但是,不幸的是,此请求返回以下错误:

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

在调试 SDK 时,我发现com.sap.cloud.sdk.odatav2.connectivity.cache.metadata.GuavaMetadataCache的方法getEdm从不将sap-client信息作为 HTTP 标头或 URL 参数添加到元数据请求中。(使用Postman,我能够证明元数据请求确实需要sap-client,否则它将失败。这就是 VDM 请求首先失败的原因。

现在我的问题是这是预期行为还是 SDK 中的错误?

我认为在我的 VDM 请求中使用.withHeader("sap-client","600").onRequestAndImplicitRequests()可以解决我的问题,但是如果我应该将此信息添加到每个 VDM 请求中,那么我为什么要在目标中设置sap-client

或者 OData 元数据请求是否设计为"与客户端无关",这就是未将sap-client添加到 SDK 中的元数据请求的原因?

由于您要连接到S/4OData 服务,因此请求需要额外的 HTTP 标头。sap-clientsap-locale的自定义值可以手动设置(如问题中所述(。或者可以使用以下代码:

HttpDestination destination =
DestinationAccessor.getDestination("MyDestination").asHttp()
.decorate(DefaultErpHttpDestination::new);
[...]
new DefaultOutboundDeliveryV2Service()
.getOutbDeliveryHeaderByKey(deliveryDocument)
.execute(destination));

通过对类型HttpDestination使用这个额外的"修饰"步骤,目标对象会自动获得如上所述的S/4风味属性。例如,默认情况下将添加目标服务中保存的sap-client的值,而无需手动调用.withHeader(...).onRequestAndImplicitRequests()

我在以下 SO 响应中描述了上下文:https://stackoverflow.com/a/59969716/9350514

相关内容

最新更新