URI-based conneg support

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Fri, 16 May 2008 17:01:33 -0400

While building our demo for JavaOne we ran into some usability issues
with the current support for URI-based conneg. Currently the URIs
returned by UriInfo are the actual request URIs rather than those used
in matching after URI preprocessing (see section 3.7.1 of the spec).

GET /foo/bar.html with an ApplicationConfig that maps "html" => "text/

UriInfo.getRequestURIBuilder().path("baz").build() => "/foo/bar.html/

This isn't generally what you want. You can do:

UriInfo.getPlatonicRequestUriBuilder().path("baz").build() => "/foo/

which is better, but you have to remeber to use the platonic builder
and often what you really want to get is "/foo/bar/baz.html", so then
you have to do


We think it would be better if you could just write:

UriInfo.getRequestURIBuilder().path("baz").build() => "/foo/bar/

To do this we propose the following changes:

(i) change the way that UriInfo works such that the URIs returned are
(ii) remove the "platonic" URIs from UriInfo as all methods are now
(iii) change the getPathExtension method so that it returns the
extension extracted by section.3.7.1 processing - we'd also rename it
in the process.
(iv) change the semantics of UriBuilder.extension so that it specifies
an extension that will be appended to the final path segment during
(v) add a new UriBuilder method to get the current value of (iv)
(vi) Specify that the UriInfo methods that return a UriBuilder set the
extension property (iv) based on the current value of (iii).

With these changes the URIs you get from UriInfo correspond to those
used in matching requests to resources (as is already the case for the
rewritten Accept and Accept-Language headers). Builders you get from
URI info are preconfigured to use the same URI-based conneg that the
request used so its easy to build representations with links to
representations using the same media type and language. Its also easy
to build platonic URIs just by unsetting the value of (iv) after you
obtain the builder from UriInfo.

Thoughts, comments ?

Marc Hadley <marc.hadley at>
CTO Office, Sun Microsystems.