Wednesday, December 30, 2009

REST-style URLs for older Java web applications using UrlRewriteFilter

Say you have an old old Java Web application that uses URLs like this:

/queryVehicles.jsp?make=Ford&model=Fusion

You want your URLs to be pretty and more RESTful like so:

/vehicles/ford/fusion

Well, you have two options. You can re-write your web application to use newer web frameworks that supports REST-style URLs such as Spring MVC 3.0, which will probably take months to do. Or you can use UrlRewriteFilter which should take no more than 30 minutes and will work with any existing Java web application.

UrlRewriteFilter very easy to use. You basically:
  1. Add UrlRewriteFilter as a servlet filter in your WEB-INF/web.xml
  2. Populate WEB-INF/urlrewrite.xml with mappings of REST-style URLs to the corresponding URLs of your legacy web application (with query params and what not).
 That's pretty much it.

UrlRewriteFilter is extremely powerful. It supports regular expression pattern matching, allowing you to perform pretty complex mapping. Check out the manual page for details.

No comments:

Post a Comment