A small code snippet to get the ip address of the webservices client invoking Apache Axis for java based webservices.
Add the following code in your webservices method which will invoked by SOAP client.
// Based on Axis 1.1
import org.apache.axis.MessageContext;
import org.apache.axis.transport.http.HTTPConstants;
...
...
public class SomeService
public string SomeMethod(String someInput)
{
//write your other codes here..
MessageContext context = MessageContext.getCurrentContext();
String callerIP = (String)context.getProperty(HTTPConstants.MC_REMOTE_ADDR);
//use the callerIP variable for tracking purpose..
...other code..
}
import org.apache.axis.MessageContext;
import org.apache.axis.transport.http.HTTPConstants;
...
...
public class SomeService
public string SomeMethod(String someInput)
{
//write your other codes here..
MessageContext context = MessageContext.getCurrentContext();
String callerIP = (String)context.getProperty(HTTPConstants.MC_REMOTE_ADDR);
//use the callerIP variable for tracking purpose..
...other code..
}
//based on Axis 1.3
import org.apache.axis.Constants;
import org.apache.axis.MessageContext;
....
....
MessageContext messageContext = MessageContext.getCurrentContext();
String ipAddress = messageContext.getStrProp(Constants.MC_REMOTE_ADDR);
Also have a look at the sample file samples\userguide\example4\LogHandler.java located in the Axis package for more info..
import org.apache.axis.Constants;
import org.apache.axis.MessageContext;
....
....
MessageContext messageContext = MessageContext.getCurrentContext();
String ipAddress = messageContext.getStrProp(Constants.MC_REMOTE_ADDR);
TrackBacks[0]
Comments[4]
Posted by balajidl on 06 February 2006 18:03:43 CET
Reply |
Permalink
Re: Get IP address of webservices client - Apache Axis for Java
How to get the IP address for client implemented based on Apache SOAP?
Or how to get the instance of org.apache.rpc.soap.SOAPContext?
Thanks.
Comment from Anonymous on 18 February 2006 05:46:23 CET
Thanks for the tip!
Comment from Perfume Master on 15 November 2007 20:43:51 CET
Great! It works!
Comment from Anonymous on 08 April 2008 16:31:11 CEST
It works, Thanks!!
Comment from Hari on 16 July 2008 18:13:17 CEST
TrackBack to http://radio.javaranch.com/balajidl/addTrackBack.action?entry=1139245423141