SAP CAP Node.JS Odata 404 error on destination service after upgrade to CDS v6

1.6k Views Asked by At

I would appreciate your help with this issue. -- Note - to get past the Spam filter, I have had to remove references through this question to "those things you send electronically over the internet" and replaced with "e" instead.

We have 4 CDS services running in SAP BTP using Cloud Foundry.

One service, a Node.JS service called the locking service, calls another, a Java service called the e service, in order to send an e via on-prem. This interaction is via Odata v4.

The client Node.JS service uses a destination service to get access to the e service.

We are in the process of upgrading from CDS version 5 to version 6. This upgrade seems to have caused a problem in this case. The access to the e service now does not work, failing with a 404 error log as shown below. It all works fine if we switch back to CDS v5 via a simple change to package.json.

Note that the log indicates these accesses are in error:-

https://destination-configuration.cfapps.eu10.hana.ondemand.com

And

https://destination-configuration.cfapps.eu10.hana.ondemand.com/pushE

These are not the destination end points for the service. The actual end points are defined in the destination and on testing within BTP, the access tests OK from the destination service definition. The destination has not been changed in the upgrade.

Error log...

ERR [remote] - Error: Error during request to remote service:

ERR Request failed with status code 404

ERR at run (/home/vcap/app/node_modules/@sap/cds/libx/_runtime/remote/utils/client.js:312:31)

ERR at processTicksAndRejections (node:internal/process/task_queues:96:5)

ERR at async RemoteService.<anonymous> (/home/vcap/app/node_modules/@sap/cds/libx/_runtime/remote/Service.js:234:20)

ERR at async next (/home/vcap/app/node_modules/@sap/cds/lib/srv/srv-dispatch.js:75:17)

ERR at async RemoteService.handle (/home/vcap/app/node_modules/@sap/cds/lib/srv/srv-dispatch.js:73:10)

ERR at async RemoteService.handle (/home/vcap/app/node_modules/@sap/cds/libx/_runtime/remote/Service.js:265:22)

ERR at async next (/home/vcap/app/node_modules/@sap/cds/lib/srv/srv-dispatch.js:75:17)

ERR at async RemoteService.handle (/home/vcap/app/node_modules/@sap/cds/lib/srv/srv-dispatch.js:73:10)

ERR at async sendE (/home/vcap/app/srv/locking-service.js:16:27)

ERR at async ApplicationService.<anonymous> (/home/vcap/app/srv/locking-service.js:128:13) {

ERR statusCode: 502,

ERR reason: [AxiosError: Error during request to remote service:

ERR Request failed with status code 404] {

ERR code: 'ERR_BAD_REQUEST',

ERR config: {

ERR timeout: 60000,

ERR xsrfCookieName: 'XSRF-TOKEN',

ERR xsrfHeaderName: 'X-XSRF-TOKEN',

ERR maxContentLength: -1,

ERR maxBodyLength: -1,

ERR proxy: false,

ERR method: 'post',

ERR baseURL: 'https://destination-configuration.cfapps.eu10.hana.ondemand.com',

ERR url: '/pushE',

ERR data: '{".........REMOVED ....."}}'

ERR },

ERR request: {

ERR method: 'POST',

ERR url: 'https://destination-configuration.cfapps.eu10.hana.ondemand.com/pushE',

ERR headers: {

ERR Accept: 'application/json,text/plain',

ERR 'Content-Type': 'application/json',

ERR authorization: 'Bearer ...',

ERR 'accept-language': 'en',

ERR 'content-length': 343,

ERR 'x-correlation-id': '4b74d979-de1f-4759-690c-3cce0cc7b9a7',

ERR 'User-Agent': 'axios/0.27.2'

ERR }

ERR },

ERR response: {

ERR status: 404,

ERR statusText: 'Not Found',

ERR headers: {

ERR 'content-length': '53',

ERR 'content-type': 'text/html; charset=utf-8',

ERR 'x-response-origin-sap-cp-cf-destination-service': 'https://destination-configuration.cfapps.eu10.hana.ondemand.com',

ERR 'x-vcap-request-id': '1cf1fa35-6103-487e-4d76-adf8a78799a3',

ERR date: 'Tue, 21 Feb 2023 14:54:24 GMT',

ERR 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload;',

ERR connection: 'close'

ERR },

ERR body: '<html><body><h1>Resource not found</h1></body></html>'

ERR },

ERR correlationId: '4b74d979-de1f-4759-690c-3cce0cc7b9a7'

ERR }

ERR }

Other information:-

  • The upgrade was from CDS v5 to v6.5.0 (the interaction still works with CDS ^5, but fails with CDS 6.1.1, 6.3.1, 6.4.1 and 6.5.0)
  • The SAP cloud SDK has also been upgraded from v1 to v2
  • Other node.JS services have been upgraded successfully, but this is the only situation where a CDS service invokes another.
  • As part of the investigation, the full process for refreshing the interface files was carried out, following the process described in https://cap.cloud.sap/docs/guides/using-services
  • The key process items followed to upgrade are shown below:-

