users@jersey.java.net

Re: [Jersey] ResourceFilter and getRemoteAdress

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 30 Nov 2009 14:13:12 +0100

On Nov 30, 2009, at 1:47 PM, Adam Miller wrote:

> I uses ResourceFilter for my jersey resources to do access control
> and it's really great and easy to use.
> Now a would like to access remoteadress ip in my filter. I have a
> ContainerRequest that don't give me the ip.
>

Currently you have to inject HttpServletRequest:

  @Context HttpServletRequest hsr;

And then call:

   hsr.getRemoteAddr()

You can perform injection on the ResourceFilte. A thread local proxy
will be injected, so if you try to access it when a request is not in
scope it will throw an IllegalStateException.

Paul.

> Does any body know how to get the ip? Or is there another preferable
> way to do filtering based on ip.
>
> best regards Adam