users@jersey.java.net

Re: [Jersey] Configuring request/response filters with annotations in JEE6

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 27 Jan 2010 09:20:48 +0100

Hi Kevin,

On Jan 26, 2010, at 7:20 AM, Kevin Duffey wrote:

> Hey all,
>
> I am unable to see my list of emails right now, so if this has been
> asked I apologize and please refer me to the thread link.
>
> I am using GF3 with Jersey, loving the heck out of it. I configure
> Jersey with:
>
> @ApplicationPath("")
> public class RestConfigApplication extends Application {
> }
>
> Works great. What I am lacking now tho is how to configure the
> request filters I had for version checks and authentication. As
> well, if this is possible to do with annotations, can response
> filters be handled in the same manner.
>

It is not currently possible with annotations.

You can do the following:

@ApplicationPath("")
public class RestConfigApplication extends DefaultResourceConfig {

   public RestConfigApplication() {
     List<? extends ContainerResponseFilter> l =
Collections.singletonList(MyFilter.class);
      
getProperties
().put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, l);
   }
}

Paul.