Obtaining the client host from a webservice

R

Roberto

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
 
A

Andy Flowers

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();
 
R

Roberto Milani 2002

Andy Flowers said:
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?
 
A

Andy Flowers

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.
 
Joined
Mar 26, 2010
Messages
1
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top