users@jersey.java.net

Problems with URI content negotiations

From: Daniel Larsson <daniel.j.larsson_at_gmail.com>
Date: Thu, 1 Oct 2009 13:12:19 +0200

Hi all,
I've dabbled a bit with URI content negotiation, i.e. setting up extension
mappings to languages like so:

public class ServletContainer extends
com.sun.jersey.spi.container.servlet.ServletContainer {

    @Override
    public void initiate(ResourceConfig rc, WebApplication wa) {
        super.initiate(rc, wa);
        rc.getLanguageMappings().put("en", "en");
        rc.getLanguageMappings().put("sv", "sv");
        rc.getLanguageMappings().put("da", "da");
        rc.getLanguageMappings().put("no", "no");
    }
}

Trouble is this isn't working very well, depending on the name of the
resource I'm trying to retrieve. It looks like the uriconneg code is looking
for the extensions in the part following the last slash, but it doesn't
check for a preceding ".". Or rather, it does the check after looking for
the "extension". This means when I try to access a URI like "
http://localhost/document.en", the code finds "docum*EN*t.en", figures out
the "en" isn't preceded by a ".", and goes on to the next mapping.

The end result is it tries to find a resource named "document.en" rather
than "document" with "Accept-Language: en".

I've attached a small maven project to illustrate the problem. Should I file
an issue?

Daniel Larsson