温馨提示:本文翻译自stackoverflow.com,查看原文请点击:sap cloud sdk - Java SDK ignores sap-client property of Destionation on metadata request
sap-cloud-sdk

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

发布于 2020-03-27 15:50:40

我正在使用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,我发现,该方法getEdmcom.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中的元数据请求中的原因?

查看更多

查看更多

提问者
floste
被浏览
45
Alexander Dümont 2020-01-31 16:20

由于您正在连接到S / 4 OData服务,因此该请求需要其他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