You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by alexey-s <al...@mail.ru> on 2012/08/06 21:25:15 UTC
[HTTP4] HttpProducer close temporary file in CachedOutputStream
I found a nasty bug.
HttpProducer uses a temporary file within the object CachedOutputStream. If
the static method doExtractResponseBodyAsStream get an error reading an
incoming message, we lose information on the temporary file.
I propose to add a block catch (IOException e) to trap the error and delete
the temporary file within the mining method CachedOutputStream.close().
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
cos = new CachedOutputStream(exchange, false);
IOHelper.copy(is, cos);
// When the InputStream is closed, the CachedOutputStream will
be closed
return cos.getWrappedInputStream();
} catch(IOException e) {
if(cos != null) {
try { cos.close(); } cact(IOException ignore) {}
}
}
} finally {
IOHelper.close(is, "Extracting response body", LOG);
}
}
--
View this message in context: http://camel.465427.n5.nabble.com/HTTP4-HttpProducer-close-temporary-file-in-CachedOutputStream-tp5716885.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: [HTTP4] HttpProducer close temporary file in CachedOutputStream
Posted by Willem Jiang <wi...@gmail.com>.
Don't worry, I'm already take care of it.
I will commit the patch once I finish to run the whole tests rightly.
Willem
On Tue, Aug 7, 2012 at 2:30 PM, alexey-s <al...@mail.ru> wrote:
> Thank you, Willem.
> I'm in a catch block forgot to send the resulting error (IOException e) on
> the top.
>
> Aleksey
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/HTTP4-HttpProducer-close-temporary-file-in-CachedOutputStream-tp5716885p5716907.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
Re: [HTTP4] HttpProducer close temporary file in CachedOutputStream
Posted by alexey-s <al...@mail.ru>.
Thank you, Willem.
I'm in a catch block forgot to send the resulting error (IOException e) on
the top.
Aleksey
--
View this message in context: http://camel.465427.n5.nabble.com/HTTP4-HttpProducer-close-temporary-file-in-CachedOutputStream-tp5716885p5716907.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: [HTTP4] HttpProducer close temporary file in CachedOutputStream
Posted by Willem Jiang <wi...@gmail.com>.
It sounds good, I just create a JIRA[1] to trace this issue.
[1]https://issues.apache.org/jira/browse/CAMEL-5487
Willem
On Tue, Aug 7, 2012 at 3:25 AM, alexey-s <al...@mail.ru> wrote:
> I found a nasty bug.
> HttpProducer uses a temporary file within the object CachedOutputStream. If
> the static method doExtractResponseBodyAsStream get an error reading an
> incoming message, we lose information on the temporary file.
> I propose to add a block catch (IOException e) to trap the error and delete
> the temporary file within the mining method CachedOutputStream.close().
>
>
> 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
> cos = new CachedOutputStream(exchange, false);
> IOHelper.copy(is, cos);
> // When the InputStream is closed, the CachedOutputStream will
> be closed
> return cos.getWrappedInputStream();
> } catch(IOException e) {
> if(cos != null) {
> try { cos.close(); } cact(IOException ignore) {}
> }
> }
> } finally {
> IOHelper.close(is, "Extracting response body", LOG);
> }
> }
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/HTTP4-HttpProducer-close-temporary-file-in-CachedOutputStream-tp5716885.html
> Sent from the Camel - Users mailing list archive at Nabble.com.