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.
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.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 samplesuserguideexample4LogHandler.java located in the Axis package for more info..
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.
Thanks for the tip!
Great! It works!
It works, Thanks!!
I have put the code in my web service, deploye it and test it with SoapUI client testing program.
I error logged the ip address, and I noticed that this code is giving me the null pointer
“MessageContext.getCurrentContext();”
Does any one knows whay. Thanks for help!
— regards