users@jersey.java.net

[Jersey] Re: How to set two values of the same type in Response

From: Jason Erickson <jason_at_jasonerickson.com>
Date: Tue, 5 Jul 2011 17:27:46 -0700

I'm not clear on what you want to do. You can only send one response, so if you want to send two values in one response, you have to either:
Format the contents of the response in a way that can be parsed on the client to extract the multiple values. XML and JSON are common choices here.
Put one value in the content of the response and others in headers. Unless you have a value that fits a specific Header, I would avoid this option. But your case might be one of the specific use-cases with a well-known header field.

In your case, given the specific values you want, you might want to put the contents of the file into the content of the response and add Content-Disposition header to set the filename. (You should have a @Produces annotation on the service to indicate the MIME type of the response as well.)

On Jul 5, 2011, at 4:55 PM, Jitesh Sinha -X (jisinha - Siliconweb Inc. at Cisco) wrote:

> To isolate the problem,I tried setting only one value in response on server side.
>
> So server side code is like this –
> String fileName = "TranslatedContent_" + requestID + "." +format;
> Response.ok(fileName).build();
>
> On client side I do –
>
> String fileName = response.getEntity(String.class) ;
>
> Where response is an instance of ClientResponse .
>
>
> On client side I get filename as blank(empty string).
> What can be the issue ?I have removed all references of ServletOutputStream.
>
> Can someone please help?
>
> Thanks
> -Jitesh
>
>
> From: Jitesh Sinha -X (jisinha - Siliconweb Inc. at Cisco)
> Sent: Tuesday, July 05, 2011 10:59 AM
> To: users_at_jersey.java.net
> Subject: [Jersey] How to set two values of the same type in Response
>
> Hi All,
>
> I need to set two values of String type in response on server side. One is filename and the other one is file contents. Do I set them one by one and then retrieve them on client side one by one?
> Also,do I need to get rid of ServleOutputStream on server side altogether?
>
> I am doing something like this on server side –
>
> ServletOutputStream sos = response.getOutputStream() ;
> sos.println(“my stuff”) ;
>
> Because of the above code,I can retrieve only those values that are written to Servlet Output Stream.Whatever I write in Response object is not retrievable.
>
>
> Thanks
> -Jitesh