Handling duplicate values in the oData query filter.
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://
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
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
- Does executing the
nextLinkrequest 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.
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.
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=falsecan be supplied as header instead of query? Maybe the OData service is more forgiving then.
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.
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).
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