If you are using http client 3, it will clean up the input stream when you 
close the connection.  
You can find more information by checking the the comments in the 
doExtractResponseBodyAsStream.

That is why we need to cache the input stream as it will be used in the other 
part of camel route.

If you disable the streamCache it doesn't affect it, but you may consider to 
disable cache the stream into file as the default size is 64K.  

--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) 
(English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Tuesday, July 2, 2013 at 5:10 PM, Bernard Ligny wrote:

> I've got a back-end web service returning large **chunked** data.
> I have defined a Camel route with a proxy to this web service.
> I do not want Camel to buffer the entire back-end response, and then return
> it as a whole to the client.
> Instead, i would like to preserve the original streaming (mainly to avoid
> read timeouts on the client side).
>  
> How can i achieve this (a "pipe" actually) in Camel ?
> Even when I disable "streamCache" on CamelContext, it seems Camel is yet
> buffering internally the response.
>  
> Hereunder the difference between a direct call to the back-end, and the same
> call via Camel:
>  
> <http://camel.465427.n5.nabble.com/file/n5735075/difference.png>  
>  
> => see Latency !
> In the first case, client gets a beginning of response after 2 sec,
> while in the second case, he has to wait for 12 sec before getting any
> data...
>  
>  
>  
> I looked into the code of "HttpProducer.java", and I'm a bit puzzled about
> what i can see in the "doExtractResponseBodyAsStream" method:
>  
>  
> private static InputStream doExtractResponseBodyAsStream(InputStream is,
> Exchange exchange) throws IOException {
> // As httpclient is using a AutoCloseInputStream, it will be closed
> when the connection is closed
> // we need to cache the stream for it.
> try {
> // This CachedOutputStream will not be closed when the exchange
> is onCompletion
> CachedOutputStream cos = new CachedOutputStream(exchange,
> false);
> IOHelper.copy(is, cos);
> // When the InputStream is closed, the CachedOutputStream will
> be closed
> return cos.getWrappedInputStream();
> } finally {
> IOHelper.close(is, "Extracting response body", LOG);
> }
> }
>  
>  
> If you always *copy* the stream, you need to read the whole stream :-(
> Where do you take account of the "streamCache" flag when deciding to cache
> or not cache the response input stream ?
>  
> Thanks for your help.
>  
> Bernard.
>  
>  
>  
>  
>  
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Chunking-issue-with-http-producer-tp5735075.html
> Sent from the Camel - Users mailing list archive at Nabble.com 
> (http://Nabble.com).



Reply via email to