我正在使用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,我发现,该方法getEdm
的com.sap.cloud.sdk.odatav2.connectivity.cache.metadata.GuavaMetadataCache
从未添加sap-client
信息,无论是作为HTTP头或URL参数的元数据请求。(使用邮差,我可以表明,元数据请求确实需要sap-client
,否则失败。这首先说明了VDM请求失败的原因。)
现在我的问题是这是预期的行为还是SDK中的错误?
我发现.withHeader("sap-client","600").onRequestAndImplicitRequests()
在VDM请求中使用可以解决我的问题,但是如果我应该将此信息添加到每个VDM请求中,那么为什么要sap-client
在目标位置设置?
还是OData元数据请求被设计为“客户端不可知”,这就是为什么sap-client
未将其添加到SDK中的元数据请求中的原因?
由于您正在连接到S / 4 OData服务,因此该请求需要其他HTTP标头。自定义值sap-client
和sap-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