Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
guanjj
Explorer
What: This blog post will show how to debug with external service for the CAP(SAP Cloud Application Programming Model) project in local IDE.

Why: When develop the CAP project, we always integrate with other SAP BTP service. If in SAP BAS(Business Application Studio), you can easily bind external service to your application to debug. Also recently, run CAP Java Apps with service bindings is not supported yet. So when debug with local VS code, you should try another way.

How: 

Suppose you will need a Malware Service for scan uploaded file.

Firstly you should create a new malware-scanner service. Then bind it to your application. After that, you can check the System-Provided Environment Variables.

It will likes like:
{
"VCAP_SERVICES": {
"malware-scanner": [
{
"label": "malware-scanner",
"provider": null,
"plan": "clamav",
"name": "malware-service",
"tags": [],
"instance_guid": "xxxxx",
"instance_name": "malware-service",
"binding_guid": "xxxxx",
"binding_name": null,
"credentials": {
"uri": "malware-scanner.cf.xxx.hana.ondemand.com",
"sync_scan_url": "https://sync_scan.cf.xxx.hana.ondemand.com",
"async_scan_url": "https://async_scan.cf.xxx.hana.ondemand.com",
"username": "xxxxx",
"password": "xxxxx"
},
"syslog_drain_url": null,
"volume_mounts": []
}
],
"hana": [...
]
}
}

Then you can copy all content into your local project's "default-env.json" file. If not exist, you can create one in root path.

 

After preparation done. You will need export this file as system variables. Open the terminal in the project root path, then enter following command:
TMP_VCAP_SERVICES=$(jq '.VCAP_SERVICES' default-env.json|jq -c .)

export VCAP_SERVICES=$TMP_VCAP_SERVICES

Then your local PC have same VCAP_SERVICES as on BTP. You can start your application to debug as normal now.

PS: You need install jq.node first;
npm install jq.node -g

 

In conclusion, when we development CAP Java project in local environment, we can fetch remote service via url link defined in system environment. Further more, you can refer to capire - Hybrid Testing (tools.sap)

One day it should support CAP Java for service bindings.

Any suggestions and ideas are most welcome!

 
2 Comments