users@jersey.java.net

Re: [Jersey] _at_ImplicitProduces and priorities <was> Re: [Jersey] prioritising HTML representations in web applications when using implicit or explicit views

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 02 Apr 2009 16:58:33 +0200

On Apr 2, 2009, at 12:18 PM, Dusan Hornik wrote:
>>> You need to use @ImplicitProduces to ensure that text/html or
>>> whatever is required is the most acceptable.
>>>
>>> For example:
>>>
>>> @ImplicitProduces("text/html;qs=5")
>>>
>>> the "qs" value will be multiplied by the 'q' value in the Accept
>>> header and the result will be used to sort media types to find the
>>> most acceptable one with the highest result.
>>>
>>> If you are using explicit views for everything (HTML and XML) then
>>> you will need to utilize a filter to modify the accept header and
>>> change the order of the media types so that the HTML media type is
>>> the most preferred. Which should also work if you do not want to
>>> use the @ImplicitProduces annotation.
> As a workaround I am currently using a filter that modifies Accept
> headers of request and if it contains text/html then it will move it
> to the front. But I would prefer if it works without this workaround
> filter.

I have fixed this in the trunk.

The most acceptable media type, taking into account the "qs"
multiplier will be set as the content type. Thus the template
processor could get access to this value (use @Context HttpContext to
get the HttpResponseContext and the HTTP response headers that have
been set).

Paul.