users@jersey.java.net

Re: [Jersey] Re: Resource Filter/Interception/Handler

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 29 Oct 2008 12:11:30 +0100

On Oct 28, 2008, at 10:19 PM, Andrew Ochsner wrote:

> Looks like ContainerRequestFilter and ContainerResponseFilter might
> be what I'm after.


Yes. Injection will occur on instances of these.


> Any examples or snippets as to how to use these?
>

See here:

http://markmail.org/message/yo45a6whqfbxzue4?q=list:net.java.dev.jersey.users+ContainerRequestFilter

You can look at the source for:

com.sun.jersey.api.container.filter.PostReplaceFilter
com.sun.jersey.api.container.filter.GZIPContentEncodingFilter
com.sun.jersey.api.container.filter.LoggingFilter

Paul.

> Thanks again
> Andy O
>
> On Tue, Oct 28, 2008 at 3:12 PM, Andrew Ochsner <aochsner_at_cs.stanford.edu
> > wrote:
> Hi:
>
> I need to grab some information out of the Http Headers before every
> call to a resource. I take it the best way to do this is to use a
> Servlet Filter?
>
> Is there any other way to do this in Jersey? What if I wanted to
> some JSR311 @Context information in this thing? Are there any hooks
> in Jersey to configure a handler to execute before (and maybe after)
> every call to a resource and have Jersey inject it's JSR311 specific
> annotated stuff?
>
> I guess I'm kinda thinking similar to SOAP handlers/interceptors,
> but I know its a bit different in a REST world.
>
> So, only option currently to use a Filter? Or am I missing something?
>
> Thanks
> Andy O
>