On Jun 17, 2008, at 1:06 PM, Magic Badger wrote:
> Long time user, first time poster.
>
> Is there any way for a resource to be able to retrieve the IP address
> of the requesting client? I would imagine that the HttpServletRequest
> object would contain such informatio, but suspect there is no way to
> access this using Jersey.
>
> Any help much appreciated!
>
HttpServletRequest.getRemoteAddr() will do what you want. To access
the HttpServletRequest in a resource class just add a field:
@Context HttpServletRequest hsr;
and the runtime will inject it on the resource class instance. You can
also use a constructor or method parameter if that is more convenient.
Obviously this will only work if the app is hosted in a Servlet
container.
Marc.
---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.