users@jersey.java.net

Re: [Jersey] Shouldn't having a Produces annotation automatically set the Content-Type of the response?

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Tue, 07 Apr 2009 09:12:30 -0400

On Apr 6, 2009, at 9:25 PM, Rohan Sahgal wrote:
>
> I later changed the code to set the content type of the response by
> doing
> r = Response.ok(getImageRep(), "text/plain").header("Content-Type",
> "image/jpg").build();
>
> This works and the browser can successfully display the image.
>
Note that in the above the "text/plain" argument is the Content-Type
and you are then overwriting it using the header method, a shorter
version would be:

r = Response.ok(getImageRep(), "image/jpg").build();

Marc.

> I was just wondering whether its possible for the response
> content-type to be automatically filled by Jersey (depending on the
> value of @Produces annotation)
> If not, can I directly annotate my method somehow to put the
> Content-Type header, I dont want to have wrapper methods like outlined
> in this sample.
>
> Thanks,
> Rohan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>