You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/10/09 04:34:07 UTC

[5/7] git commit: CAMEL-7896 netty http producer should close the channel when theresponse connection header is close

CAMEL-7896 netty http producer should close the channel when theresponse connection header is close


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d843918a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d843918a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d843918a

Branch: refs/heads/camel-2.13.x
Commit: d843918a90126e177026cfdfe7a727580bb3a79a
Parents: a5eb8c0
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Oct 8 21:32:39 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Thu Oct 9 10:32:38 2014 +0800

----------------------------------------------------------------------
 .../netty/http/handlers/HttpClientChannelHandler.java         | 7 +++++++
 .../camel/component/netty/handlers/ClientChannelHandler.java  | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d843918a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpClientChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpClientChannelHandler.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpClientChannelHandler.java
index 0f3a7a9..f1abaac 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpClientChannelHandler.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpClientChannelHandler.java
@@ -20,6 +20,7 @@ import java.util.Map;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
+import org.apache.camel.component.netty.NettyConstants;
 import org.apache.camel.component.netty.handlers.ClientChannelHandler;
 import org.apache.camel.component.netty.http.NettyHttpProducer;
 import org.jboss.netty.buffer.ChannelBuffer;
@@ -28,6 +29,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
 import org.jboss.netty.channel.MessageEvent;
 import org.jboss.netty.handler.codec.http.HttpChunk;
 import org.jboss.netty.handler.codec.http.HttpChunkTrailer;
+import org.jboss.netty.handler.codec.http.HttpHeaders;
 import org.jboss.netty.handler.codec.http.HttpResponse;
 import org.jboss.netty.handler.codec.http.HttpResponseStatus;
 import org.slf4j.Logger;
@@ -91,6 +93,11 @@ public class HttpClientChannelHandler extends ClientChannelHandler {
             }
         } else if (msg instanceof HttpResponse) {
             response = (HttpResponse) msg;
+            Exchange exchange = super.getExchange(ctx);
+            if (!HttpHeaders.isKeepAlive(response)) {
+                // just want to make sure we close the channel if the keepAlive is not true
+                exchange.setProperty(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, true);
+            }
             if (LOG.isTraceEnabled()) {
                 LOG.trace("HttpResponse received: {} chunked:", response, response.isChunked());
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/d843918a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
index e0ddb9f..ea9d578 100644
--- a/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
+++ b/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ClientChannelHandler.java
@@ -222,7 +222,7 @@ public class ClientChannelHandler extends SimpleChannelUpstreamHandler {
         }
     }
 
-    private Exchange getExchange(ChannelHandlerContext ctx) {
+    protected Exchange getExchange(ChannelHandlerContext ctx) {
         NettyCamelState state = producer.getState(ctx.getChannel());
         return state != null ? state.getExchange() : null;
     }