camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Dudgeon <>
Subject Re: streaming results using rest dsl
Date Sat, 03 Jan 2015 10:22:53 GMT
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('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 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.


View raw message