Jersey async processing of input stream; immediately return accepted

17 Views Asked by At

I am trying to design a jersey rest api that accepts a client input stream for background processing, and returns a 201 created response to the client immediately, along with a task id in the location response header. The client would push all of its data and then note the receipt of the created response, and begin polling the location URI for completion status.

The server may take a while to process the input stream, and I don't want the client to timeout waiting for the response.

I've implemented this, but the problem is that, as soon as I return 201 Created from the resource method, jersey closes the input stream. I presume it also stops attempting to receive input from the client at this point.

Seems like my only option is to spool the input stream to a temporary disk file in the foreground, and then return a Created response. Then spawn a background thread to read from the file.

Is there a better way?

0

There are 0 best solutions below