Solution to Tuckey’s UrlRewriteFilter 3.2 DTD Validation Failure

What is UrlRewriteFilter?

 

Based on the popular and very useful mod_rewrite for apache, UrlRewriteFilter is a Java Web Filter for any J2EE compliant web application server (such as ResinOrion or Tomcat), which allows you to rewrite URLs before they get to your code. It is a very powerful tool just like Apache’s mod_rewrite.

URL rewriting is very common with Apache Web Server (see mod_rewrite’s rewriting guide) but has not been possible in most java web application servers. The main things it is used for are:

  • URL Tidyness / URL Abstraction – keep URLs tidy irrespective of the underlying technology or framework (JSP, Servlet, Struts etc).
  • Browser Detection – Allows you to rewrite URLs based on request HTTP headers (such as user-agent or charset).
  • Date based rewriting – Allows you to forward or redirect to other URL’s based on the date/time (good for planned outages).
  • Moved content – enable a graceful move of content or even a change in CMS.
  • Tiny/Friendly URL’s (i.e. blah.com/latest can be redirected to blah.com/download/ver1.2.46.2/setup.exe)
  • A Servlet mapping engine (see Method Invocation)

UrlRewriteFilter uses an xml file, called urlrewrite.xml (it goes into the WEB-INF directory), for configuration. Most parameters can be Perl5 style Regular Expressions or Wildcard Expressions. This makes it very powerful indeed.

 

What is the Problem?

 

The configuration file for the 3.2 version of the filter, urlrewrite.xml, fails validation in the Eclipse IDE. Particularly the following line.

<!DOCTYPE urlrewrite PUBLIC “-//tuckey.org//DTD UrlRewrite 3.2//EN”
http://tuckey.org/res/dtds/urlrewrite3.2.dtd”&gt;

This is the default document type declaration (DTD) for the file. Copying the url, http://tuckey.org/res/dtds/urlrewrite3.2.dtd, into your browser, you’ll realize that the url is redirected to the Tuckey home page, http://www.tuckey.org, instead of displaying the DTD.

 

What is the Solution?

 

By adding ‘www’ to the url, the problem seems to be solved. The new url, http://www.tuckey.org/res/dtds/urlrewrite3.2.dtd seems to correctly display the DTD and furthermore, validation is successful in eclipse.

Therefore, if you use version 3.2 of the urlrewrite filter, your new DTD declaration in urlrewrite.xml should be:

<!DOCTYPE urlrewrite PUBLIC “-//tuckey.org//DTD UrlRewrite 3.2//EN”
http://www.tuckey.org/res/dtds/urlrewrite3.2.dtd”&gt;

I hope it works for you.

 

References

 

http://code.google.com/p/urlrewritefilter/
https://groups.google.com/forum/#!topic/urlrewrite/COEdoePM0mU
http://gamerprospersonalblog.blogspot.com/2011/08/solved-urlrewritexml-validation-issue.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s