cancel
Showing results for 
Search instead for 
Did you mean: 

Get server and client ip address and port

Former Member
0 Kudos

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!!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I was happy since it worked, but then I remembered that I read in the blog below that we ought to use only the clases which names begin with WD or IWD only... is there another way to get the port??

/people/bertram.ganz/blog/2005/02/02/never-ever-hijack-internal-web-dynpro-classes-and-interfaces

former_member182374
Active Contributor
0 Kudos

Hi Alejandro Monteverde,

See this thread:

Also, you can read the http header for getting server & port.

BTW, if you need the url for navigating to a portal component/application/document you don't need the server & port, you can use relative path.

For example if you are running WD application called 'A', you can open WD called 'B' you can write:

IWDWindow window = wdComponentAPI.getWindowManager().createExternalWindow("/webdynpro/dispatcher/local/Bprj/Bapp", "", false);
window.open();

In your case use:

IWDWindow window = wdComponentAPI.getWindowManager().createExternalWindow("/VideosTutorialesGAT/index.jsp", "", false);
window.open();

Same for KM document or JSP file...

Regards,

Omri

Former Member
0 Kudos

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

Answers (3)

Answers (3)

Former Member
0 Kudos

That last one is the answer I was looking for!!! the only issue there is that you should multiply by 100 instead of multiplying by 10.

Thanks a lot!!!

Former Member
0 Kudos

Yeah!! it really worked!!

Thanks a lot!!

abhijeet_mukkawar
Active Contributor
0 Kudos

hi ,

check out following code

String hostName = TaskBinder.getCurrentTask().getProtocolAdapter().getServerName();

int port = TaskBinder.getCurrentTask().getProtocolAdapter().getServerPort();

hope it helps

reagards,

abhijeet