Re: streaming results using rest dsl

2015-01-04 Thread Claus Ibsen
Hi

It depends on what component you use with the rest-dsl. eg jetty /
restlet etc and what they support. Usually they support the body as a
InputStream type which they can use to transfer to their output
stream.

Not sure if any of them support the RS spec classes / annotations. But
it would be nice to add that to the rest-dsl so ppl can use those
apis/classes as well. Though it would require some work to map/binding
that to what they support. And it would also be great to have
camel-cxf supported as well as it support those RS
classes/annotations. But last time I looked CXF wasn't able (or it was
hard to do) to define REST services without writing java code.
https://issues.apache.org/jira/browse/CAMEL-7652

On Fri, Jan 2, 2015 at 8:15 PM, Tim Dudgeon tdudgeon...@gmail.com wrote:
 Is there a way to stream output using the Rest DSL?
 Something like using the JAC-RS StreamingOutput class?
 http://docs.oracle.com/javaee/6/api/javax/ws/rs/core/StreamingOutput.html

 I have large amount of data (split into multiple Exchanges) and don't want
 to wait for all to be processed before start sending the response.

 Tim




-- 
Claus Ibsen
-
Red Hat, Inc.
Email: cib...@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/


Re: streaming results using rest dsl

2015-01-04 Thread Claus Ibsen
On Sat, Jan 3, 2015 at 11:22 AM, Tim Dudgeon tdudgeon...@gmail.com wrote:
 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


That is just because of this example using a byte array. But you
should be able to use a FileInputStream or other stream that reads in
chunks.

For 2 I guess it depends on the component in use what it does and how
big its buffers are. I guess you can tweak those to be higher/lower to
force it to write the first bytes sooner.

Also I guess it may depend on whether you use chunked http mode as well.


 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





-- 
Claus Ibsen
-
Red Hat, Inc.
Email: cib...@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/


Re: streaming results using rest dsl

2015-01-03 Thread Henryk Konsek
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 Konsek
http://henryk-konsek.blogspot.com


streaming results using rest dsl

2015-01-02 Thread Tim Dudgeon

Is there a way to stream output using the Rest DSL?
Something like using the JAC-RS StreamingOutput class?
http://docs.oracle.com/javaee/6/api/javax/ws/rs/core/StreamingOutput.html

I have large amount of data (split into multiple Exchanges) and don't 
want to wait for all to be processed before start sending the response.


Tim