users@jersey.java.net

Re: [Jersey] How to return two response

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 31 Aug 2009 11:23:06 +0200

On Aug 28, 2009, at 6:10 PM, karim Daher wrote:

> Hi all
> I am working in project where I have to return for the same request
> two responses , and I don't know how jersey could handle this?

Have you considered using MIME multipart and multipart/mixed?

See:

   https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/contribs/jersey-multipart/index.html
   https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/contribs/jersey-multipart/com/sun/jersey/multipart/MultiPart.html


> In fact, when I receive a request to download a document, I have to
> load the document and return it in as application/octet-stream, and
> after this I have to return to the UI a jsonObject or string to tell
> it if the download was sent successfully or if any error occurred
> during the operation.
>

OK, multipart/mixed may work for you. The first part can container the
JSON document, and the second part can contain the document.

You can use the standard HTTP status codes for error and if there is
an error you should not return multipart/mixed, and can return
something else as the response entity.


An alternative to using multipart/mixed (i am not sure if it is easy
for browsers to consume such representations) is for the client to
make two requests, the first is the JSON document, that contains a URL
for the document to download, and the second is to download the
document from the URL in the first request.

Paul.

> Do anyone have any idea how can I implement this?
>


> Thank you
>
> Créez un personnage à votre image pour votre WL Messenger Venez voir