Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Get server and client ip address and port

Hi!! I want to get the address and port of the server where the application is running and the same information of the user who is connecting.

Since I'm using NW04s I can no longer use the hijack:

HttpServletRequest req = ((IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletRequest();

String baseURL = "http://"req.getServerName()":"req.getServerPort()"/VideosTutorialesGAT/index.jsp";

I'm succesfully using the WDProtocolAdapter to get the address, like this:

String dirIP = WDProtocolAdapter.getProtocolAdapter().getRequestObject().getClientHostAddress();

But I can not find the right command to get the port number... where can I find this information??

Thanks a lot!!

Former Member
Former Member replied


Your hint leads me to the following:

1. returns InetAddress of local host, inetAddress.getCanonicalHostName() returns the fully qualified domain name for this IP address. Now we have FQDN of server:

final myAddress =;
final String httpHostName = myAddress.getCanonicalHostName();

2. If you know, WebAS Java sets ceratin JVM properties when starting JVM, these properties are available via System.getProperty(). So we can get following variable:

final String instanceNumber = System.getProperty("SAPSYSTEM").toString();

4. Http port in WebAS Java is composed as 50000 + instanceNumber * 10 (50##0 where ## is instance nuimber), hence

final int httpPortNumber = 50000 + 10 * Integer.parseInt( instanceNumber );

Puzzle solved! No non-API calls! Neither WD API calls

Valery Silaev

SaM Solutions

Message was edited by:

Valery Silaev

0 View this answer in context

Helpful Answer

Not what you were looking for? View more on this topic or Ask a question