Setting server preferred media type

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting server preferred media type

Tim Williams
I'm wondering how to indicate the server preferred
representation/Media Type when the client's */* preference hits?
Suppose, I have something like:

@GET
@Produces("application/xml")
public Object getAsXml()...

@GET
@Produces("text/plain")
public Object getAsText()...

@GET
@Produces("text/html")
public Object getAsHtml()...

If a client sends Accept: */* (e.g. curl http://example.com --header
"Accept: */*"), Jersey chooses the application/xml representation.
How do I indicate that the server default should be text/html?  It
seems to prefer application/xml in all cases I could find.

Thanks,
--tim

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Setting server preferred media type

Paul Sandoz
Administrator
Hi Tim,

Jersey supports what is termed "quality of source" with the "qs" media  
type parameter, for example:

@GET
@Produces("application/xml;qs=2")
public Object getAsXml()...

@GET
@Produces("text/plain")
public Object getAsText()...

@GET
@Produces("text/html;qs=3")
public Object getAsHtml()...


This means that ""text/html" will take precedence over "application/
xml" which takes precedence over "text/plain".

Further more if the accept header is say:

  "application/xml, text/html;q=0.8"

or

  "application/xml, text/*;q=0.8"

the "text/html" will still take precedence.

Hth,
Paul.


On Jun 15, 2010, at 8:45 PM, Tim Williams wrote:

> I'm wondering how to indicate the server preferred
> representation/Media Type when the client's */* preference hits?
> Suppose, I have something like:
>
> @GET
> @Produces("application/xml")
> public Object getAsXml()...
>
> @GET
> @Produces("text/plain")
> public Object getAsText()...
>
> @GET
> @Produces("text/html")
> public Object getAsHtml()...
>
> If a client sends Accept: */* (e.g. curl http://example.com --header
> "Accept: */*"), Jersey chooses the application/xml representation.
> How do I indicate that the server default should be text/html?  It
> seems to prefer application/xml in all cases I could find.
>
> Thanks,
> --tim
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Setting server preferred media type

Tim Williams
In reply to this post by Tim Williams
Thanks Paul, that's great.  Google isn't helping me find documentation
for this feature, if you could point me somewhere useful, I'm happy to
RTM btw:)

I notice that the qs value gets sent to the client along with the MIME
type, is there a way to turn that off?  Or, is a 'qs' attribute
allowed for all MIME types?

Thanks,
--tim


> Hi Tim,
>
> Jersey supports what is termed "quality of source" with the "qs" media
> type parameter, for example:
>
> @GET
> @Produces("application/xml;qs=2")
> public Object getAsXml()...
>
> @GET
> @Produces("text/plain")
> public Object getAsText()...
>
> @GET
> @Produces("text/html;qs=3")
> public Object getAsHtml()...
>
>
> This means that ""text/html" will take precedence over "application/
> xml" which takes precedence over "text/plain".
>
> Further more if the accept header is say:
>
>  "application/xml, text/html;q=0.8"
>
> or
>
>  "application/xml, text/*;q=0.8"
>
> the "text/html" will still take precedence.
>
> Hth,
> Paul.
>
>
> On Tue, Jun 15, 2010 at 2:45 PM, Tim Williams <[hidden email]> wrote:
>> I'm wondering how to indicate the server preferred
>> representation/Media Type when the client's */* preference hits?
>> Suppose, I have something like:
>>
>> @GET
>> @Produces("application/xml")
>> public Object getAsXml()...
>>
>> @GET
>> @Produces("text/plain")
>> public Object getAsText()...
>>
>> @GET
>> @Produces("text/html")
>> public Object getAsHtml()...
>>
>> If a client sends Accept: */* (e.g. curl http://example.com --header
>> "Accept: */*"), Jersey chooses the application/xml representation.
>> How do I indicate that the server default should be text/html?  It
>> seems to prefer application/xml in all cases I could find.
>>
>> Thanks,
>> --tim
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Setting server preferred media type

Paul Sandoz
Administrator
On Jun 16, 2010, at 6:27 PM, Tim Williams wrote:
> Thanks Paul, that's great.  Google isn't helping me find documentation
> for this feature, if you could point me somewhere useful, I'm happy to
> RTM btw:)

It is rather obscurely documented here:

   https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/view/ImplicitProduces.html

but what it requires is a section in the user guide, so i need to get  
off my lazy backside and write it!


>
> I notice that the qs value gets sent to the client along with the MIME
> type, is there a way to turn that off?

Not currently.


> Or, is a 'qs' attribute
> allowed for all MIME types?
>

I suspect any parameter can be allowed with clients ignoring stuff  
they do not understand. For example you can add the parameter  
"foo=bar" to a produceable media type.

Paul.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]