users@jsr311.java.net

Re: Sorting accept media types

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Thu, 26 Feb 2009 16:41:57 -0500

On Feb 26, 2009, at 3:55 PM, Sergey Beryozkin wrote:
>
> So HTTP spec says that specificity is the primary factor, right?
> Same as
> JAXRS spec which says that a quality factor is a secondary key. If we
> have
>
> Accept : text/plain,text/xml;q=0.9, application/*
>
> application/* is less specific than text/xml even though it has a
> higher
> quality factor.
>
> Another very similar example.
>
> Accept : application/xml;q=0.9, application/*
>
> If we have two methods that can produce xml and json then
> it does look like it's application/xml that needs to be returned, even
> though application/* has a higher quality factor ?
>
> If not then what does it mean to have a specificity as a primary key ?
>
The algorithm in section 3.8 tries to find the most acceptable
concrete media type when one isn't specified either explicitly (in a
Request) or implicitly (the method only @Produces one type). In step 7
it sorts with specificity as the primary key and q-value as secondary
since there no point in picking a wildcard media range over a concrete
type when the purpose of the algorithm is to pick a concrete type.

Its really a question of combinations of acceptable and producible
types. If you have

Accept: application/xml;q=0.9, text/*

and the chosen method was annotated:

@Produces(["application/xml", "text/plain"])

Then after step 5 the set of types M would be:

{"application/xml;q=0.9", "text/plain"}

You'd then sort the list as described above and pick "text/plain".

Note that the method chosen to service the request in section 3.7.2
can have a great impact on the media type returned. The algorithm in
3.8 plays no part in selecting the method.

Marc.

>
> -----Original Message-----
> From: Stephan.Koops_at_web.de [mailto:Stephan.Koops_at_web.de]
> Sent: 26 February 2009 18:33
> To: users_at_jsr311.dev.java.net
> Subject: Re: Sorting accept media types
>
> Hi Sergey,
>
> returning text/xml is not wrong, because it will not be in conflict
> with
>
> "*/*". If the client sends
> Accept : text/plain,text/xml;q=0.9, applicatio/*
> then returning text/xml is wrong
>
> best regards
> Stephan
>
> Sergey Beryozkin schrieb:
>> Hi
>>
>> If we have
>>
>> Accept : text/plain,text/xml;q=0.9, */*
>>
>> and two methods with one producing text/xml and another
>> one application/pdf then what format has to be returned ?
>>
>> text/xml is more specific than */* but */* has a quality factor 1.0.
>> JAXRS specification says a quality factor is a primary key, but in
>> this case it does seem correct to return text/xml, is it correct ?
>>
>> Another question :
>>
>> Accept : application/pdf;q=0.9, text/*
>>
>> text/* is more specific than */* but it's still less specifc than
>> application/pdf. Its quality factor is 1.0 though. So is it text/xml
>> format (given the example with 2 methods above) that has to be
> returned ?
>>
>> 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
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: users-help_at_jsr311.dev.java.net
>