On 03/01/2015 09:35, Henryk Konsek wrote:
Hi Tim,

Is there a way to stream output using the Rest DSL?
I used the following to download stream of bytes from the REST API:

rest("/api").
         
get("/download").bindingMode(RestBindingMode.off).produces('application/octet-stream').route().
         setBody().constant(new ByteArrayOutputStream("foo".getBytes()));.

So I guess that setting OutputStream as the response body should do the trick.

Cheers.
Henryk, thanks for the suggestion.
So the problem I see with that is that
1. the complete byte array has to be held in memory so it doesn't scale
2. the first byte isn't sent until the last one is generated so you don't get an immediate response

I was thinking you need to somehow get a "forward reference" to an OutputStream to write to. I tried setting a javax.ws.rs.core.StreamingOutput in the hope that this would be handled, but it wasn't (just got the toString() representation).

Also, I don't understand the .constant() bit. The value is not a constant, so I don't see why that's needed.

Tim


Reply via email to