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:04 UTC

[2/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/581e96f2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/581e96f2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/581e96f2

Branch: refs/heads/camel-2.14.x
Commit: 581e96f254c7827480603efedc967f861f6083b1
Parents: f31e9ac
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:31:35 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/581e96f2/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 d463260..82df81c 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/581e96f2/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;
     }