Obtaining the client host from a webservice

Discussion in 'Java' started by Roberto, Oct 18, 2004.

  1. Roberto

    Roberto Guest

    Hi, I need to know, inside an Axis web service, the client request
    hostname. I.E.:

    Client Webservice (AXIS server)
    Hostname 1 -----> Hostname 2

    Inside the source of WebService (usually named as
    WebServiceBindingImpl.java) I would like to know the hostname 1 of client.

    Any idea?

    Inviato da www.mynewsgate.net
    Roberto, Oct 18, 2004
    #1
    1. Advertising

  2. Roberto

    Andy Flowers Guest

    Try this...

    // first get the message context
    MessageContext mc = MessageContext.getCurrentContext();

    // then get the remote address from the current HTTP request directed at the
    web service
    String remote_client =
    ((javax.servlet.http.HttpServletRequest)mc.getProperty(org.apache.axis.transport.http.HTTPConstants.MC_HTTP_SERVLETREQUEST)).getRemoteHost();

    "Roberto" <> wrote in message
    news:...
    > Hi, I need to know, inside an Axis web service, the client request
    > hostname. I.E.:
    >
    > Client Webservice (AXIS server)
    > Hostname 1 -----> Hostname 2
    >
    > Inside the source of WebService (usually named as
    > WebServiceBindingImpl.java) I would like to know the hostname 1 of client.
    >
    > Any idea?
    >
    > Inviato da www.mynewsgate.net
    Andy Flowers, Oct 18, 2004
    #2
    1. Advertising

  3. "Andy Flowers" <> wrote in message news:<ZSPcd.265$>...
    > Try this...
    >
    > // first get the message context
    > MessageContext mc = MessageContext.getCurrentContext();
    >
    > // then get the remote address from the current HTTP request directed at the
    > web service
    > String remote_client =
    > ((javax.servlet.http.HttpServletRequest)mc.getProperty(org.apache.axis.transport.http.HTTPConstants.MC_HTTP_SERVLETREQUEST)).getRemoteHost();


    mc.getProperty(org.apache.axis.transport.http.HTTPConstants.MC_HTTP_SERVLETREQUEST))

    is NULL, so I cannot call getRemoteHost().

    Then I tried:

    Iterator i = mc.getPropertyNames();
    while (i.hasNext()) {
    String v = (String) i.next();
    System.out.println (v + " = " + msg.getProperty(v));
    }

    and the output is:

    home.dir = .
    realpath = axis/services/EsempioService
    jws.classDir = jwsClasses
    attachments.directory = C:\Documents and Settings\manganelli\Local Settings\Temp
    transport.url = http://andromeda:8080/axis/services/EsempioService
    path = axis/services/EsempioService

    any idea?
    Roberto Milani 2002, Oct 19, 2004
    #3
  4. Roberto

    Andy Flowers Guest

    What version of AXIS are you using ?

    I use version AXIS version 1.1, in conjunction with Tomcat 4.1, and have no
    problems getting this property.

    If you have a look at the source, AxisServlet.java (which you can get from
    http://ws.apache.org/axis/download.cgi) you ill see that this property is
    set in the doGet() handler of the AXIS servlet.

    You could also use the source to debug what may be happening in your
    scenario.

    "Roberto Milani 2002" <> wrote in message
    news:...
    > "Andy Flowers" <> wrote in message
    > news:<ZSPcd.265$>...
    >> Try this...
    >>
    >> // first get the message context
    >> MessageContext mc = MessageContext.getCurrentContext();
    >>
    >> // then get the remote address from the current HTTP request directed at
    >> the
    >> web service
    >> String remote_client =
    >> ((javax.servlet.http.HttpServletRequest)mc.getProperty(org.apache.axis.transport.http.HTTPConstants.MC_HTTP_SERVLETREQUEST)).getRemoteHost();

    >
    > mc.getProperty(org.apache.axis.transport.http.HTTPConstants.MC_HTTP_SERVLETREQUEST))
    >
    > is NULL, so I cannot call getRemoteHost().
    >
    > Then I tried:
    >
    > Iterator i = mc.getPropertyNames();
    > while (i.hasNext()) {
    > String v = (String) i.next();
    > System.out.println (v + " = " + msg.getProperty(v));
    > }
    >
    > and the output is:
    >
    > home.dir = .
    > realpath = axis/services/EsempioService
    > jws.classDir = jwsClasses
    > attachments.directory = C:\Documents and Settings\manganelli\Local
    > Settings\Temp
    > transport.url = http://andromeda:8080/axis/services/EsempioService
    > path = axis/services/EsempioService
    >
    > any idea?
    Andy Flowers, Nov 2, 2004
    #4
  5. Roberto

    hbasavar

    Joined:
    Mar 26, 2010
    Messages:
    1
    Thanks for this post. I was able to use the solution provided on Axis 2. I had to change the reference appropriately but works great. It returns IP address and that was what I wanted.:D
    hbasavar, Mar 26, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Orpheus66
    Replies:
    0
    Views:
    4,393
    Orpheus66
    Jul 30, 2003
  2. Jerry Qu
    Replies:
    1
    Views:
    442
    lee atkinson
    Feb 20, 2009
  3. kw

    Obtaining element ID for client script

    kw, Aug 23, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    122
  4. What-a-Tool

    Method for obtaining client display size?

    What-a-Tool, Jan 4, 2005, in forum: ASP General
    Replies:
    4
    Views:
    157
    What-a-Tool
    Jan 4, 2005
  5. Paul

    obtaining client side IP

    Paul, May 19, 2005, in forum: ASP General
    Replies:
    6
    Views:
    146
    Jeff Cochran
    May 19, 2005
Loading...

Share This Page