users@jersey.java.net

Re: [Jersey] ImplicitProduces annotation

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 28 Jun 2010 05:45:24 -0700

Hi,

@ImplicitProduces is only utilized for defining the media type of
implicit views (e.g. when assigning JSPs as the view templates when no
@GET methods are defined that match the media types in the
@ImplicitProduces). In this case since your response is explicit you
can set the "qs" value on the @Produces of your resource method:

    @GET
    @Produces( { "application/xhtml+xml;qs=3, "text/html;qs=2",
MediaType.APPLICATION_XML })
    public synchronized Response getFoo() {
        return ...
    }


or:

    @GET
    @Produces("application/xhtml+xml;qs=3, text/html;qs=2, application/
xml")
    public synchronized Response getFoo() {
        return ...
    }

and from the above you can use your own string constant.

Paul.

On Jun 28, 2010, at 5:26 AM, Camel Christophe wrote:

> Hello everybody,
>
> I desperately trying to configure Jersey to return a text/hml content
> instead of application/xml with Chrome browser. When performing
> content
> negotiation, Chrome sends the following acceptable media types, in the
> following order :
>
> application/xml,application/xhtml+xml,text/html;q=0.9,text/
> plain;q=0.8,i
> mage/png,*/*;q=0.5
>
> Without any further Jersey customization, returned content is always
> application/xml, and I believe this is expected.
>
> So, to circumvent the problem, I added the ImplicitProduces annotation
> to my resource, like this :
>
> @Path("foo")
> @ImplicitProduces("text/html;qs=5")
> @Component
> @Scope("singleton")
> public final class FooResource {
>
> ...
> @GET
> @Produces( { MediaType.APPLICATION_XHTML_XML, MediaType.TEXT_HTML,
> MediaType.APPLICATION_XML })
> public synchronized Response getFoo() {
> return ...
> }
> ...
>
> }
>
> But this doesn't work. Content returned is always application/xml.
> Is it
> an already known problem ? I'm using Jersey 1.3.
>
> Thanks for any help.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>