Content Negotiation Filter

Created: 2012/12/03 21:35:26+0000 Revised: 2013/02/08 23:48:10+0000 Revisions:  11 10 9 8 7 6 5 4 3 2 1

As part of the (limited) linked data I provide on this website I implemented a content negotiation filter to provide the 303 redirects. It is configured with an XML file that describes the possible variants. The content negotiation algorithm is based on the Apache Negotiation Algorithm but lacks support for the encoding and character set.

I implemented this myself because when I was trying to find out how I should do this I kept finding Paul Tuckey's UrlRewriteFilter and JAX-RS which uses annotations. The UrlRewriteFilter only supports string matching on the accept header and 302 redirects. JAX-RS and annotations had nothing to do with how I was implementing my website.

I used Maven as the build tool for this. Some of you may have heard me say that I prefer Ant and this is true. One of the problems I have with Maven is that the lifecycles make it unsuitable for persistent data stores, this does not apply here. What I like about Maven is the dependency management, which I usually take advantage of using Ivy. Ivy does support publishing to a repository but I felt that it would be more straight forward to use Maven and there wasn't anything I wanted to do that Maven would make difficult.

It is currently available from source control at BitBucket, It has also been released to the Maven central repository.

Group IDcom.mattunderscore
Artifact IDcontent-negotiation
Dependenciesjavax.servlet.servlet-api, junit.junit, org.hamcrest, com.mattunderscore.filter-utils, com.mattunderscore.http-structured-headers
Show all

It is now in three artifacts, I have successfully converted it to a multi-module project. The Maven generated site is available at I am sure you will all be very glad to learn that this release does contain automated testing and test coverage reports. What next? Improved test coverage? Continuous integration? Enough documentation for you to use it?

For those of you interested in linked data for this project, see here: