Think Good
View list of my frequently visited bloglines
Tags - Categories : All | General | Software Development

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 samples\userguide\example4\LogHandler.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!!


Add a comment

Title
Body
HTML : b, i, blockquote, br, p, pre, a href="", ul, ol, li
Math Quiz 1 + 5 = (Helps stop blog spam)
Name
E-mail address
Website
Remember me Yes  No 

E-mail addresses are not publicly displayed, so please only leave your e-mail address if you would like to be notified when new comments are added to this blog entry (you can opt-out later).

TrackBack to http://radio.javaranch.com/balajidl/addTrackBack.action?entry=1139245423141