users@jsr311.java.net

Re: When to sort Accept header values

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 28 Jan 2009 15:09:56 -0500

On Jan 28, 2009, at 2:23 PM, Sergey Beryozkin wrote:
>
> I’d like to clarify when to sort Accept header values.
> Consider this example.
>
> public class TestClass {
>
> @Produces(“application/xml”)
> public Book getBook1() {}
>
> @Produces(“application/json”)
> public Book getBook2() {}
>
> }
>
> 1.Accept: application/xml;q=0.5, application/json;q=0.6
>
> getBook2() is selected
>
Yes.

>
> 2.Accept: application/xml, application/json
>
> getBook1() is selected ?
>
> 3.Accept: application/json, application/xml
>
> getBook2() is selected ?
>
The spec doesn't define which one is chosen, sorting is only specified
for specificity (x/y > x/* > */*) and q value.

> if the above examples are correct then is it the case that Accept
> header values should not be sorted for the purpose of selecting a
> method to be invoked ?
>
> I’ve got a bit confused – when they actually should be sorted ?
> Section 3.7.2/3.b mentions Accept, but say nothing about sorting of
> accept values. Which makes sense,
>
> Do they need to be sorted only when a selected method has multiple
> Produces values, to determine the media type of a given response ?
>
The sorting for selecting a method in 3.7.2 step 3 applies regardless
of whether the @Produce/_at_Consumes is singular or multiple valued. The
sorting to select a type in 3.8 only applies when the chosen method
can produce more than one media type.

Marc.

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