Author: ningjiang Date: Tue Aug 7 13:32:43 2012 New Revision: 1370254 URL: http://svn.apache.org/viewvc?rev=1370254&view=rev Log: CAMEL-5487 HttpProducer should close temporary file in CachedOutputStream when the exception is throw
Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=1370254&r1=1370253&r2=1370254&view=diff ============================================================================== --- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java (original) +++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java Tue Aug 7 13:32:43 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/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java?rev=1370254&r1=1370253&r2=1370254&view=diff ============================================================================== --- camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java (original) +++ camel/trunk/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java Tue Aug 7 13:32:43 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); }