On Aug 28, 2009, at 2:37 PM, Alan McKernan wrote:
> Hi everyone,
>
> I have a number of ServletFilters, and one ResourceFilterFactory.
>
> I need the ServletFilters to execute before the
> ResourceFilterFactory as the ServletFilters setup some context
> required by the ResourceFilterFactory.
>
> Anyone know how I can achieve this?
>
What is a "ServletFilter" ? do you mean a servlet filter declared in
the web.xml?
> Otherwise I can move some of my ServletFilter logic into a
> ResourceFilter, but there I cant seem to access the servlet request
> via @Context, it always comes out null. Any solution for this maybe?
>
You need to inject onto ResourceFilterFactory and pass those injected
values to the ResourceFilter instances your factory is responsible for
creating when the create method is called.
For example:
public class MyRFF implements ResourceFilterFactory {
private final HttpServletRequest hsr;
public ResourceFilterFactory(@Context HttpServletRequest hsr) {
this.hsr = hsr;
}
public List<ResourceFilter> create(AbstractMethod am) {
// no need to pass reference if MyRF is an non-static inner class
ResourceFilter rf = new MyRF(hsr);
return Collections.singletonList(rf);
}
}
Paul.