什么时候使用(装饰)什么以及为什么-DefaultErpHttpDestination,DefaultHttpDestination? [英] When to use (decorate with) what and why - DefaultErpHttpDestination, DefaultHttpDestination?
问题描述
使用Java SAP Cloud SDK
我必须使用com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.outbounddeliveryv2.batch.OutboundDeliveryV2ServiceBatch.execute(HttpDestinationProperties destination)
在S/4系统上执行一些更新.此方法execute
接受类型为HttpDestinationProperties
的参数.
I have to use com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.outbounddeliveryv2.batch.OutboundDeliveryV2ServiceBatch.execute(HttpDestinationProperties destination)
to perform some updates on S/4 system. This method, execute
takes an argument of type HttpDestinationProperties
.
由于我需要目的地,因此我正在使用以下代码来获取目的地:
Since I need a destination, I am using below code to get destination:
HttpDestination destination = DestinationAccessor.getDestination("MyErpSystem").asHttp();
由于HttpDestination
扩展了HttpDestinationProperties
,因此我们可以安全地将其传递给execute
.但是根据连接到Cloud Foundry上的OData服务"的步骤4使用SAP Cloud SDK的教程,访问目标的代码如下:
Since HttpDestination
extends HttpDestinationProperties
, we can safely pass it to execute
. But according to step 4 of 'Connect to OData Service on Cloud Foundry Using SAP Cloud SDK' tutorial, the code for accessing destination looks like this:
ErpHttpDestination destination = DestinationAccessor.getDestination("MyErpSystem").asHttp().decorate(DefaultErpHttpDestination::new);
然后将目的地传递给服务的execute
方法.
and then they pass that destintion to the execute
method of the service.
我的问题是,由于execute
方法采用的是HttpDestinationProperties
类型的参数,我怎么知道我必须使用DefaultErpHttpDestination
? DefaultHttpDestination
也是如此.
My question is that since execute
methods takes an argument of type HttpDestinationProperties
, How would I know that I have to use DefaultErpHttpDestination
? Same thing goes for DefaultHttpDestination
.
我有以下问题-
- 何时以及为何将目的地包装在
DefaultErpHttpDestination
中? - 何时以及为何将目的地包装在
DefaultHttpDestination
中? - 为什么我应该将目的地全部包装在两个以上的包装纸中?
- When and why should I wrap the destination in
DefaultErpHttpDestination
? - When and why should I wrap the destination in
DefaultHttpDestination
? - Why should I wrap the destination in above two wrappers at all?
推荐答案
这是一个很好的问题!
上下文:
- 您当然可以继续使用原始方法:
- Of course you can keep using your original approach:
HttpDestination destination =
DestinationAccessor.getDestination("MyErpSystem").asHttp();
这是针对目的地以通用 HTTP服务终结点为目标的推荐方法. 它加载HTTP连接所需的目标属性,例如URL,身份验证,...
This is the recommended way for destinations targeting a generic HTTP service endpoint. It loads the required destination properties for HTTP connections, e.g. URL, Authentication, ...
- 在教程中,我们描述了与 S/4HANA OData服务的集成:
- In the tutorials we are describing the integration with S/4HANA OData services:
HttpDestination destination =
DestinationAccessor.getDestination("MyErpSystem").asHttp()
.decorate(DefaultErpHttpDestination::new);
通过使用 ERP 属性装饰" HttpDestination
实例,我们启用其他与S/4相关的HTTP请求标头:sap-client
和sap-locale
.通过上述配置,这些值会自动从目的地服务(如果已设置)中读取.
By "decorating" the HttpDestination
instance with ERP properties, we enable additional S/4 related HTTP request headers: sap-client
and sap-locale
. With the above configuration, those values are read automatically from the destination service - if they are set.
您的问题(顺序更改):
Your questions (changed order):
何时以及为何将目标包装在DefaultHttpDestination中?"
"When and why should I wrap the destination in DefaultHttpDestination?"
DestinationAccessor#getDestination
返回通用Destination
.为了确保我们正在处理HTTP(而非RFC)连接,您需要像以前一样运行#asHttp
.使用生成的HttpDestination
实例,您可以运行 OData 和 REST 之类的HTTP查询.根据您的用例,不需要其他包装.
DestinationAccessor#getDestination
returns a generic Destination
. In order to make sure we are dealing with HTTP (and not RFC) connections, you need to run #asHttp
- as you already do. With the resulting HttpDestination
instance, you can run HTTP queries like OData and REST. Depending on your use case, no additional wrapping is required.
例如,如果您要使用 BAPI 端点,则需要运行#asRfc
.此方法将检查不同的目的地属性,以确保设置了所有必需的值.
For example, if you were about to use BAPI endpoints, then you'd need to run #asRfc
instead. This method will check for different destination properties to make sure all required values are set.
何时以及为何将目标包装在DefaultErpHttpDestination中?"
"When and why should I wrap the destination in DefaultErpHttpDestination?"
建议仅在处理 S/4 服务端点并且依赖sap-client
和sap-locale
的自定义值时,才将目标包装在DefaultErpHttpDestination
中.只要在#execute(HttpDestinationProperties)
方法之前进行包装,就可以在应用程序运行时的任何时候进行包装.
It is recommended to wrap the destination in DefaultErpHttpDestination
only when you are dealing with S/4 service endpoints and you rely on custom values for sap-client
and sap-locale
. The wrapping can be done at any time of your application runtime, as long as it happens before #execute(HttpDestinationProperties)
method.
如果不想再次包装它,则需要手动管理sap-client
和sap-locale
的HTTP请求标头.
If you do not want to wrap it a second time, then you'd need to manually manage the HTTP request headers for sap-client
and sap-locale
.
为什么要在两个包装纸之间完全包装目的地?"
"Why should I wrap the destination in above two wrappers at all?"
这是API合同.它可以确保在调用实际请求之前正确设置了所有必需的 destination 属性.提供了(可选)目标实例的 ERP 风味包装,以确保也自动考虑所有 S/4 属性.
This is the API contract. It makes sure all required destination properties are correctly set before even invoking the actual request. The (optional) ERP flavored wrapping of the destination instance was provided to make sure all S/4 properties are automatically considered as well.
这篇关于什么时候使用(装饰)什么以及为什么-DefaultErpHttpDestination,DefaultHttpDestination?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!