UrlRewriteFilter with Wicket
UpdatedSome of you have probably tried using UrlRewriteFilter with a framework that’s installed as a filter and noticed that it doesn’t work properly. The redirects work correctly but the transparent forwarding doesn’t. I’ve been trying to get it to work with Wicket and I finally figured out what’s wrong with my configuration.
I have configured UrlRewriteFilter and Wicket in my web.xml like this:
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>WebApplication</filter-name>
<filter-class>
org.apache.wicket.protocol.http.WicketFilter
</filter-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>net.korri.www.wicket.WicketApplication</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>WebApplication</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
But the problem with this configuration is that when the UrlRewriteFilter forwards an url, the other filters will be skipped. So I need to change my filter mapping configuration for Wicket a little bit:
<filter-mapping>
<filter-name>WebApplication</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Now all requests and forwards will always be filter by the Wicket filter and so the url forwarding will work. One thing to notice is that the dispatcher tag was added in 2.4 servlet specification so you need to be using at least that version. More info about the dispatcher tag is available here.