Skip to Content
avatar image
Former Member

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Mar 28, 2007 at 04:31 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Omri Cohen

      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

  • avatar image
    Former Member
    Mar 28, 2007 at 02:16 PM

    hi ,

    check out following code

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

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

    hope it helps

    reagards,

    abhijeet

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 28, 2007 at 04:27 PM

    Yeah!! it really worked!!

    Thanks a lot!!

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 02, 2007 at 04:59 PM

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

    Add comment
    10|10000 characters needed characters exceeded