users@jersey.java.net

Re: Jersey setting the appropriate Content Type in the Response

From: emiddio-frontier <emiddio_at_frontier.com>
Date: Tue, 9 Nov 2010 18:59:45 -0800

i'm new to this - but i thougt the @Produces was for determining the method
to invoke,
as determined by Accepts header in the incoming msg -- not for setting the
outgoing
response Content-Type;

The documentation i have says it always returns the 1st @Produces if both
are
equally acceptable to the client.

gary

----- Original Message -----
From: "tuco" <rahul.babbar1_at_gmail.com>
To: <users_at_jersey.dev.java.net>
Sent: Tuesday, November 09, 2010 10:01 AM
Subject: Jersey setting the appropriate Content Type in the Response


>
> Hi,
>
> Here is my situation.
>
> 1) The generation of appropriate format (XML/JSON etc) is custom and not
> JAXB based so that i have my own convertor to convert objects to these
> format.
> 2) So, according to the above case, i need to return String in all the GET
> methods in my Servlet for handling the requests.
> 3) However i need to set the appropriate Content Type in the response so
> that the browser can interpret it.
> 4) My GET methods are annotated with @Produces({MediaType.TEXT_XML,
> MediaType.APPLICATION_JSON}) so that these are the applicable types which
> can be returned.
> 5) Before returning the String in the method, i am setting the appropriate
> Content Type in the response(I am injecting HttpServletResponse in my REST
> service class ).
>
> However, in all the cases, Jersey returns the String with content Type set
> in response as MediaType.TEXT_XML.
> If i annotate the method with @Produces({MediaType.APPLICATION_JSON,
> MediaType.TEXT_XML}), it sets the content type as
> MediaType.APPLICATION_JSON, so its setting the first media type.
>
> Can someone help me out of here?
> --
> View this message in context:
> http://jersey.576304.n2.nabble.com/Jersey-setting-the-appropriate-Content-Type-in-the-Response-tp5721896p5721896.html
> Sent from the Jersey mailing list archive at Nabble.com.