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 10:28:23 +0200

Hi,

Perhaps there are other ways we can improve this as well.

e.g. @Produces on a template processor?

Open to suggestions!

Paul.

On Apr 2, 2009, at 9:51 AM, Paul Sandoz wrote:

> Hi,
>
> Are you using @ImplicitProduces ? and implicit views?
>
> IIRC the accept header sent by Safari (or Chrome?) is such that text/
> xml is the most acceptable.
>
> 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.
>
> Paul.
>
> On Apr 2, 2009, at 7:54 AM, Dusan Hornik wrote:
>
>> Hello
>>
>> I am trying to use Jersey and velocity template processor to render
>> the vm pages.
>> My problem is that the content-type I am getting in response is
>> text/xml for Webkit browsers (Safari, Chrome).
>>
>> To reproduce this I created DummTemplateProcessor class in
>> bookstore 1.0.3-SNAPSHOT
>> ---
>> @Provider
>> public class DummyTemplateProcessor implements TemplateProcessor
>> {
>> public String resolve(final String name)
>> {
>> return name;
>> }
>> public void writeTo(final String fullyQualifedName, final Object
>> model, final OutputStream out) throws IOException
>> {
>> final DataOutputStream dataOutputStream = new
>> DataOutputStream(out);
>> dataOutputStream.writeBytes("<html><body>"+fullyQualifedName +
>> " <br></body></html>");
>> }
>> }
>> ---
>>
>> Accessing http://localhost:8080/bookstore/anystring from webkit
>> browser will return "<html><body>anystring <br></body></html>" with
>> content type text/xml.
>>
>>
>> James Strachan wrote:
>>> 2009/2/5 Paul Sandoz <Paul.Sandoz_at_sun.com>:
>>>
>>>> On Feb 4, 2009, at 6:45 PM, James Strachan wrote:
>>>>
>>>>> Its much less essential, but supporting the nicer new MIME
>>>>> strings on
>>>>> @Produces would be great too - so you can use a single constant in
>>>>> your code to refer to a set of MIME types (e.g. application/xml,
>>>>> text/xml and application/json for example) to avoid having to
>>>>> cut and
>>>>> paste a String[] expression in each method using the @Produces
>>>>> annotation.
>>>>>
>>>>> I've raised an issue for this so we don't forget - but its more
>>>>> a case
>>>>> of making things more consistent and DRY, so way less important
>>>>> than
>>>>> support in @ImplicitProduces :)
>>>>> https://jersey.dev.java.net/issues/show_bug.cgi?id=202
>>>>>
>>>>>
>>>> Thanks, for now i am not implementing proposed JAX-RS 1.1
>>>> features because
>>>> they have yet to be approved. Once approved i will start
>>>> implementing such
>>>> features in earnest!
>>>>
>>>
>>> Cool no worries! Just wanted to pop a test case in the issue tracker
>>> before I forgot.
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>