Get IP address of webservices client – Apache Axis for Java

27 sec read

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..
}

//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 samplesuserguideexample4LogHandler.java located in the Axis package for more info..

Related posts:

5 Replies to “Get IP address of webservices client – Apache Axis…”

  1. 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.

  2. 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

Leave a Reply

Your email address will not be published. Required fields are marked *