How do I apply a servlet filter when serving an HTML page directly?
- by Philippe Beaudoin
First off, I'm using Google AppEngine and Guice, but I suspect my problem is not related to these.
When the user connect to my (GWT) webapp, the URL is a direct html page. For example, in development mode, it is: http://127.0.0.1:8888/Puzzlebazar.html?gwt.codesvr=127.0.0.1:9997. Now, I setup my web.xml in the following way:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>PuzzleBazar</display-name>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Puzzlebazar.html</welcome-file>
</welcome-file-list>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--
This Guice listener hijacks all further filters and servlets. Extra
filters and servlets have to be configured in your
ServletModule#configureServlets() by calling
serve(String).with(Class<? extends HttpServlet>) and
filter(String).through(Class<? extends Filter)
-->
<listener>
<listener-class>com.puzzlebazar.server.guice.MyGuiceServletContextListener
</listener-class>
</listener>
</web-app>
Since I'm using Guice, I have to configure extra filters in my ServletModule, where I do this:
filter("*.html").through( SecurityCookieFilter.class );
But my SecurityCookieFilter.doFilter is never called. I tried things like "*.html*" or <url-pattern>*</url-pattern> but to no avail. Any idea how I should do this?