Skip to Content
0
Jun 09, 2020 at 05:55 PM

CAP: Consume S/4HANA external service not working

757 Views

Hi,

I'm trying to consume an external service in CDS, I´m working in Cloud Foundry Environment in a Business Application with WebIDE, y followed the documentation Consuming Services and the OpenSAP course Unit 2: Connecting to Remote Services, and finally de posts CAP: Consume External Service – Part 1, CAP: Consume External Service – Part 2. It works fine when I do it with the OData NorthWind example, but when I try it with an S/4HANA service y receive this error:

{"message":"Attempting to retrieve destination from environment variable.","level":"info","custom_fields":{"package":"core","messageContext":"destination-accessor"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-06-09T17:25:02.076Z","msg":"Attempting to retrieve destination from environment variable.","written_ts":1591723502076,"written_at":"2020-06-09T17:25:02.076Z"}
{"message":"Could not retrieve destination from environment variable.","level":"info","custom_fields":{"package":"core","messageContext":"destination-accessor"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-06-09T17:25:02.078Z","msg":"Could not retrieve destination from environment variable.","written_ts":1591723502078,"written_at":"2020-06-09T17:25:02.078Z"}
{"message":"Attempting to retrieve destination from service binding.","level":"info","custom_fields":{"package":"core","messageContext":"destination-accessor"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-06-09T17:25:02.078Z","msg":"Attempting to retrieve destination from service binding.","written_ts":1591723502078,"written_at":"2020-06-09T17:25:02.078Z"}
{"message":"Unable to find a service binding for given name \"SCP-TO-DEVVIRTUALNEO\"! Found the following bindings: s4cap-s4cap-uaa-S0019246072-workspKL8pDH6LAjq+PI9x, s4cap-conns4cap-S0019246072-workspOeKcqQC3TvHCyLFe, s4cap-s4cap-db-hdi-container-S0019dJBJdRo5DnLNI72P, s4cap-dests4cap-S0019246072-worksp6fvZ7pO3i0qk1mEo.\n ","level":"info","custom_fields":{"package":"core","messageContext":"destination-accessor"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-06-09T17:25:02.079Z","msg":"Unable to find a service binding for given name \"SCP-TO-DEVVIRTUALNEO\"! Found the following bindings: s4cap-s4cap-uaa-S0019246072-workspKL8pDH6LAjq+PI9x, s4cap-conns4cap-S0019246072-workspOeKcqQC3TvHCyLFe, s4cap-s4cap-db-hdi-container-S0019dJBJdRo5DnLNI72P, s4cap-dests4cap-S0019246072-worksp6fvZ7pO3i0qk1mEo.\n ","written_ts":1591723502079,"written_at":"2020-06-09T17:25:02.079Z"}
{"message":"Could not retrieve destination from service binding.","level":"info","custom_fields":{"package":"core","messageContext":"destination-accessor"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-06-09T17:25:02.079Z","msg":"Could not retrieve destination from service binding.","written_ts":1591723502079,"written_at":"2020-06-09T17:25:02.079Z"}
{"message":"If you are not using SAP Extension Factory, this information probably does not concern you.","level":"info","custom_fields":{"package":"core","messageContext":"destination-accessor"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-06-09T17:25:02.079Z","msg":"If you are not using SAP Extension Factory, this information probably does not concern you.","written_ts":1591723502079,"written_at":"2020-06-09T17:25:02.079Z"}
{"message":"Attempting to retrieve destination from destination service.","level":"info","custom_fields":{"package":"core","messageContext":"destination-accessor"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-06-09T17:25:02.080Z","msg":"Attempting to retrieve destination from destination service.","written_ts":1591723502080,"written_at":"2020-06-09T17:25:02.080Z"}
{"message":"Unable to match a specific XSUAA service instance to the given JWT. The following XSUAA instances are bound: s4cap-SCPCFQAS91f91a19-69fd-4fcc-95de-a14f3e41a809!t4787. The following one will be selected: s4cap-SCPCFQAS91f91a19-69fd-4fcc-95de-a14f3e41a809!t4787. This might produce errors in other parts of the system!","level":"warn","custom_fields":{"package":"core","messageContext":"environment-accessor"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-06-09T17:25:02.081Z","msg":"Unable to match a specific XSUAA service instance to the given JWT. The following XSUAA instances are bound: s4cap-SCPCFQAS91f91a19-69fd-4fcc-95de-a14f3e41a809!t4787. The following one will be selected: s4cap-SCPCFQAS91f91a19-69fd-4fcc-95de-a14f3e41a809!t4787. This might produce errors in other parts of the system!","written_ts":1591723502081,"written_at":"2020-06-09T17:25:02.081Z"}
{"message":"Sucessfully retrieved destination from destination service.","level":"info","custom_fields":{"package":"core","messageContext":"destination-accessor"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-06-09T17:25:02.365Z","msg":"Sucessfully retrieved destination from destination service.","written_ts":1591723502365,"written_at":"2020-06-09T17:25:02.365Z"}
{"message":"OnPrem destination proxy settings from connectivity service will be used.","level":"info","custom_fields":{"package":"core","messageContext":"proxy-util"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-06-09T17:25:02.365Z","msg":"OnPrem destination proxy settings from connectivity service will be used.","written_ts":1591723502365,"written_at":"2020-06-09T17:25:02.365Z"}
{"message":"Unable to match a specific XSUAA service instance to the given JWT. The following XSUAA instances are bound: s4cap-SCPCFQAS91f91a19-69fd-4fcc-95de-a14f3e41a809!t4787. The following one will be selected: s4cap-SCPCFQAS91f91a19-69fd-4fcc-95de-a14f3e41a809!t4787. This might produce errors in other parts of the system!","level":"warn","custom_fields":{"package":"core","messageContext":"environment-accessor"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-06-09T17:25:02.366Z","msg":"Unable to match a specific XSUAA service instance to the given JWT. The following XSUAA instances are bound: s4cap-SCPCFQAS91f91a19-69fd-4fcc-95de-a14f3e41a809!t4787. The following one will be selected: s4cap-SCPCFQAS91f91a19-69fd-4fcc-95de-a14f3e41a809!t4787. This might produce errors in other parts of the system!","written_ts":1591723502366,"written_at":"2020-06-09T17:25:02.366Z"}
{"message":"Unable to create \"SAP-Connectivity-Authentication\" header: no JWT found on the current request.\n Continuing without header. Connecting to on-premise systems may not be possible.","level":"warn","custom_fields":{"package":"core","messageContext":"connectivity-service"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-06-09T17:25:02.538Z","msg":"Unable to create \"SAP-Connectivity-Authentication\" header: no JWT found on the current request.\n Continuing without header. Connecting to on-premise systems may not be possible.","written_ts":1591723502538,"written_at":"2020-06-09T17:25:02.538Z"}
{"message":"OnPrem destination proxy settings from connectivity service will be used.","level":"info","custom_fields":{"package":"core","messageContext":"proxy-util"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-06-09T17:25:02.539Z","msg":"OnPrem destination proxy settings from connectivity service will be used.","written_ts":1591723502539,"written_at":"2020-06-09T17:25:02.539Z"}
[2020-06-09T17:25:02.681Z | ERROR | 1003549]: Request failed with status code 403
[2020-06-09T17:25:02.681Z | ERROR | 1003549]: Error stacktrace: Error: Request failed with status code 403 at createError (/home/vcap/app/node_modules/axios/lib/core/createError.js:16:15) at settle (/home/vcap/app/node_modules/axios/lib/core/settle.js:17:12) at IncomingMessage.handleStreamEnd (/home/vcap/app/node_modules/axios/lib/adapters/http.js:236:11) at IncomingMessage.emit (events.js:323:22) at endReadableNT (_stream_readable.js:1204:12) at processTicksAndRejections (internal/process/task_queues.js:84:21)

this is my mta.yml

ID: s4cap
_schema-version: '2.1'
parameters:
  deploy_mode: html5-repo
version: 0.0.1
modules:
  - name: s4cap-approuter
    type: approuter.nodejs
    path: s4cap-approuter
    parameters:
      disk-quota: 256M
      memory: 256M
    requires:
      - name: s4cap_html5_repo_runtime
      - name: dest_s4cap
      - name: conn_s4cap
      - name: s4cap-uaa
      - name: srv_api
        group: destinations
        properties:
          forwardAuthToken: true
          name: srv_api
          url: '~{url}'
  - name: s4cap_ui_deployer
    type: com.sap.html5.application-content
    path: s4cap_ui_deployer
    requires:
      - name: s4cap_html5_repo_host
    build-parameters:
      requires:
        - name: s4capui
          artifacts:
            - './*'
          target-path: resources/s4capui
  - name: s4cap-db
    type: hdb
    path: db
    parameters:
      memory: 256M
      disk-quota: 512M
    requires:
      - name: s4cap-db-hdi-container
  - name: s4cap-srv
    type: nodejs
    path: srv
    parameters:
      memory: 512M
      disk-quota: 512M
    provides:
      - name: srv_api
        properties:
          url: '${default-url}'
    requires:
      - name: s4cap-db-hdi-container
      - name: s4cap-uaa
      - name: dest_s4cap
      - name: conn_s4cap
  - name: s4capui
    type: html5
    path: s4capui
    build-parameters:
      builder: custom
      commands:
        - npm install
        - npm run build
      supported-platforms: []
      build-result: dist
resources:
  - name: s4cap_html5_repo_runtime
    parameters:
      service-plan: app-runtime
      service: html5-apps-repo
    type: org.cloudfoundry.managed-service
  - name: s4cap_html5_repo_host
    parameters:
      service-plan: app-host
      service: html5-apps-repo
    type: org.cloudfoundry.managed-service
  - name: s4cap-db-hdi-container
    type: com.sap.xs.hdi-container
    properties:
      hdi-container-name: '${service-name}'
  - name: s4cap-uaa
    type: org.cloudfoundry.managed-service
    parameters:
      service-plan: application
      service: xsuaa
      config:
        xsappname: 's4cap-${space}'
        tenant-mode: dedicated
      path: xs-security.json
  - name: dest_s4cap
    parameters:
      service-plan: lite
      service: destination
    type: org.cloudfoundry.managed-service
  - name: conn_s4cap
    parameters:
      service-plan: lite
      service: connectivity
    type: org.cloudfoundry.managed-service

and this is my package.json

{
	"name": "s4cap-srv",
	"description": "Generated from ../package.json, do not change!",
	"version": "1.0.0",
	"dependencies": {
		"@sap/cloud-sdk-core": "^1.17.2",
		"@sap/hana-client": "^2.4.196",
		"@sap/xsenv": "^2.2.0",
		"@sap/xssec": "^2.2.5",
		"@sap/cds": "^3.34.2",
		"passport": "^0.4.1",
		"express": "^4.17.1",
		"axios": "^0.19.2",
		"moment": "^2.24.0",
		"moment-timezone": "^0.5.28",
		"execution-time": "^1.4.1",
		"hdb": "^0.17.1",
		"uuid": "^3.4.0"


	},
	"engines": {
		"node": "^10 || ^12"
	},
	"devDependencies": {},
	"scripts": {
		"postinstall": "npm dedupe && node .build.js",
		"start": "node ./node_modules/@sap/cds/bin/cds.js serve gen/csn.json",
		"watch": "nodemon -w . -i node_modules/**,.git/** -e cds -x npm run build",
		"start:express": "node --inspect express.js"
	},
	"private": true,
	"cds": {
		"requires": {
			"db": {
				"kind": "hana",
				"model": "gen/csn.json"
			},
			"uaa": {
				"kind": "xsuaa"
			},
			"Z_OD_SCP_CORE_0001_SRV": {
				"kind": "odata",
				"model": "srv/external/Z_OD_SCP_CORE_0001_SRV",
				"credentials": {
					"destination": "SCP-TO-DEVVIRTUALNEO",
					"requestTimeout": 30000
				},
				"pool": {
					"min": 1,
					"max": 10
				}
			},
			"Z_OD_SCP_VEHI_SRV": {
				"kind": "odata",
				"model": "srv/external/Z_OD_SCP_VEHI_SRV",
				"credentials": {
					"destination": "SCP-TO-DEVVIRTUALNEO",
					"requestTimeout": 30000
				},
				"pool": {
					"min": 1,
					"max": 10
				}
			},
			"ZCDS_VW_TEST_CDS": {
				"kind": "odata",
				"model": "srv/external/ZCDS_VW_TEST_CDS",
				"credentials": {
					"destination": "SCP-TO-DEVVIRTUALNEO",
					"requestTimeout": 30000
				},
				"pool": {
					"min": 1,
					"max": 10
				}
			},
			"NorthWind": {
				"kind": "odata",
				"model": "srv/external/NorthWind",
				"credentials": {
					"destination": "NorthWind",
					"requestTimeout": 30000
				},
				"pool": {
					"min": 1,
					"max": 10
				}
			}
		},
		"auth": {
			"passport": {
				"strategy": "JWT"
			}
		},
		"odata": {
			"version": "v4"
		}
	}
}

This is how I configured the destination

Thank's in advance