Author: ningjiang Date: Wed Aug 8 03:44:31 2012 New Revision: 1370656 URL: http://svn.apache.org/viewvc?rev=1370656&view=rev Log: Merged revisions 1370254 via svnmerge from https://svn.apache.org/repos/asf/camel/trunk
........ r1370254 | ningjiang | 2012-08-07 21:32:43 +0800 (Tue, 07 Aug 2012) | 1 line CAMEL-5487 HttpProducer should close temporary file in CachedOutputStream when the exception is throw ........ Modified: camel/branches/camel-2.10.x/ (props changed) camel/branches/camel-2.10.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java camel/branches/camel-2.10.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java Propchange: camel/branches/camel-2.10.x/ ------------------------------------------------------------------------------ Merged /camel/trunk:r1370254 Propchange: camel/branches/camel-2.10.x/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: camel/branches/camel-2.10.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=1370656&r1=1370655&r2=1370656&view=diff ============================================================================== --- camel/branches/camel-2.10.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java (original) +++ camel/branches/camel-2.10.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java Wed Aug 8 03:44:31 2012 @@ -302,12 +302,23 @@ public class HttpProducer extends Defaul 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. + CachedOutputStream cos = null; try { // This CachedOutputStream will not be closed when the exchange is onCompletion - CachedOutputStream cos = new CachedOutputStream(exchange, false); + cos = new CachedOutputStream(exchange, false); IOHelper.copy(is, cos); // When the InputStream is closed, the CachedOutputStream will be closed return cos.getWrappedInputStream(); + } catch (IOException ex) { + // try to close the CachedOutputStream when we get the IOException + if (cos != null) { + try { + cos.close(); + } catch (IOException ignore) { + //do nothing here + } + } + throw ex; } finally { IOHelper.close(is, "Extracting response body", LOG); } Modified: camel/branches/camel-2.10.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java?rev=1370656&r1=1370655&r2=1370656&view=diff ============================================================================== --- camel/branches/camel-2.10.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java (original) +++ camel/branches/camel-2.10.x/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java Wed Aug 8 03:44:31 2012 @@ -307,12 +307,23 @@ public class HttpProducer extends Defaul 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. + CachedOutputStream cos = null; try { // This CachedOutputStream will not be closed when the exchange is onCompletion - CachedOutputStream cos = new CachedOutputStream(exchange, false); + cos = new CachedOutputStream(exchange, false); IOHelper.copy(is, cos); // When the InputStream is closed, the CachedOutputStream will be closed return cos.getWrappedInputStream(); + } catch (IOException ex) { + // try to close the CachedOutputStream when we get the IOException + if (cos != null) { + try { + cos.close(); + } catch (IOException ignore) { + //do nothing here + } + } + throw ex; } finally { IOHelper.close(is, "Extracting response body", LOG); }