Cannot access S/4HANA on Premise system via Cloud

2019-08-09 05:44发布

问题:

I'm trying to access an S/4HANA on Premise system via the Cloud Connector and SAP Cloud Platform connectivity service using the SAP Cloud SDK for JavaScript (version 1.5.0).

In detail, I have

  • Cloud Connector
  • connectivity service
  • xsuaa service instance
  • Application Router (app-router)
  • destination
  • destination service

which all work as expected. These preconditions are explained by different tutorials (https://blogs.sap.com/2019/04/02/a-do-it-yourself-at-home-guide-how-to-connect-a-node.js-app-on-sap-cloud-platform-for-the-cloud-foundry-to-an-s4hana-on-premise-system-securely-via-cloud-connector/, https://blogs.sap.com/2017/07/13/part-2-how-to-use-the-sap-cloud-platform-connectivity-and-the-cloud-connector-in-the-cloud-foundry-environment/).

With this setup I have no difficulties accessing an S/4HANA Cloud system. When using the SAP Cloud SDK for Java everything works as expected, i.e. I can access the on premise system. I have sufficient rights on the on premise system. Basic Authentication is used.

Example GET request for retrieving document info records using the SAP Cloud SDK JavaScript:

let destination = await useOrFetchDestination({
destinationName: 'MY_DESTINATION',
jwt: 'MY_JWT' });
DocumentInfoRecord.requestBuilder()
.getAll()
.execute(destination);

But testing against an on premise system makes the GET request fail with status code 503:

ERR Error: get request failed!
ERR     at Object.errorWithCause (/path-to-app/node_modules/@sap/cloud-sdk-util/dist/error.js:14:20)
ERR     at specializeError (/path-to-app/@sap/cloud-sdk-core/dist/request-builder/request/odata-request.js:175:32)
ERR     at /path-to-app/@sap/cloud-sdk-core/dist/request-builder/request/odata-request.js:162:58
ERR     at processTicksAndRejections (internal/process/task_queues.js:86:5)
ERR Caused by:
ERR Error: Request failed with status code 503
ERR     at createError (/path-to-app/axios/lib/core/createError.js:16:15)
ERR     at settle (/path-to-app/axios/lib/core/settle.js:17:12)
ERR     at IncomingMessage.handleStreamEnd (/path-to-app/axios/lib/adapters/http.js:237:11)
ERR     at IncomingMessage.emit (events.js:198:15)
ERR     at endReadableNT (_stream_readable.js:1139:12)
ERR     at processTicksAndRejections (internal/process/task_queues.js:81:17)

What might I have missed? Are additional HTTP headers necessary to make the request succeed?

UPDATE: added destination information to the code snippet and completed error message.

2nd UPDATE: The destination config looks similar to this:

Name: <MY_DESTINATION>
Type: HTTP
URL: http://...    //this matches the cloud connector host, i.e. in SAP Cloud Platform Cockpit --> Cloud Connectors --> Exposed Back-End Systems
ProxyType: OnPremise
Authentication: BasicAuthentication
User: <USERNAME>
Password: <PASSWORD>

回答1:

After some investigation the location ID turned out to cause the problem. It had been set to a specific value on the destination and the cloud connector. Therefore, the cloud connector would only accept requests providing this property.

There were no errors in the cloud connector's logs. But remotely debugging the application (following these instructions) brought up this error message:

There is no SAP Cloud Connector (SCC) connected to your subaccount. Requested opening of a tunnel for subaccount "SUBACCOUNT_ID" and SCC location ID, with default value, that is empty string or simply not configured. Check the configuration on SCC and cloud side.

Using useOrFetchDestination from the SAP Cloud SDK JavaScript to retrieve destination information did not return this property which is why it had never been added to a request.

The current workaround is to remove the location ID from both the destination and the cloud connector. Then the requests succeed.

Is there a way to retrieve the location ID of a destination?

Update: The location ID can be retrieved from the destination using the originalProperties property. If present, it holds the property called CloudConnectorLocationId. As described here this value can be added as SAP-Connectivity-SCC-Location_ID header to the request.

Thanks Dennis H for your support.



回答2:

Update:

To be honest, I'm a little stumped currently. Given that your request works with the Java SDK, I, too, am confused as to why it fails in JS.

Have you tried to query the same exact service in Java? (I.e. are you sure the path mappings in your cloud connector work correctly?) Can you share your destination config from the cloud cockpit? Is there any other log output except the error that you've already posted? Do you have access to the cloud connector logs? (I.e. can you somehow find out where the request fails?


Original answer:

If this is the exact code you're using:

DocumentInfoRecord.requestBuilder()
  .getAll()
  .execute({});

Then the request won't work anyway, since you have not provided a correct destination to the execute function. You need to either pass a destination itself, e.g.:

.execute({
  url: 'https://my.onprem.system',
  ...
})

(but I imagine this being quite difficult for an on-prem destination), or provide a destination name the JWT of the current request, e.g.:

.execute({
  destinationName: 'my-on-prem-destination',
  jwt: myJwt
})

If this is not the code you're using, could you please provide a more representative code snippet and the full stack trace of the error?