Tuesday, December 29, 2009

Get Client IP in Axis2

If you are using Axis2 for developing your web services, then in most cases you would want to obtain the client's IP address.

The following method gives you that.

//Import statement to import MessageContext class
import org.apache.axis2.context.MessageContext;

/*
* This method gets the client IP address using axis2 MessageContext
*
* @return Client IP : String
*/
private String getClientIP () {

      return (String)(MessageContext.getCurrentMessageContext()).getProperty(MessageContext.REMOTE_ADDR);

}

No comments:

Post a Comment