javasap-cloud-sdk

Get Operation Which Caused Changeset to Fail or Get Content-ID of Batch Response


When working with a batch that contains a changeset is it possible to get the Content-ID of the Batch Response if the changeset has failed?

Let's say I have the following code to create a batch with a changeset using the SDK. createDocument3 is going to raise an error and cause the whole changeset to fail:

BatchRequestBuilder batchRequestBuilder = new BatchRequestBuilder("/v1/");
        batchRequestBuilder.addChangeset(createDocument1, createDocument2, createDocument3));

BatchResponse batchResponse = batchRequestBuilder.execute(destination);

Here is the sample request & response data that is passed to the endpoint.

[Thu Feb 29 22:06:11 2024] [10.0.0.2] [pid=4152] [Request] "POST /v1/$batch HTTP/1.1"
OData-Version:4.0
Content-Type:multipart/mixed;boundary=batch_17d7a8c3-d3c7-42d4-b6a6-06ef1d975008
Content-Length:2173
Host:test-sapsvcl.aadds.teamson.com:50000
Connection:Keep-Alive
User-Agent:Apache-HttpClient/4.5.14 (Java/21.0.2)
Cookie:**************************************************************************
Accept-Encoding:gzip,deflate
X-Forwarded-Proto:https

--batch_17d7a8c3-d3c7-42d4-b6a6-06ef1d975008
Content-Type: multipart/mixed;boundary=changeset_d3c4fa68-582a-46fd-8691-d24272625cda

--changeset_d3c4fa68-582a-46fd-8691-d24272625cda
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 1

POST Orders HTTP/1.1
Accept: application/json
Content-Type: application/json

{"@odata.type":"#SAPB1.Document"..........}

--changeset_d3c4fa68-582a-46fd-8691-d24272625cda
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 2

POST Orders HTTP/1.1
Accept: application/json
Content-Type: application/json

{"@odata.type":"#SAPB1.Document"..........}

--changeset_d3c4fa68-582a-46fd-8691-d24272625cda
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 3

POST Orders HTTP/1.1
Accept: application/json
Content-Type: application/json

{"@odata.type":"#SAPB1.Document"..........}

--changeset_d3c4fa68-582a-46fd-8691-d24272625cda--

--batch_17d7a8c3-d3c7-42d4-b6a6-06ef1d975008--


[Thu Feb 29 22:06:11 2024] [10.0.0.2] [pid=4152] [Response] "POST /v1/$batch HTTP/1.1"
Status Code:[200 OK]
Date:Thu, 29 Feb 2024 22:06:11 GMT
Server:Apache
OData-Version:4.0
Content-Length:569
Content-Type:multipart/mixed;boundary=batchresponse_hKXEHg8m-qSXb-TCW6-dl3M-4r2H6qxgAbaG

--batchresponse_hKXEHg8m-qSXb-TCW6-dl3M-4r2H6qxgAbaG
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 3

HTTP/1.1 400 Bad Request
Content-Type: application/json;charset=utf-8
Content-Length: 258
OData-Version: 4.0

{
   "error" : {
      "code" : "-5002",
      "details" : [
         {
            "code" : "",
            "message" : ""
         }
      ],
      "message" : "Error."
   }
}

--batchresponse_hKXEHg8m-qSXb-TCW6-dl3M-4r2H6qxgAbaG--

After the request is executed, I check the results of each operation.

batchResponse.getModificationResult(createDocument1);
batchResponse.getModificationResult(createDocument2);
batchResponse.getModificationResult(createDocument3);

The first call to the above raises an exception, however in reality it was createDocument3 that was the cause of the error.

Is there any way for me to know which operation caused the changeset to fail within the SDK? You can see in the batchresponse that Content-ID: 3 is returned so is it possible to get it from there?


Solution

  • SAP Cloud SDK 5.6.0 has the following improvement: