cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP Cloud SDK JAVA: Access from localhost

gamergtx260
Explorer
0 Likes
29,585

Hi all,

My requirement is a simple api call to Business Partner A2X (https://api.sap.com/api/OP_API_BUSINESS_PARTNER_SRV/cloud-sdk/Java). My on-premise S4 HANA system is connected to BTP via cloud connector. I could execute an api call to the Business Partner via a destination created of type on-premise (with sap-client property) and the url is the one maintained in cloud connector. Everything works fine.

What I have done so far:

#1: Now, I would like to access this destination from my local machine without changing and pushing code to BTP. So, I have followed this blog (https://sap.github.io/cloud-sdk/docs/java/features/connectivity/sdk-connectivity-destination-service) and have maintained my environment variable "destinations" as below

set destinations =[{"type":"HTTP","name":"SAPABAPBACKEND","url":"http://SAPABAPBACKEND.dest","proxyType":"on-premise","proxyHost":"localhost","proxyPort":8080,"user":"user","password":"password", "properties": [{"key": "TrustAll", "value": "true"}, {"key": "sap-client", "value": "102"}, {"key": "sap-language", "value": "en"}] }]

When I set this variable, I always get 404. I am not sure if the values above are correct. What exactly is the URL here? Also, if I can use my reverse proxy url of my on-premise system, should it be of type internet? If internet then where should I set the sap-client property?

#2: Removing the destinations variable and copied the environment variables VCAP_SERVICES that was system generated in BTP into the root folder of my application in a default-env.json file but it gives me the error "Failed to get 'destination' service credentials from VCAP_SERVICES variable: no service binding found for service plan '(any)'". I could ssh into my application though.

What has worked so far:

I have tried to use sap-cf-proxy https://github.com/jowavp/sap-cf-proxy and it detects the onpremise destination but only works if I append the sap-client parameter to it like below:

http://localhost:5050/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner?sap-client=102&$selec...

Somehow the sap-client parameter is not considered.

gregorw alexander.duemont What am I missing here? Any help would be greatly appreciated. Thanks so much

Accepted Solutions (0)

Answers (2)

Answers (2)

gregorw
SAP Mentor
SAP Mentor
0 Likes

Please give sap-cf-proxy. My team is using it since over a year to connect from our local development systems to the on prem destination.

gamergtx260
Explorer
0 Likes

Hi Gregor,

Yes, I have tried to use sap-cf-proxy, it detects the onpremise destination but only works if I append the sap-client parameter to it like below: I tested this with postman only.

http://localhost:5050/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner?sap-client=102&$select=BusinessPartner

Somehow the parameter "sap-client" is not taken into account. I have set this both in environment variable and also in destinations.

Please have a look at my code and error below:

Env variable:

[{"type":"HTTP","name":"SAP_ABAP_BACKEND","url":"http://localhost:5050","proxyType":"on-premise","proxyHost":"localhost","proxyPort":5050,"user":"user","password":"password", "sap-client":"102", "properties": [{"key": "TrustAll", "value": "true"}, {"key": "sap-client", "value": "102"}, {"key": "sap-language", "value": "en"}] }]

Code snippet:

the error I get in sap-cf-proxy is below

Thanks

gregorw
SAP Mentor
SAP Mentor
0 Likes

Please create an issue in the sap-cf-proxy project and if you want to get a quick solution try to contribute the fix via a pull request.

gamergtx260
Explorer
0 Likes

Thanks Gregor, I have created a new issue. Kindly take a look.

gamergtx260
Explorer
0 Likes

Hi Gregor,

I was messing with the authentication.js file and changed this the grant_type from password to client_credentials and it worked. I am still trying to understand why it worked. Will keep you posted!

Thanks

Rajkumar Elango

jschneider
Advisor
Advisor
0 Likes

Hi gamergtx260

Unfortunately, you cannot reach On-Premise systems from your local development machine.
This is because the Cloud Connector denies any connections that are not originating from the same subnet as the Cloud Connector is a part of (this is a security feature to prevent attackers from gaining access to your OP systems).

That said, you have the possibility to use the Business Application Studio (BAS) to develop your application.
Within your BAS instance, you can configure your `destinations` environment variable in a way that actually allows you to also reach your On-Premise system.
This works because your BAS instance is backed by a container in your BTP Workspace, which can be connected to via a local proxy that is running on the BAS machine. In consequence, the Cloud Connector accepts the proxied request since it is indeed coming from within the same subnet.

You can learn more about the exact details and how to configure your BAS environment in our documentation.

Best regards,

Johannes

gamergtx260
Explorer
0 Likes

Thank you for your reply. I understand.

Please advise if I can and how to use the reverse proxy url of my on-premise system and create a destination type "Internet" and consume via cloud sdk? I had tried it with no success because I cannot give the "sap-client" property anywhere.

gregorw
SAP Mentor
SAP Mentor
0 Likes

Hi johannes.schneider,

would be great to get your feedback on the option that I've provided with sap-cf-proxy.

CU
Gregor

jschneider
Advisor
Advisor

Hey gregorw

I took a brief look into the sap-cf-proxy project and it seems to do exactly what one would need to reach OP systems even from local dev machines - awesome!
Unfortunately, we (the SAP Cloud SDK team) were not aware of that tool.
I'll reach out to our PO to get some capacity for testing the setup and to extend our documentation.
In general, I think the approach would work very similarly to what we have already described with the BAS scenario (i.e. users would need to configure their local `destinations` environment variable to use the local proxy to reach the OP system).

Thanks for bringing our attention to this project!

Best regards,
Johannes