Updated Branches: refs/heads/master 0916620d8 -> 5e57a5c05
CAMEL-6945 NettyHttpProducer closes the connection when the request 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/5e57a5c0 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5e57a5c0 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5e57a5c0 Branch: refs/heads/master Commit: 5e57a5c053304876f3a9b794638909519f15dc4b Parents: 0916620 Author: Willem Jiang <willem.ji...@gmail.com> Authored: Fri Nov 8 13:36:38 2013 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Fri Nov 8 13:36:38 2013 +0800 ---------------------------------------------------------------------- .../apache/camel/component/netty/http/NettyHttpProducer.java | 8 +++++++- .../camel/component/netty/handlers/ClientChannelHandler.java | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/5e57a5c0/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java index 8a5ae2e..857c875 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java @@ -21,7 +21,9 @@ import java.net.URI; import org.apache.camel.AsyncCallback; import org.apache.camel.Exchange; import org.apache.camel.component.netty.NettyConfiguration; +import org.apache.camel.component.netty.NettyConstants; import org.apache.camel.component.netty.NettyProducer; +import org.jboss.netty.handler.codec.http.HttpHeaders; import org.jboss.netty.handler.codec.http.HttpRequest; import org.jboss.netty.handler.codec.http.HttpResponse; @@ -58,7 +60,11 @@ public class NettyHttpProducer extends NettyProducer { HttpRequest request = getEndpoint().getNettyHttpBinding().toNettyRequest(exchange.getIn(), u.toString(), getConfiguration()); String actualUri = request.getUri(); exchange.getIn().setHeader(Exchange.HTTP_URL, actualUri); - + // Need to check if we need to close the connection or not + if (!HttpHeaders.isKeepAlive(request)) { + // 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 (getConfiguration().isBridgeEndpoint()) { // Need to remove the Host key as it should be not used when bridging/proxying exchange.getIn().removeHeader("host"); http://git-wip-us.apache.org/repos/asf/camel/blob/5e57a5c0/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 ef05486..3d58471 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 @@ -162,7 +162,12 @@ public class ClientChannelHandler extends SimpleChannelUpstreamHandler { } else { close = exchange.getIn().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class); } - + + // check the setting on the exchange property + if (close == null) { + close = exchange.getProperty(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class); + } + // should we disconnect, the header can override the configuration boolean disconnect = producer.getConfiguration().isDisconnect(); if (close != null) {