users@jersey.java.net

Resource-specific filters

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 22 Jan 2009 18:52:25 +0100

Hi,

I have completed support for resource specific filters. See the
JavaDoc of:

   com.sun.jersey.api.container.filter

   http://download.java.net/maven/2/com/sun/jersey/jersey-server/1.0.2-SNAPSHOT/jersey-server-1.0.2-SNAPSHOT-javadoc.jar


You can use annotations, for example:

   @ResourceFilters(MyResourceFilter.class)
   public class MyResource {

       @GET String get() { ... }

       @Path("sub") Object getSubResource() { ... }
   }

which is equivalent to:

   public class MyResource {

       @ResourceFilters(MyResourceFilter.class)
       @GET String get() { ... }

       @ResourceFilters(MyResourceFilter.class)
       @Path("sub") Object getSubResource() { ... }
   }

the annotation on the classes is inherited on the methods.

The class MyResourceFilter implements
com.sun.jersey.spi.container.ResourceFilter.

The support for the ResourceFilters annotation is implemented as a
com.sun.jersey.spi.container.ResourceFilterFactory. So is support for
@RolesAllowed (which i have not tested yet).

ResourceFilterFactory classes or instances can be registered with the
ResourceConfig.

You can add support for your own annotations that declare filter
behavior and an implementation of a ResourceFilterFactory look for
those annotations.

Paul.