Jersey RESTful Web Service - How to determine remote host
Clemens Berndt
Greenhorn
Joined: Mar 03, 2009
Posts: 1
posted
0
How can one get the remote address and/or hostname of the client endpoint that originated a request within a Jersey Resource class?
I had a look at the injectable objects available via the @Context annotation, but none provide that sort of information.
Any pointers are much appreciated
Peer Reynders
Bartender
Joined: Aug 19, 2005
Posts: 2906
posted
0
Welcome to Javaranch!
If Jersey is hosted by a Servlet Container you should be able to use:
That is why I left the link at the end of the post.
Apparently"injectability" of HttpServletRequest is part of Jersey, not JAX-RS - so there wouldn't be any mention of it in the documentation of the javax.ws.rs.core package.
It seems that com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider is behind that magic.
Paul Sandoz also mentions that it should be possible to "use a Jersey filter and set properties on @HttpContext" to avoid dependencies on HttpServletRequest - but he doesn't go into any details (though there are some hints here).
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35258
7
posted
0
I just discovered some more hints of how Jersey filters work in the package javadocs of the com.sun.jersey.api.container.filter package.