我使用的是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));我需要对配置在"MyDestination“中的系统和特定的SAP执行此请求。因此,我在目的地中添加了具有相应值的附加属性sap-client。
然而,不幸的是,此请求返回以下错误:
Unable to fetch the metadata : Failed to execute OData Metadata request.在调试SDK时,我发现getEdm of com.sap.cloud.sdk.odatav2.connectivity.cache.metadata.GuavaMetadataCache方法从未将sap-client信息作为header或URL参数添加到元数据请求中。(使用Postman,我能够显示元数据请求确实需要sap-client,否则会失败。这就是为什么VDM请求首先失败的原因。)
现在我的问题是,这是有意的行为还是SDK中的bug?
我认为在我的VDM请求中使用.withHeader("sap-client","600").onRequestAndImplicitRequests()可以解决我的问题,但是如果我应该将这个信息添加到每个VDM请求中,那么为什么我要在目的地中设置sap-client呢?
或者OData元数据请求设计为“客户端不可知论”,这就是为什么sap-client没有添加到SDK中的元数据请求的原因吗?
发布于 2020-01-31 08:20:36
由于您正在连接到一个S/4 OData服务,所以请求需要额外的headers。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()。
我在以下响应中描述了上下文:https://stackoverflow.com/a/59969716/9350514
https://stackoverflow.com/questions/59992127
复制相似问题