I’d like the ability to modify/configure filters in a different way than web.xml. Here is a static configuration of 2 filters. I’d like the ability to have one filter statically configured and allow that filter to load additional filters. I just wanted to know if anyone knows of lib that already has this.
Using Servlet API 2.5
<web-app>
...
<filter>
<filter-name>MyFilter1</filter-name>
<filter-class>com.me.MyFilter1</filter-class>
</filter>
<filter-mapping>
<filter-name>MyFilter1</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
...
<filter>
<filter-name>MyFilter2</filter-name>
<filter-class>com.me.MyFilter2</filter-class>
</filter>
<filter-mapping>
<filter-name>MyFilter2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
...
</web-app>
I’ve seen this done in Guice with GuiceFilter where the Filters are configured at runtime.
Just do the same job as the container already does. I.e. reinvent the wheel of the chain of responsibility design pattern as is under the covers been used by servlet filters.
with those little helper classes (which can if necessary be made
private staticnested classes of the aboveGodFilter):and
You could if necessary also feed a XML config file with all possible filters so that you end up with easier configuration. You could use reflection to create filters in
init()of yourGodFilter.Oh nevermind, that’s what the
web.xmland the container already is doing…