users@jersey.java.net

Shouldn't having a Produces annotation automatically set the Content-Type of the response?

From: Rohan Sahgal <rohansahgal_at_gmail.com>
Date: Mon, 6 Apr 2009 18:25:47 -0700

Hi,
I have been using jersey1.0.1.

I came across a situation where I wanted to return a dynamic image and
an audio file in response to a url.

I followed the approach as shown in the Simple Servlet sample.

However I noticed that if i goto the image url outlined in the sample,
the browser(firefox) tries to read it as an application/octstream type
of file. Since it does not know what to do, it gives the option to
save.

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.

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