Service upgrade steps

Action (Service)
Update CDS version to v6 (^6) by direct edit of package.json
Include dependency on Node JS engine at specified version (^16) :-
"engines": { "node": "^16" },
(as described in https://sap.github.io/cloud-sdk/docs/js/guides/upgrade-to-version-2 ) :-
npm uninstall --save @sap-cloud-sdk/core
npm install @sap-cloud-sdk/http-client
npm install @sap-cloud-sdk/connectivity
npm install @sap-cloud-sdk/odata-v2
npm install @sap-cloud-sdk/odata-v4
npm cache clear --force
npm cache verify
npm install --package-lock-only
Npm audit fix –force
npm update
Npm add npm-check-updates -g
Ncu
Ncu –upgrade
Npm install

App-router upgrade steps

Action (App-router)
edit package.json and change engines/node node to “^16.0.0”
npm cache clear –force (in one case this fixed a problem with “npm ERR! Cannot read properties of null (reading 'pickAlgorithm')”)
npm cache verify
npm install --package-lock-only
Npm audit fix –force
Npm update
Ncu
Ncu –upgrade
Npm install

Questions

  • Has anyone experienced a similar issue and found a solution?

  • If you have upgraded to v6 for a similar node JS Odata client using externalised destination details, are you able to share relevant configuration details and service call code?

  • Why do we get a 404 error when a test of the destination service is successful? (Destination export is below.)

  • The mta.yaml has a reference to the destination service – is this redundant, or worse, could it be causing the problem?

  • Is there an upgrade process that we missed?

  • Are the upgrade steps that we took above, valid?

  • Anything else you can think of or recommend?

MTA.yaml fragment

name: e-service-odata-destination

type: org.cloudfoundry.managed-service

parameters:

service-plan: lite

service: destination
  • Package.json
{
  "name": "locking-service",
  "version": "2.0.0",
  "description": "Locking Service based on CDS v6 and node v16",
  "repository": "https://......LockAPI",
  "license": "UNLICENSED",
  "private": true,
  "dependencies": {
    "@sap-cloud-sdk/connectivity": "^2.14.0",
    "@sap-cloud-sdk/http-client": "^2.14.0",
    "@sap-cloud-sdk/odata-v2": "^2.14.0",
    "@sap-cloud-sdk/odata-v4": "^2.14.0",
    "@sap/cds": "^6",
    "@sap/hana-client": "^2.15.19",
    "@sap/xsenv": "^3.4.0",
    "@sap/xssec": "^3.2.17",
    "express": "^4",
    "passport": "^0.6.0"
  },
  "devDependencies": {
    "@sap/hdi-deploy": "^4.5.3",
    "sqlite3": "^5.1.4"
  },
  "engines": {
    "node": "^16"
  },
  "scripts": {
    "start": "cds run"
  },
  "cds": {
    "hana": {
      "deploy-format": "hdbtable",
      "syntax": "hdi"
    },
    "requires": {
      "db": {
        "kind": "hana"
      },
      "eService": {
        "kind": "odata",
        "model": "srv/external/EService",
        "credentials": {
          "destination": "e-service-odata-destination"
        }
      }
    },
    "odata": {
      "flavor": "x4"
    },
    "uaa": {
      "kind": "xsuaa"
    }
  }
}

Connect code in js handler in locking service

const eService = await cds.connect.to('eService');

let data = {

e: {

<<removed>>

}

};

const eResponse = await eService.send('pushE', data);


Destination export (testing this destination is successful):-

#clientSecret=<< Existing password/certificate removed on export >>

#

#Wed Feb 22 10:25:45 UTC 2023

Description=E service CAP ODATA service

Type=HTTP

clientId=xxxxxxxx

Authentication=OAuth2ClientCredentials

Name=e-service-odata-destination

tokenServiceURL=https\://xxxxxxxx.authentication.eu10.hana.ondemand.com/oauth/token

ProxyType=Internet

URL=https\://xxxxxxxxxxxx.cfapps.eu10.hana.ondemand.com/odata/v4/e-service/

tokenServiceURLType=Dedicated
1

There are 1 best solutions below

0
On

​With the help of SAP, we solved this issue. By chance, we were accessing the destination through a service instance called email-service-odata-destination, but the destination entry which was defined in that service instance, was also called email-service-odata-destination. This worked OK under CDS v5, but failed with a 404 error under CDS v6 (which also involved an upgrade from SAP Cloud SDK v1 to v2).

Steps to fix the problem:-

  • We set up a new service instance with different names for service instance and destination (we could have changed the old service instance, obviously)
  • changed MTA.yaml to reference the new service instance name
  • changed package.json credentials section to reference the new destination name