users@jersey.java.net

Re: Re: [Jersey] Content Negociation

From: <amsmota_at_gmail.com>
Date: Wed, 21 Jan 2009 18:37:57 +0000

Many thanks for that. I was about to implement that myself, but I ended
using

HttpHeaderFactory.createAcceptMediaType(...)

with some twists.

I really wanted to put some more Jersey stuff on my application, specially
those nice "injected interfaces" (I don't know if I like the concept,
though) and following your recommendation in [1], but time is against me...
Specifically, I eventually will want to use some of the web/servlet stuff
but in other "connectors" like JMS and IMAP (the ones I implemented
already) and others... Do you think that makes sense?

Cheers.

[1] https://jersey.dev.java.net/servlets/ReadMsg?list=users&msgNo=3286


PS I noticed that I was answering directly to you, so I'm putting this back
in the list. Sorry for that.



On Jan 21, 2009 11:54am, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
>
>
> On Jan 21, 2009, at 12:41 PM, amsmota_at_gmail.com wrote:
>
>
>
>
> Thanks for your quick (as usual) reply... However...
>
>
>
> On Jan 21, 2009 11:20am, Paul Sandoz Paul.Sandoz_at_sun.com> wrote:
>
> >
>
> > On Jan 21, 2009, at 12:10 PM, amsmota_at_gmail.com wrote:
>
> >
>
> > Also, does Jersey considers the quality values when matching mime types?
>
> >
>
> > Yes, quality values of media types in the accept header but not
currently of media types in the @Produces.
>
>
>
> How does Jersey does that? Because I'm using the MediaType implementation
to do that
>
>
>
>
>
>
> It only looks at quality parameters of media types *in the Accept
header*. The list of media types in the accept header is ordered according
to the quality parameter (an absence means a quality of 1.0).
>
>
>
> See the method:
>
>
>
> javax.ws.rs.core.HttpHeaders.getAcceptableMediaTypes()
>
>
https://jsr311.dev.java.net/nonav/javadoc/javax/ws/rs/core/HttpHeaders.html#getAcceptableMediaTypes()
>
>
>
> The JAX-RS spec defines the matching algorithm:
>
>
>
>
https://jsr311.dev.java.net/nonav/releases/1.0/spec/spec3.html#x3-360003.7.2
>
>
>
> See part 3.
>
>
>
>
>
>
> if(anotherType.isCompatible(type))
>
>
>
>
>
>
> Compatibility only looks at the type and subtype and wildcards.
>
>
>
>
>
>
> but nowhere there is the quality present. And it seems it does only a
simple string comparison to match the types.
>
>
>
> So, given this situation
>
>
>
> Accept: application/octet-stream
>
>
>
> @Produces("text/html")
>
> produceHtml()
>
>
>
> @Produces("application/pdf")
>
> producePdf()
>
>
>
> shouldn't the producePdf be matched?
>
>
>
>
>
>
> Not for the browser based Accept header you presented in the previous
email.
>
>
>
> Yes for the curl example.
>
>
>
> Paul.
>