SAP Business Technology Platform (BTP) offers a complete suite of tools and services to access on-premise systems such as SAP S/4HANA, SAP HANA On-Premise, any OData service, generic HTTP services, or any other service supporting the TCP/IP protocol. The SAP Cloud Application Programming Model (CAP) provides tools and guidance for developing and testing cloud services, prioritizing local development. The challenge of integrating on-premise services with a local CAP application development setup is where CAP’s value truly shines. The following blog serves as a comprehensive guide, detailing the steps to achieve this integration.
To establish a secure connection to on-premise services, it is essential to install the Cloud Connector within your local network environment. Ensure that the target on-premise system is accessible from this network, as the Cloud Connector will facilitate communication between your cloud applications and the on-premise services.
The Cloud Connector can be installed on variety of operating systems as described here.
To facilitate the initial setup of connectivity between SAP BTP and the Cloud Connector, the authentication information has already been prepared. Download the authentication data file from your SAP BTP subbaccount:
Establish connection between Cloud Connector and your SAP BTP subaccount:
Your Cloud Connector is now available to your SAP BTP subaccount.
Let's expose the resources that need to be made visible in your SAP BTP subaccount:
The exposed host:port combination is now available, in addition resources must be exposed:
The configuration is now complete. By checking the 'Cloud Connectors' in the relevant SAP BTP subaccount, you should see the already configured Cloud Connector and the exposed backend system, for example: 'localhost:4004'.
To access an on-premise backend system, the CAP application must utilize the destination and connectivity services provided by SAP BTP. If you don't already have a CAP application, you can easily set up a new one with the following command:
cds init sample --add sample && cd sampleEnable both destination and connectivity, and also deployment via mta with the following command:
cds add destination,connectivity,xsuaa,mtaSubsequent deployment will automatically create the required SAP BTP instances for the destination and connectivity services.
If you prefer to manually instantiate the destination and connectivity services, you can do so with the following commands:
cf create-service destination lite sample-destination
cf create-service-key sample-destination sample-destination-keycf create-service connectivity lite sample-connectivity
cf create-service-key sample-connectivity sample-connectivity-keyTo access the SAP BTP services locally in a hybrid development environment, bind the necessary SAP BTP services. For connectivity, set the proxy host to localhost, as it defaults to an internally accessible SAP BTP hostname (see Overwrite Cloud Service Credentials):
npx cds bind --to sample-connectivity --credentials "{ \"onpremise_proxy_host\": \"localhost\" }"
npx cds bind --to sample-destination
npx cds bind --to sample-authAccessing systems via the connectivity service requires a destination with proxy type OnPremise. The destination can be either on subaccount level or instance based and can be created either via mta or manually in the SAP BTP destination service UI by providing the following parameters, where the host:port must be the same as the previously configured Cloud Connector (localhost:4004) :
Name: 'on-prem-dest'
Type: 'HTTP'
Authentication: 'NoAuthentication'
URL: 'http://localhost:4004'
ProxyType: 'OnPremise'
Description: 'on-premise destination'Destinations can be created alternatively programmatically utilizing the Destination REST API:
npm i -D "@sap-cloud-sdk/http-client"
npm i -D "@sap/xsenv"
npm i -D "@sap/xssec"(async () => {
const xsenv = require('@sap/xsenv')
const xssec = require('@sap/xssec')
const destinationCredentials = xsenv.serviceCredentials({ tag: 'destination' })
const xsuaaService = new xssec.XsuaaService(destinationCredentials)
const token = await xsuaaService.fetchClientCredentialsToken()
const { executeHttpRequest } = require('@sap-cloud-sdk/http-client')
const destinationName = 'on-prem-dest'
const data = JSON.stringify({
Name: destinationName,
Type: 'HTTP',
Description: 'on-prem destination',
URL: 'http://localhost:4004',
ProxyType: 'OnPremise',
Authentication: 'NoAuthentication'
})
try {
const response = await executeHttpRequest({
url: destinationCredentials.uri + "/destination-configuration/v1/instanceDestinations" },{
method: 'POST',headers: {
"Authorization": "Bearer " + token.access_token,
'X-CSRF-Token': 'None'},
data
})
console.log("Create destination", destinationName, response.status, response.statusText)
} catch(e) {
console.log("Failed to create destination", destinationName, e.status, e.response?.data)
}
})()cds bind --exec node createNewDestination.jsIn order to use that destination in a CAP application, a new service needs to be defined with the destination specified as parameter. Add the following configuration to your package.json file providing the name of the already created destination:
"cds": {
"requires": {
"OnPremService": {
"kind": "odata",
"credentials": {
"destination": "on-prem-dest"
}
}
}
}The connectivity proxy port should be forwarded to SAP BTP via a ssh tunnel. In order to open a ssh connection to SAP BTP an already deployed microservice is required. In case you do not have one then an initial deployment can be performed via the following command:
cds upIn case there is no current CAP application to deploy, a newly created CAP app can serve that purpose:
cds init sample --add sample,xsuaa && cd sample && npx cds upOpen a ssh tunnel to the SAP BTP microservice with the connectivity proxy port forwarded with the command:
cf ssh sample-srv -L 20003:connectivityproxy.internal.cf.eu12.hana.ondemand.com:20003The created destination was configured as an HTTP endpoint with port 4004. To test the destination, ensure the CAP service is running locally on port 4004. Start the CAP service with the SAP BTP services bound by executing the following command in the root directory of your CAP project:
PORT=4004 cds bind --exec cds-serve --profile hybridPerform an initial destination check via the Destinations UI in SAP BTP by selecting the destination and then pressing the 'Check Destination' button.
With the Cloud Connector instance running locally and connected to your SAP BTP subaccount, a reachable SAP BTP destination, the tunneled connectivity proxy, and the locally running CAP service, you can perform the final validation of the setup.
Create a new file named testOnPremSystem.js with the following content. Adapt the service name and resource path in the get method to match your specific case:
(async () => {
const cds = require ('@sap/cds')
const onPremService = await cds.connect.to("OnPremService")
try {
let res = await onPremService.get("/odata/v4/test/OnPremService")
console.log(res)
} catch(e) {
console.log(e)
}
})()Run the test with service bindings:
cds bind --exec node testOnPremService.jsWith everything configured and running, the CAP application can be extended with functionality to access an on-premise system.
An already preconfigured and functional example containing scripts to ease the validation of the scenario is available on github in the following repository: github: on-prem-connectivity-example .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 24 | |
| 15 | |
| 14 | |
| 11 | |
| 9 | |
| 9 | |
| 9 | |
| 9 | |
| 9 | |
| 8 |