users@jersey.java.net

[Jersey] Re: Configure ResourceFilters in Spring?

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Wed, 12 Jan 2011 11:16:28 +0100

On Jan 11, 2011, at 8:01 PM, Ryan Stewart wrote:

> What are the different ways that a ResourceFilter can be registered?
> Can I set one up in a Spring context? I have a
> ContainerRequestFilter which is a Spring bean and is currently
> applied to my resource classes using the @ResourceFilters
> annotation. I'd like to break that coupling in the resource class,
> and configuring the filters in the web.xml isn't a viable solution.
> I've seen some discussion that seemed to imply that a
> ResourceFilterFactory might be detected and used if wired up as a
> Spring bean, but this doesn't seem to work, either.

If you are using @ResourceFilters and one or more classes referenced
by that annotation are bound by Spring then it should work (Jersey
should defer to Spring to get a reference to those classes).

Note that @ResourceFilters refers to ResourceFilter subclasses that
are responsible for returning ContainerRequestFilter and
ContainerResponseFilter. So it is up to a ResourceFilter subclass to
return references to Container*Filter.

You can also use your own ResourceFilterFactory that is bound by
Spring if you don't want to use @ResourceFilters. In this case it is
up to your ResourceFilterFactory to return references to
ResourceFilter that in turn return reterences to Container*Filter.

Hth,
Paul.