How to get the client's ip address in jax rs and ws
In this tutorial I'll not teach how to create jax-rs nor jax-ws web service but rather will show how we can get the client's or the ...
https://www.czetsuyatech.com/2015/01/javaee-rest-get-client-ip.html
In this tutorial I'll not teach how to create jax-rs nor jax-ws web service but rather will show how we can get the client's or the caller's ip address who invoke the service.
In jax-rs:
If you need help building jax-rs service here's how I'm doing things: http://czetsuya-tech.blogspot.com/2014/11/rest-testing-with-arquillian-in-jboss.html.
In jax-rs:
//inject
@Context
private HttpServletRequest httpServletRequest;
public void serviceMethod() {
//get the ip
log.debug("IP=" + httpServletRequest.getRemoteAddr());
}
In jax-ws, we inject a different resource but it's almost the same.
@Resource
private WebServiceContext wsContext;
public void serviceMethod() {
MessageContext mc = wsContext.getMessageContext();
HttpServletRequest req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST);
log.debug("IP=" + req.getRemoteAddr());
}
If you need help building jax-rs service here's how I'm doing things: http://czetsuya-tech.blogspot.com/2014/11/rest-testing-with-arquillian-in-jboss.html.




Post a Comment