SAP / cloud-sdk

The SAP Cloud SDK documentation and support repository.
https://sap.github.io/cloud-sdk/
Apache License 2.0
44 stars 41 forks source link

Support for adding headers in batch mode #156

Closed KurtStauffer closed 3 years ago

KurtStauffer commented 3 years ago

Issue Description

According to the Integration guide for Contacts OData the Sap-Cuan-SequenceId header is mandatory when updating a ContactOriginData record. When updating in singleton mode I am able to set this header as follows and it works without issue:

service
  .updateContactOriginData(contact)
  .withHeader("Sap-Cuan-SequenceId", "PatchUpdate")
  .executeRequest(destination);

However, there is no option to set this header when performing the same update in batch mode:

service
  .batch()
  .beginChangeSet()
  .updateContactOriginData(contact)
  .withHeader(...) // this option does not exist
  .endChangeSet()
  .executeRequest(destination);

When I run the batch request my SAP Import Monitor shows the error:

Invalid content in field Sap-Cuan-SequenceId

Perhaps I am missing something but this appears to be a shortcoming in the batch mode implementation for the OData v2 typed client to not be able to set the required header. I should note that we are connecting to a SAP S/4HANA Cloud system and so switching to use OData v4 doesn't appear to be an option for us.

Also, before posting here I did ask this same question over at StackOverflow and was encouraged to log the issue here.

Any help would be greatly appreciated!

Thanks, Kurt

mvn_dep_tree.txt

Impact / Priority

Affected development phase: Development

Impact: Blocked

Timeline: Go-Live end of March

Project Details


Checklist

artemkovalyov commented 3 years ago

Hi @KurtStauffer,

Thanks for moving the issue here. I added it to the top of our backlog to refine this week and investigate the feasibility of a quick fix. I'll get back to you by Friday with possible fix ideas and timeframe options.

You mentioned you plan to go live end of March, can you elaborate more specifics about the deadlines? The runway is pretty short already, especially assuming our bi-weekly release cycle.

KurtStauffer commented 3 years ago

Thanks @artemkovalyov, I really appreciate the help! Our deadline is pretty flexible and if needs be we can continue using our current implementation (which is using RestTemplate to send the batch request) until the SDK is ready. I just found the SDK the other day and saw an opportunity to clean up some ugly code on our end. I love what you've done so far and I'm excited to see where it goes from here!

Thanks!

MatKuhr commented 3 years ago

Hi @KurtStauffer ,

You can actually already achieve this today with the SDK using the low-level API:

String servicePath = service.getServicePath();

ODataRequestBatch requestBatch =  new ODataRequestBatch(servicePath, ODataProtocol.V2);
ODataRequestUpdate requestUpdate = service. updateContactOriginData(contact)
        .withHeader("Sap-Cuan-SequenceId", "PatchUpdate")
        .toRequest(); // -> this transitions the request from high to low level API

requestBatch.beginChangeset().addUpdate(requestRead).endChangeset();

HttpClient httpClient = HttpClientAccessor.getHttpClient(destination);
ODataRequestResultMultipartGeneric batchResult = requestBatch.execute(httpClient);

// extract information from batch response, by referring to the individual OData request reference
ODataRequestResultGeneric queryResult = batchResult.getResult(requestUpdate);
MyXyzClass result = queryResult.as(MyXyzClass.class);

As @artemkovalyov pointed out we will be working to support this on the high level API as well. However, adapting the above solution might still be a step in the right direction. Because the upcoming API will most likely be similar to the above, but without the need of toRequest() and the manual response evaluation.

We already have such a high-level API for OData V4. I would expect the upcoming V2 variant to be similar.

Johannes-Schneider commented 3 years ago

Hi @KurtStauffer,

I just wanted to let you know that we shipped a first version of that feature with Cloud SDK 3.43.0. As Matthias outlined already, we tried to stick as close to our existing OData V4 API as possible, so changes in your code should hopefully be minimal.

Please let us know whether the new API works for you.

Thanks and best regards, Johannes

artemkovalyov commented 3 years ago

Hey @KurtStauffer,

We hope the feature works well for you. We'll be closing this issue for now as we haven't heard from you in a while. If you still have any questions don't hesitate to re-open this issue or create a new one.

Cheers!