users@jersey.java.net

Re: [Jersey] Server prioritization of media types

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 04 Jan 2010 10:50:15 +0100

On Dec 18, 2009, at 7:20 PM, Paul Sandoz wrote:

> On Dec 18, 2009, at 4:04 PM, Paul Sandoz wrote:
>>>> OK, are your fine with the proposed syntax?
>>>
>>> Yes, looks good to me!
>>>
>>> I guess its not possible to use a ">" token instead of "," when
>>> passing multiple MIME types as a single String with @Produces? Was
>>> just wondering if ordering could be combined into @Produces such as
>>> @Produces("text/html > text/xml") etc. If its not easily possible
>>> then
>>> for sure the @ProducesOrder sounds good to me
>>>
>>
>> I was wondering that too. Let me think about it.
>>
>
> One possible solution is as follows:
>
> public class X {
> @GET
> @Produces("(application/xml, text/xml) > (application/json)")
> public ... getXml() { ... }
>
> @GET
> @Produces("application/json")
> public ... getJson() { ... }
>
> @GET
> @Produces("(text/html, application/html) > (text/xml, application/
> xml)")
> public Viewable getHtml() { ... }
> }
>
> But i think that is over complicated.
>
> Another solution is to define a relative priority integer value:
>
> public class X {
> @GET
> @Produces("application/xml;p=2, text/xml;p=2")
> public ... getXml() { ... }
>
> @GET
> @Produces("application/json") // p=1
> public ... getJson() { ... }
>
> @GET
> @Produces("text/html;p=3, application/html;p=3")
> public Viewable getHtml() { ... }
> }
>
> @ImplicitProduces("text/html;p=3, application/html;p=3")
> public class X {
> @GET
> @Produces("application/xml;p=2, text/xml;p=2")
> public ... getXml() { ... }
>
> @GET
> @Produces("application/json") // p=1
> public ... getJson() { ... }
> }
>
> And is it easy to support a media list property for an application
> wide setting.
>
> In fact we could probably reuse "qs" in this respect. I doubt that
> it will break backwards compatibility as the intent was to achieve
> the same result.
>

I have fixed this reusing the "qs" parameter so it is now possible to
do:

public class X {
   @GET
   @Produces("application/xml;qs=2, text/xml;qs=2")
   public ... getXml() { ... }

   @GET
   @Produces("application/json") // p=1
   public ... getJson() { ... }

   @GET
   @Produces("text/html;qs=3, application/html;qs=3")
   public Viewable getHtml() { ... }
}

and thus explicit views will work now as is the case for implicit views.

Paul.