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

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

我正在使用 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

然而不幸的是,这个请求returns出现了以下错误:

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 header 或 URL元数据请求的参数。(使用 Postman,我能够证明元数据请求确实需要 sap-client,否则会失败。这就是 VDM 请求首先失败的原因的解释。)

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

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

或者 OData 元数据请求是否设计为 "client agnostic",这就是为什么 sap-client 未添加到 SDK 中的元数据请求的原因?

由于您正在连接到 S/4 OData 服务,请求需要额外的 HTTP headers。 sap-clientsap-locale 的自定义值可以手动设置(就像你所做的那样,在你的问题中描述)。或者您可以使用以下代码:

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

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

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

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