[
https://issues.apache.org/jira/browse/CAMEL-6294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13634858#comment-13634858
]
Ulrich Kramer edited comment on CAMEL-6294 at 4/18/13 5:58 AM:
---------------------------------------------------------------
h3. Multiple convertions
If you call msg.getBody in your Processor twice you don't know if the exchange
was created using a StreamCache. To be sure, you always have to call
MessageHelper.resetStreamCache before you call Message.getBody.
Wouldn't it be easier to call MessageHelper.resetStreamCache during the
convertion of StreamCache to something else?
Additionally there should be no automatic convertion from StreamCache to
InputStream (FileInputStreamCache extends InputStream). I think it would be
better to extend the StreamCache interface with a method returning an
InputStream. This method could be used to convert StreamCache instances to
InputStreams. Today two concurrent readers get the same InputStream object.
h3. Closing InputStream
I think it should be possible to call FileInputStreamCache.close without
getting an exception on a the following convertion. This could be also achieved
by calling MessageHelper.resetStreamCache during each convertion or by setting
stream to null in FileInputStreamCache.close.
h3. Closing CachedOutputStream
Many source code analyzers want a stream to be closed before leaving the
method. I think it should be easy to hand over the ownership of the temporary
file from CachedOutputStream to FileInputStreamCache during the call to
getStreamCache
was (Author: ulrich.kramer):
h3. Multiple convertions
If you call msg.getBody in your Processor twice you don't know if the exchange
was created using a StreamCache. To be sure, you always have to call
MessageHelper.resetStreamCache before you call Message.getBody.
Wouldn't it be easier to call MessageHelper.resetStreamCache during the
convertion of StreamCache to something else?
h3. Closing InputStream
I think it should be possible to call FileInputStreamCache.close without
getting an exception on a the following convertion. This could be also achieved
by calling MessageHelper.resetStreamCache during each convertion or by setting
stream to null in FileInputStreamCache.close.
h3. Closing CachedOutputStream
Many source code analyzers want a stream to be closed before leaving the
method. I think it should be easy to hand over the ownership of the temporary
file from CachedOutputStream to FileInputStreamCache during the call to
getStreamCache
> StreamCache doesn't work as expected
> ------------------------------------
>
> Key: CAMEL-6294
> URL: https://issues.apache.org/jira/browse/CAMEL-6294
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 2.10.4
> Environment: Debian 6.0
> Reporter: Ulrich Kramer
> Assignee: Willem Jiang
> Fix For: 2.10.5
>
>
> The following Unittests fail:
> {code}
> package com.sap.camel.util;
> import java.io.InputStream;
> import junit.framework.Assert;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Exchange;
> import org.apache.camel.Message;
> import org.apache.camel.converter.stream.CachedOutputStream;
> import org.apache.camel.impl.DefaultCamelContext;
> import org.apache.camel.impl.DefaultExchange;
> import org.testng.annotations.Test;
> public class StreamCacheBugs {
>
> private CamelContext context;
> public void setUp() {
>
> context = new DefaultCamelContext();
> }
> @Test
> public void multipleConvertionsYielsToEmptyBody() throws Exception {
> Exchange exchange = new DefaultExchange(context);
> Message msg = exchange.getIn();
> CachedOutputStream out = new CachedOutputStream(exchange);
> out.write("Hello World".getBytes());
> msg.setBody(out.getStreamCache());
> Assert.assertEquals(msg.getBody(String.class), "Hello World");
> Assert.assertEquals(msg.getBody(String.class), "Hello World");
> }
> @Test
> public void closingInputStreamYieldsToException() throws Exception {
> Exchange exchange = new DefaultExchange(context);
> Message msg = exchange.getIn();
> CachedOutputStream out = new CachedOutputStream(exchange);
> for ( int i = 0 ; i < 10000; i++)
> out.write("0123456789".getBytes());
> msg.setBody(out.getStreamCache());
> InputStream in = msg.getBody(InputStream.class);
> in.read();
> in.close();
> msg.getBody(String.class);
> }
>
> @Test
> public void cachedOutputStreamsShouldBeClosable() throws Exception {
> Exchange exchange = new DefaultExchange(context);
> Message msg = exchange.getIn();
> CachedOutputStream out = new CachedOutputStream(exchange);
> for ( int i = 0 ; i < 10000; i++)
> out.write("0123456789".getBytes());
> msg.setBody(out.getStreamCache());
> out.close();
> msg.getBody(String.class);
> }
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira