users@jsr311.java.net

Re: When to sort Accept header values

From: Sergey Beryozkin <sberyoz_at_progress.com>
Date: Thu, 29 Jan 2009 09:46:17 -0000

Hi Reto

So if we do sort Accept values for the purpose of selecting a method then if we have

Accept: application/xml, application/json

then given a Test class below, a method which can serve application/json will never get invoked as application/xml will be selected
first (if we sort in a descending order for ex), assumimg both methods consume the same content type value.

Cheers, Sergey


> Hi Sergey
>
> Looking at section 14.1 of RFC 2616 the order of the entries in the
> Accept header field isn't an indication of their precedence, only the
> q-value and how specific a media-type is has an effect to their
> priority, so you can sort them right away. How equally specific
> media-types with the same q-value are handled is undefined.
>
> Cheers,
> reto
>
> Sergey Beryozkin said the following on 01/28/2009 08:23 PM:
>>
>> Hi
>>
>>
>>
>> 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
>>
>>
>>
>> 2.Accept: application/xml, application/json
>>
>>
>>
>> getBook1() is selected ?
>>
>>
>>
>> 3.Accept: application/json, application/xml
>>
>>
>>
>> getBook2() is selected ?
>>
>>
>>
>> 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 ?
>>
>>
>>
>> Thanks, Sergey
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: users-help_at_jsr311.dev.java.net
>