users@jersey.java.net

Re: [Jersey] prioritising HTML representations in web applications when using implicit or explicit views

From: James Strachan <james.strachan_at_gmail.com>
Date: Wed, 28 Jan 2009 12:30:34 +0000

2009/1/28 Paul Sandoz <Paul.Sandoz_at_sun.com>:
>
> On Jan 28, 2009, at 11:22 AM, James Strachan wrote:
>
>> 2009/1/28 Paul Sandoz <Paul.Sandoz_at_sun.com>:
>>>
>>> On Jan 28, 2009, at 10:38 AM, James Strachan wrote:
>>>
>>>> 2009/1/28 Paul Sandoz <Paul.Sandoz_at_sun.com>:
>>>>>
>>>>> On Jan 28, 2009, at 12:47 AM, James Strachan wrote:
>>>>>
>>>>>> 2009/1/27 James Strachan <james.strachan_at_gmail.com>:
>>>>>>>
>>>>>>> Awesome stuff Paul, many thanks! Taking it for a spin now...
>>>>>>
>>>>>> It works like a charm! Great stuff Paul!
>>>>>>
>>>>>
>>>>> Great. I am still not sure about the prioritization aspect of media
>>>>> types
>>>>> declared with @ImplicitProduces, it seems a hack that might be hard to
>>>>> remove when priorities are supported, or not be of the desirable
>>>>> behavior
>>>>> for some. It would be more consistent if @ImplicitProduces has the same
>>>>> order semantics as @Produces.
>>>>
>>>> Yeah.
>>>>
>>>> I wonder if we could just add support for priorities in the MIME types
>>>> for now?
>>>
>>> For @Produces that will require more work :-) I do not have time to
>>> investigate and implement in time for the 1.0.2 release with all the
>>> other
>>> things that need to be done.
>>
>> OK :)
>>
>> Would you have time to just support the priorities/quality for
>> @ImplicitProduces for 1.02?
>
> I am not sure that will work without priorities also being set on media
> types in the @Produces since it may be necessary to reduce the priority of
> the other media types. Or i suppose increase the priority in the implicit
> produces to something > 1. If we assume we cannot change the priorities in
> the @Produces then for the Safari header the text/html would require a
> priority > 1.0 / 0.8.
>
> There are some edge cases where priorities will not work (if we assume the
> Apache conneg algorithm of multiplication of priority with quality)
> depending on the priority values. Say for example, because the moon is
> rising in Jupiter, that we have a priority of 1.0 for text/html and a
> priority of 0.5 for application/xml, and the Safari accept header for a
> later version is changed from:
>
> text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
>
> to:
>
> text/xml,application/xml,application/xhtml+xml,text/html;q=0.4,text/plain;q=0.3,image/png,*/*;q=0.2
>
> For the first accept header the order and relative quality would be:
>
> text/xml, # q = 1
> application/xhtml+xml, # q = 1
> image/png, # q = 1
> text/html;q=0.9, # q = 0.9
> text/plain;q=0.8, # q = 0.8
> application/xml, # q = 0.5
> */*;q=0.5 # q = 0.5
>
> For the second accept header the order and relative quality would be:
>
> text/xml, # q = 1
> application/xhtml+xml, # q = 1
> image/png, # q = 1
> application/xml, # q = 0.5
> text/html;q=0.2, # q = 0.4
> text/plain;q=0.8, # q = 0.3
> */*;q=0.5 # q = 0.2
>
>
> All this means developers should pick priorities with care and perhaps there
> needs to be a default that works with accept headers of the common browsers?

Totally agreed. I spent a little while googling; I was hoping to find
some handy website showing headers for common browsers somewhere but
'http' and 'accept' and 'header' seem kinda common words :). So far
Safari & iphone do seem strange, but am sure if we looked at all the
versions of IE, Opera & phones there will be other oddities.

I guess we'd want to set the quality to something massive on text/html
(like 10 or even 100 :-) to avoid the issue you mention of a browser
lowering text/html too low.

Incidentally - I can imagine doing a mixture of implicit views and
explicit views (for example processing form submissions and
re-rendering the form edit page if there are validation errors or
redirecting to the success page if the post worked). So having a way
to set the global quality of mime types is going to be very handy; I'm
now liking specifying it globally even better than specifying it on
specific MIME types - particularly now that I've now had more coffee
:)


>> Am thinking that's slightly preferable as
>> its a clean longer term solution.
>
> I will look into it as if we support priorities application wide or specific
> to @ImplicitProduces the same code needs to be used.

Cool. I'm just happy and grateful the code is there :)

-- 
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://fusesource.com/