在所有文档中,我找到了ODataQueryBuilder的示例。 但是,您是否也有一个示例如何使用com.sap.cloud.sdk.odatav2.connectivity包的Create,Update和Delete方法:
如何处理CSRF令牌?
请提供一个工作示例?
答案 0 :(得分:10)
在OData服务的元数据端点上使用HEAD请求获取CSRF令牌。
一些注意事项:
<强> ODataCreateRequestBuilder 强>
Map<String, Object> body = new HashMap<>();
body.put("FirstName", "John");
body.put("LastName", "Doe");
body.put("BusinessPartnerCategory", "1");
ODataCreateRequest createRequest =
ODataCreateRequestBuilder
.withEntity("/sap/opu/odata/sap/API_BUSINESS_PARTNER", "A_BusinessPartner")
.withBodyAsMap(body)
.build();
createRequest.execute("DestinationName");
<强> ODataUpdateRequestBuilder 强>
Map<String, Object> keys = new HashMap<>();
keys.put("BusinessPartner", "12345");
Map<String, Object> params = new HashMap<>();
params.put("FirstName", "John");
params.put("MiddleName", "D.");
params.put("LastName", "Doe");
params.put("BusinessPartnerCategory", "1");
final ODataUpdateRequest updateRequest =
ODataUpdateRequestBuilder
.withEntity("/sap/opu/odata/sap/API_BUSINESS_PARTNER", "A_BusinessPartner", keys)
.withBodyAsMap(params)
.build();
updateRequest.execute("DestinationName");
<强> ODataDeleteRequestBuilder 强>
Map<String, Object> keys = new HashMap<>();
keys.put("BusinessPartner", "12345");
keys.put("AddressID", "98765");
ODataDeleteRequest deleteRequest =
ODataDeleteRequestBuilder
.withEntity("/sap/opu/odata/sap/API_BUSINESS_PARTNER", "A_BusinessPartnerAddress", keys)
.build();
deleteRequest.execute("DestinationName");