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

Omri,

Your hint leads me to the following:

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

final java.net.InetAddress myAddress = java.net.InetAddress.getLocalHost();
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

http://www.sam-solutions.net

Message was edited by:

Valery Silaev

0 View this answer in context

Helpful Answer

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