cloud-sdk-java icon indicating copy to clipboard operation
cloud-sdk-java copied to clipboard

Handling duplicate values in the oData query filter.

Open chandrashek4r opened this issue 8 months ago • 5 comments

Describe the Bug

We have an additional property, URL.queries.<any>, configured in the destination service.

We use the SAP Cloud SDK framework to retrieve data from the data source called S4 HANA. This is done by invoking the ODataRequestResultPagination.Iterate method, which handles pagination and fetches data from S4 HANA.

When calling the S4 HANA OData service, the additional property from the destination service is included as an OData request query parameter. This setup works well until we receive a response from OData containing a nextLink URL for fetching data from subsequent pages. However, when we make the request for the next page, the variable from the destination service is added again. This results in duplicate values in the OData query filter, causing a "400 Bad Request" error from the S4 HANA OData gateway.

Steps to Reproduce

Here are the configuration details for reference.

Odata request URL : https:///sap/opu/odata4/sap/cdi_cds/cdi_cds/sap/c_ehslocationrevisiondex/0001/MasterData?$select=Plant&saml2=false

oData nextLink response : "@odata.nextLink": "/sap/opu/odata4/sap/cdi_cds/cdi_cds/sap/c_ehslocationrevisiondex/0001/MasterData? saml2=false &$select=Plant&$skiptoken=F_20250507143826_000431000_0000000001_0000000003_0000000003"

Expected Behavior

200 - HTTP OK Response

Screenshots

Image Image

Used Versions

Apache Maven 3.9.8 Java version: 17,

Code Examples

protected final ODataRequestRead oDataRequestRead;
oDataRequestRead.execute(httpClient).iteratePages(dataConverter.getSource())

Stack Trace

No response

Log File

Log file ...

Affected Development Phase

Production

Impact

Blocked

Timeline

No response

chandrashek4r avatar May 13 '25 06:05 chandrashek4r

  • Does executing the nextLink request in Potsman also return 400 Bad Request?
    • If yes, then the problem is with the OData service
    • If no, we need the stack-trace of the exception, and maybe some HTTP wire logs of the request to compare it to postman.

CharlesDuboisSAP avatar May 13 '25 06:05 CharlesDuboisSAP

When executing only the nextLink request in Postman, it does not return a 400 Bad Request error. However, when the same request is called from the application using the Cloud SDK framework, it results in a 400 Bad Request error. This is because the framework appends the destination configuration variable a second time in the OData query filter.

chandrashek4r avatar May 13 '25 06:05 chandrashek4r

Cloud SDK adds the query parameter saml2=false to all requests, if the destination has URL.queries.saml2=false. This is a generic action on our HTTP client that we cannot really change from OData client due to our API design and component hierarchy.

Idea for workaround:

  • Have you checked whether saml2=false can be supplied as header instead of query? Maybe the OData service is more forgiving then.

newtork avatar May 13 '25 07:05 newtork

Authentication to the on-premise system fails when we provide the values in the headers.

Is there a way to remove duplicate query filters from the OData URL?

We have observed an event listener called "ODataRequestListener" to obtain the desired OData URL, but the listener is set to empty in the "ODataRequestRead" object after the first call. Please share any documentation on "ODataRequestListener" if implementing this could help resolve our issue.

chandrashek4r avatar May 15 '25 03:05 chandrashek4r

Hi @chandrashek4r

We will have to look deeper into this problem on our end as it is not straight forward for us to remove duplicate query filters. We will get back to you once we have more information on this.

In the meantime, as a workaround, you could try to add a custom query parameter to the ODataRequestRead object you are creating. Sepcifically, instead of setting the URL.queries.<any> as additional property of your destination, add oDataRequestRead.addQueryParameter(key, value); to your code (using the appropriate key and value).

Jonas-Isr avatar May 15 '25 12:05 Jonas-Isr

Hi @chandrashek4r,

I am happy to inform you that a fix for your problem was released in the new Cloud SDK version 5.19.0 yesterday 🥳

Thus, I will close this issue as resolved.

Best, Jonas

Jonas-Isr avatar May 27 '25 09:05 Jonas-Isr