Obtain client ip address from web service

I have developed a webservice in java.

I have a single application which needs to be concurrently accessed by multiple clients. Therefore I need to know which client has made each request. Is there a way to obtain the client ip address from the soap response?

eadam-ukAsked:
Who is Participating?
 
petiexCommented:
Inject a WebServiceContext instance into your WebService class, and use it in each WebMethod to get the current request's MessageContext Map. Get the SERVLET_REQUEST item from that, cast as an HttpServletRequest. From that HttpServletRequest, you can invoke getRemoteAddr() to get the client's IP.

@WebService
public class MyService{

@Resource
WebServiceContext wsCtxt;

@WebMethod
public void myWebMethod(){

MessageContext msgCtxt = wsCtxt.getMessageContext();
HttpServletRequest req = (HttpServletRequest)msgCtxt.get(MessageContext.SERVLET_REQUEST);
String clientIP = req.getRemoteAddr();

}
see:
http://forums.java.net/jive/message.jspa?messageID=213272
0
 
tbeernotCommented:
The answer from petiex above assume some things about the SOAP library you are using and that you are using HTTP as the transport. Let me first ask that: what SOAP library are you using and what is the transport?

The answer is essentially correct though: you need to get access to you transport protocol (usually HTTP) and get it from there.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.