PDA

View Full Version : DispatcherFilter - DispatcherServelt like class for filters?


mariuss
Jun 12th, 2007, 08:09 PM
I was wondering if there is any dispatcher class for filters, something along the lines of DispatcherServlet?

The idea is to be able to configure a DispatcherFilter which will load an xml bean file based on its name and instantiate filters from there. For example:
<filter>
<filter-name>Master</filter-name>
<filter-class>org.springframework.web.servlet.DispatcherFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>Master</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

And the corresponding xml file would be Master-filter.xml

These *-filter.xml files will have to define mappings and controllers similar to *-servlet.xml files. In this case controllers will have to implement javax.servlet.FilterConfig (or some Spring provided base class).

This would allow very flexible configuration of filters.

I know that you can use HandlerInterceptors with DispatcherServlet to achieve similar results, but that assumes that you are going with the Spring MVC all the way. Also, you may want to use third party filters and just need a nice way to configure them (with values from .properties files for example).

What do you think?

Marius

Marten Deinum
Jun 13th, 2007, 01:56 AM
Have a look at the DelegatingFilterProxy (http://www.springframework.org/docs/api/org/springframework/web/filter/DelegatingFilterProxy.html). It allows you to configure your filters just as Spring beans.

And/Or you might want to check-out the way Acegi does it with the FilterToBeanProxy (http://www.acegisecurity.org/multiproject/acegi-security/apidocs/org/acegisecurity/util/FilterToBeanProxy.html)

mariuss
Jun 13th, 2007, 03:35 PM
Thanks a lot. Yes, that looks somewhat like what I described. No *-filter.xml files, but good enough.

As a side note, the documentation does not mention this filter proxy at all. Should I add a feature request for the documentation?

Marius

Marten Deinum
Jun 13th, 2007, 04:54 PM
Hmm I read about it somewhere. Could be a blog post. If you feel it is missing from the documentation please feel free to open a jira ticket.