cancel
Showing results for 
Search instead for 
Did you mean: 

Can't call external service when using the OData v2 proxy on CAP project

js2
Product and Topic Expert
Product and Topic Expert
0 Kudos

I have a CAP project which calls an external service to start a workflow.

When I add the odata v2 proxy so that I can use a fiori elements app for some reason the external service call fails.

The external service url is: https://api.workflow-sap.cfapps.ap10.hana.ondemand.com/workflow-service/rest/v1/workflow-instances

The errors I see are:

2020-11-24T14:51:03.84+0800 [APP/PROC/WEB/0] OUT {"message":"Successfully retrieved destination from destination service.","level":"info","custom_fields":{"package":"core","messageContext":"destination-accessor-service"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-11-24T06:51:03.847Z","msg":"Successfully retrieved destination from destination service.","written_ts":1606200663847,"written_at":"2020-11-24T06:51:03.847Z"}
   2020-11-24T14:51:03.84+0800 [APP/PROC/WEB/0] OUT {"message":"Try to fetch https_proxy or HTTPS_PROXY from the process env. Found value is undefined","level":"info","custom_fields":{"package":"core","messageContext":"proxy-util"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-11-24T06:51:03.847Z","msg":"Try to fetch https_proxy or HTTPS_PROXY from the process env. Found value is undefined","written_ts":1606200663847,"written_at":"2020-11-24T06:51:03.847Z"}
   2020-11-24T14:51:03.84+0800 [APP/PROC/WEB/0] OUT {"message":"No Proxy settings for https are found in environment variables - no proxy used","level":"info","custom_fields":{"package":"core","messageContext":"proxy-util"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-11-24T06:51:03.847Z","msg":"No Proxy settings for https are found in environment variables - no proxy used","written_ts":1606200663847,"written_at":"2020-11-24T06:51:03.847Z"}
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR [2020-11-24T06:51:04.014Z | ERROR | 1902147]: Error: Failed to build HTTP request for destination: failed to build headers!
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR     at Object.errorWithCause (/home/vcap/app/node_modules/@sap-cloud-sdk/util/dist/error.js:5:20)
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR     at /home/vcap/app/node_modules/@sap-cloud-sdk/core/dist/http-client/http-client.js:195:38
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR     at process._tickCallback (internal/process/next_tick.js:68:7)
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR Caused by:
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR Error: Request for "OAuth2ClientCredentials" authentication access token failed or denied.
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR     at Object.errorWithCause (/home/vcap/app/node_modules/@sap-cloud-sdk/util/dist/error.js:5:20)
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR     at /home/vcap/app/node_modules/@sap-cloud-sdk/core/dist/header-builder/authorization-header.js:166:38
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR     at process._tickCallback (internal/process/next_tick.js:68:7)
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR Caused by:
   2020-11-24T14:51:04.01+0800 [APP/PROC/WEB/0] ERR Error: FetchTokenError: Client credentials Grant failed! Request failed with status code 401

So even though the error says something about the authentication, I did not get this error and calling the external service worked fine before adding the odata v2 proxy. Any ideas? The initial error above is somthing to do with a proxy...

My v2 adapter proxy is as follows (straight from the doco on the npm registry):

"use strict";

const cds = require("@sap/cds");
const proxy = require("@sap/cds-odata-v2-adapter-proxy");

cds.on("bootstrap", app => app.use(proxy()));

module.exports = cds.server;

gregorw
Active Contributor
0 Kudos

Does this issue occur locally or when deployed on SAP CP?

js2
Product and Topic Expert
Product and Topic Expert
0 Kudos

gregorw - When deployed.

js2
Product and Topic Expert
Product and Topic Expert
0 Kudos

gregorw it seems that the proxy is upsetting the OAuth2ClientCredentials flow in the external api call (to the workflow service).

I am trying to set the path attribute of the proxy to be more than just "v2" to include my service name like: "v2/safety-incident" but it doesn't seem to like it and I get 404's on my CAP service.

This is how I configured the proxy:

"use strict";

const cds = require("@sap/cds");
const proxy = require("@sap/cds-odata-v2-adapter-proxy");

cds.on("bootstrap", app => app.use(proxy({
    path: "v2/safety-incident",
})));

module.exports = cds.server;
gregorw
Active Contributor
0 Kudos

Have you filed an Issue internaly?

OliverKlemenz
Advisor
Advisor
0 Kudos

I cannot explain, why the CDS OData V2 Adapter Proxy shall interfere with the Workflow Service, but the "proxy" mentioned in the first console logs, has nothing to do with the OData V2 Proxy. These logs are from AppRouter or SAP Cloud SDK.

Please make sure, that the OData calls have their own path, and don't clash with other resources, such as UI, service calls, that may be routed by the AppRouter...

If you change the Proxy path to "v2/safety-incident" in the proxy configuration, then the OData V2 service is reachable under the new path "v2/safety-incident/<service-name>", and should not return an 404.

Accepted Solutions (0)

Answers (0)