Skip to Content

Not able to connect to SAP ABAP system using java Application

Feb 26 at 06:23 AM


avatar image
Former Member

Hi all,

I have a java spring boot application deployed in CP which is trying to connect to SAP ABAP system.

Everytime, I am getting 502 error. Also, using postman Im able to access the end url but not with java application.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

avatar image
Former Member Feb 26 at 09:12 AM


Finally succeeded in getting the response.

List of changes :

1. Connect to HTTPUrlConnection via proxy

Proxy proxy = getProxy(proxyType);

(HttpURLConnection) url.openConnection(proxy)

//To get the proxy host and proxy port..

private Proxy getProxy(String proxyType) { String proxyHost = null; int proxyPort; if (ON_PREMISE_PROXY.equals(proxyType)) { // Get proxy for on-premise destinations proxyHost = System.getenv("HC_OP_HTTP_PROXY_HOST"); proxyPort = Integer.parseInt(System.getenv("HC_OP_HTTP_PROXY_PORT")); } else { // Get proxy for internet destinations proxyHost = System.getProperty("http.proxyHost"); proxyPort = Integer.parseInt(System.getProperty("http.proxyPort")); } logger.error(proxyHost + " : proxy port " + proxyPort); return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); }

2. Add the "SAP-Connectivity-ConsumerAccount" header in the connection .

TenantContext tContext = null;

tContext = (TenantContext) temp.lookup("TenantContext");

connection.setRequestProperty("SAP-Connectivity-ConsumerAccount", URLManager.tContext.getAccountName());

Feel free to contact me in case you did not understand...

10 |10000 characters needed characters left characters exceeded