You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/04/07 10:42:53 UTC
[2/4] camel git commit: CAMEL-9768: Close the stream either now or
later depending on that disable stream cache option. This closes #932.
CAMEL-9768: Close the stream either now or later depending on that disable stream cache option. This closes #932.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d72b9af0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d72b9af0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d72b9af0
Branch: refs/heads/master
Commit: d72b9af01be9a0efbccb06a955b69c6239154587
Parents: f918aad
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Apr 7 10:42:18 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Apr 7 10:42:18 2016 +0200
----------------------------------------------------------------------
.../camel/component/http4/HttpProducer.java | 23 ++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d72b9af0/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
index 4edc6c5..c59c3b8 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java
@@ -43,6 +43,7 @@ import org.apache.camel.http.common.HttpOperationFailedException;
import org.apache.camel.http.common.HttpProtocolHeaderFilterStrategy;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.support.SynchronizationAdapter;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.GZIPHelper;
import org.apache.camel.util.IOHelper;
@@ -179,11 +180,25 @@ public class HttpProducer extends DefaultProducer {
}
}
} finally {
- if (httpResponse != null && !getEndpoint().isDisableStreamCache()) {
+ final HttpResponse response = httpResponse;
+ if (httpResponse != null && getEndpoint().isDisableStreamCache()) {
+ // close the stream at the end of the exchange to ensure it gets eventually closed later
+ exchange.addOnCompletion(new SynchronizationAdapter() {
+ @Override
+ public void onDone(Exchange exchange) {
+ try {
+ EntityUtils.consume(response.getEntity());
+ } catch (Throwable e) {
+ // ignore
+ }
+ }
+ });
+ } else if (httpResponse != null) {
+ // close the stream now
try {
- EntityUtils.consume(httpResponse.getEntity());
- } catch (IOException e) {
- // nothing we could do
+ EntityUtils.consume(response.getEntity());
+ } catch (Throwable e) {
+ // ignore
}
}
}