Reputation: 531
we are firing a draft activation call(submit call) to s4 system using the cloud sdk(java). S4 odata service in odata v2.0. The submit call is a function import with the following signature -
<FunctionImport
Name="C_GuidedProcmtReqnHdrTPActivation"
ReturnType="MMPUR_REQ_GPR_MAINTAIN_SRV.C_GuidedProcmtReqnHdrTPType"
EntitySet="C_GuidedProcmtReqnHdrTP" m:HttpMethod="POST"
sap:action-for="MMPUR_REQ_GPR_MAINTAIN_SRV.C_GuidedProcmtReqnHdrTPType"
sap:applicable-path="Activation_ac">
<Parameter Name="PurchaseRequisition" Type="Edm.String"
Mode="In" MaxLength="10" />
<Parameter Name="DraftUUID" Type="Edm.Guid" Mode="In" />
<Parameter Name="IsActiveEntity" Type="Edm.Boolean"
Mode="In" />
</FunctionImport>
Using vdm we are executing the following call
HeaderCDSForPRForGuidedBuying requisitionHeader = s4ReqService
.guidedProcmtReqnHdrTPActivation(Constants.EMPTY_STRING, UUID.fromString(draftReqId.toString()), false)
.cachingMetadata().execute(getS4Destination());
However, we are not able to receive the sap-message header in this call. The question is how to receive the sap-message for this function import?
we are using cloud SDK version 3.21.0
Upvotes: 1
Views: 508
Reputation: 1701
Update:
As of SAP Cloud SDK 3.34.1 we provide an improved function import logic for OData V2. We offer the method yourFunctionImport.toRequest()
which gives access to the internally built OData request object.
You can use this request object to invoke the function import and to retrieve a Java representation of the function import result, including the response headers.
Code snippet:
final ODataRequestGeneric odataRequest = s4ReqService
.guidedProcmtReqnHdrTPActivation(Constants.EMPTY_STRING, UUID.fromString(draftReqId.toString()), false)
.toRequest();
final ODataRequestResult odataResult =
odataRequest.execute(HttpClientAccessor.getHttpClient(destination));
final Iterable<String> headerNames = odataResult.getHeaderNames();
final Iterable<String> headerValues = odataResult.getHeaderValues("header-key);
Outdated:
At the time of this writing, accessing HTTP response headers of function import calls when using the OData VDM is not possible. I'll update this answer, in case this feature is available in a newer version.
For the time being, we propose building the request manually as workaround.
Let me sketch this out for Function Imports with GET requests.
Generic pattern:
final ODataRequestRead functionImportRequest = new ODataRequestRead("service-url", "function-import-name", "query-string", ODataProtocol.V2);
final ODataRequestResultGeneric functionImportResponse = functionImportCall.execute(HttpClientAccessor.getHttpClient(destination));
final Iterable<String> headerNames = functionImportResponse.getHeaderNames();
final Iterable<String> headerValues = functionImportResponse.getHeaderValues("response-header-key");
Applying that generic pattern to a concrete function import of a concrete service:
final ODataRequestRead functionImportRequest = new ODataRequestRead("/sap/opu/odata/sap/API_CV_ATTACHMENT_SRV/", "GetAttachmentCount", "BusinessObjectTypeName='1000'&LinkedSAPObjectKey='2000'&SemanticObject='3000'", ODataProtocol.V2);
final ODataRequestResultGeneric functionImportResponse = functionImportCall.execute(HttpClientAccessor.getHttpClient(destination));
//use functionImportResponse.getHeaderNames() or functionImportResponse.getHeaderValues(key)
If the function import requires POST request, additional CSRF token handling must be added.
The drawback of this workaround is that it neglects the type-safety that the VDM provides you.
Upvotes: 2