I'm using Tomcat, but i'd like to go for a generic way (servlet 3.0)
I have some configured filters in the web.xml and one of these is the GuiceFilter. GuiceFilter is a a little bully...once it get executed it will swallow the request and never call proceeding filters. This way i cant get executed any filter after the Guice one. I could define all filters in guice insetead of web.xml, but this will not work for some filters: "Tomcat WebSocket (JSR356) Filter" This is a filter Tomcat will register after all other to handle WebSockets...it should be the first one, not the last one, but i just need it gets executed before GuiceFilter or inside it.
I've found a way to get all registered filters and add them to guice:
for (Entry<String, ? extends FilterRegistration> entry : context.getFilterRegistrations().entrySet()) {
FilterRegistration filterRegistration = entry.getValue();
System.out.println(entry.getKey() + " = " + filterRegistration);
Class<? extends Filter> clazz = (Class<? extends Filter>) Class.forName(filterRegistration.getClassName());
if (GuiceFilter.class.isAssignableFrom(clazz)) {
continue;
}
bind(clazz).in(Singleton.class);
filter(filterRegistration.getUrlPatternMappings()).through(clazz, filterRegistration.getInitParameters());
}
but this way i'll get some filters (the one before Guice one) executed twice (the normal filter chain and the guice one)
Is there a way to get the filters order? (so i can add only the ones after guice)
Or, another way: is there a way to remove the filter from the normal chain leaving only the guice one (moving all other filters to guice itself)?