cancel
Showing results for 
Search instead for 
Did you mean: 

CAP - CDS breaks remotely redirected search parameter with unwanted quotes

Hi Community,

we are currently using CAP to connect multiple ODATA Backends (which we do not control) to a unified Frontend. We are using Projected Entities and intercept Frontend requests, filter out the specific ID for that backend System, and then redirect the request to the correct Backend Service.

So far everything has worked fine, except for the search query:

When sending a search request query from the frontend, we get a request like this:

GET http://localhost:4004/v2/ABC/ EntityABC?$skip=0&$top=20&$select=abetc&search=name

However CDS interprets this request as

[cds] - GET /ABC/EntityABC?%24skip=0&%24top=20&%24select=abetc&%24search="name"

It puts quotes around the search term, which when sent to the backend ODATA gives us back an empty set, instead of the data that was actually requested.

Testing this behavior on the backend ODATA directly confirms this, search queries only work when not encapsulated by quotes.

Looking through the request object in our service handler, the query seems to be interpreted correctly, but then at some point CDS encapsulates it.

The request query object that is passed to the server:

{ SELECT: {
  from: {
    ref: [
      'namespace.EntityABC'
    ]
  },
  columns: [
    {ref:['abetc']},  ]
  search: [ {val:'name'} ],
  limit: { rows: {val:20}, offset: {val:0} },
  orderBy: [
    {ref:[ 'abetc' ], sort: 'asc' }  ]
}}

CDS definition:

@sap.searchable
@cds.search
service SomeService @(requires : 'authenticated-user') {
    entity EntityABC     as projection on namespace.ExternalBackend {
        key abetc,
        key 'somekey'         as SystemID  : String,
            *,
            toNavProperty as nav : redirected to navProperty
    } excluding {
        toNavProperty
    };

Is there a way around this behavior? Apart from search, every other operation works out of the box.

Dependencies:

  "dependencies": {

    "@sap/audit-logging": "^5.5.3",
    "@sap/cds": "^5",
    "@sap/cds-odata-v2-adapter-proxy": "^1.8.21",

Thank you and kind regards

Max

OlenaT
Advisor
Advisor
0 Kudos

Hi maxhenkes,

Thank you for bringing this issue to our attention. We took it as a feature request, but first we need to discuss with our OData v2 colleagues if complicated search expressions are supported and how they should be passed to the remote service. We will get back to you when we have more information about this issue.

Best regards,

Olena

0 Kudos

Hi Olena,

thank you for your comment.

I want to emphasis that this is not a problem related to complicated search expressions.

If you were to pass a complicated search expression containing quotes, it will pass these as double quotes around the search term. CAP breaks this functionality by editing our search term. IMO this is unexpected behavior and that is why we have also raised a bug report, which you are aware of.

Thank you and kind regards


Max

0 Kudos

Hi,

I've noticed in the URL that there is a %24 in front of the search parameter. For OData v2 this might not be correct.

%24 is the Url encoded character for $. If this is removed from the URL does the request still fail?

Regards

Daniel

0 Kudos

Hi Daniel,

the outgoing CDS request is displayed as v4 ODATA by CDS in the terminal. The remote call is correctly translated to v2 and does not have a $ before the search term. The query works fine if manually transferred from the fiori frontend, once it goes through CAP the system adds "" automatically, which is the cause of this error. A ticket for this has already been raised.

Regards

Max

Accepted Solutions (0)

Answers (1)

Answers (1)

OlenaT
Advisor
Advisor
0 Kudos

Hi Max,

As I already mentioned in the issue you raised, starting the next cds version there will be no quoting of search term for OData v2 backend.

Best regards,

Olena