I am writing a Java Rest Web Service and need the caller\'s IP Address. I thought I saw this in the cookie once but now I don\'t see it. Is there a consistent place to get this
You could do something like this:
@WebService
public class YourService {
@Resource
WebServiceContext webServiceContext;
@WebMethod
public String myMethod() {
MessageContext messageContext = webServiceContext.getMessageContext();
HttpServletRequest request = (HttpServletRequest) messageContext.get(MessageContext.SERVLET_REQUEST);
String callerIpAddress = request.getRemoteAddr();
System.out.println("Caller IP = " + callerIpAddress);
}
}