October 2nd, 2013 by lastcow

Help! RewriteFilter won’t start – Why? Look to web.xml DOCTYPE for answers.

I was developing JSF 2.2.1 web application using [[Rewrite]] for URL cleanup and navigation. It was simple to get started building an application using Rewrite on JBoss WildFly Beta 4 server. I installed the dependencies, starting using the appropriate configuration and components. All I wanted to do was map a few simple pages, and create links to them in the html – Rewrite was perfect for this.

Everything was working fine in the application except page mappings didn’t seem to work (I had to access pages via their direct URL,) and the <pretty:link> always rendered a link to the homepage.

I stopped by the #ocpsoft channel on IRC, and Lincoln helped me solved this ‘strange’ issue (and invited me to write a quick post about it.) Now of course you must be wondering what was wrong – It was because the doctype declaration of my web.xml was both invalid, and also specifying an out-of-date servlet version.

This is the original web.xml DOCTYPE declaration generated by Intellij IDEA:

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

As it turns out, this caused Wildfly to use an older version of Servlet support, which meant that I needed to either register Rewrite in the application manually, by adding the RewriteFilter configuration to my web.xml file, or simply update the web.xml file to use the more recent (and correct) document type (which is by far the simpler solution!)

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" 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_3_0.xsd"
   metadata-complete="false">

Now everything works fine, the old declaration deactivated servlet 3.0, which actually prevented Rewrite to start up (Rewrite bundles a web-fragment.xml file which requires Servlet 3.0 in order to support automatic activation.)

Thanks again to Lincoln, saved my life. 😉

~Lastcow (zhijiang)