CAMEL-8072 Camel Netty Http Server should close the channel once it return an error message
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e9dded76 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e9dded76 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e9dded76 Branch: refs/heads/camel-2.13.x Commit: e9dded769bff8e060c64e62c962cd552d24d4c70 Parents: 8a50d42 Author: Willem Jiang <[email protected]> Authored: Fri Nov 21 23:02:46 2014 +0800 Committer: Willem Jiang <[email protected]> Committed: Fri Nov 21 23:07:57 2014 +0800 ---------------------------------------------------------------------- .../http/handlers/HttpServerChannelHandler.java | 15 ++++++++++----- .../handlers/HttpServerMultiplexChannelHandler.java | 8 ++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/e9dded76/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java index 63edef7..a30834d 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerChannelHandler.java @@ -85,7 +85,8 @@ public class HttpServerChannelHandler extends ServerChannelHandler { response.setHeader(Exchange.CONTENT_TYPE, "text/plain"); response.setHeader(Exchange.CONTENT_LENGTH, 0); response.setContent(ChannelBuffers.copiedBuffer(new byte[]{})); - messageEvent.getChannel().write(response); + messageEvent.getChannel().write(response).syncUninterruptibly(); + messageEvent.getChannel().close(); return; } if (consumer.getEndpoint().getHttpMethodRestrict() != null @@ -95,7 +96,8 @@ public class HttpServerChannelHandler extends ServerChannelHandler { response.setHeader(Exchange.CONTENT_TYPE, "text/plain"); response.setHeader(Exchange.CONTENT_LENGTH, 0); response.setContent(ChannelBuffers.copiedBuffer(new byte[]{})); - messageEvent.getChannel().write(response); + messageEvent.getChannel().write(response).syncUninterruptibly(); + messageEvent.getChannel().close(); return; } if ("TRACE".equals(request.getMethod().getName()) && !consumer.getEndpoint().isTraceEnabled()) { @@ -104,7 +106,8 @@ public class HttpServerChannelHandler extends ServerChannelHandler { response.setHeader(Exchange.CONTENT_TYPE, "text/plain"); response.setHeader(Exchange.CONTENT_LENGTH, 0); response.setContent(ChannelBuffers.copiedBuffer(new byte[]{})); - messageEvent.getChannel().write(response); + messageEvent.getChannel().write(response).syncUninterruptibly(); + messageEvent.getChannel().close(); return; } // must include HOST header as required by HTTP 1.1 @@ -114,7 +117,8 @@ public class HttpServerChannelHandler extends ServerChannelHandler { response.setHeader(Exchange.CONTENT_TYPE, "text/plain"); response.setHeader(Exchange.CONTENT_LENGTH, 0); response.setContent(ChannelBuffers.copiedBuffer(new byte[]{})); - messageEvent.getChannel().write(response); + messageEvent.getChannel().write(response).syncUninterruptibly(); + messageEvent.getChannel().close(); return; } @@ -176,7 +180,8 @@ public class HttpServerChannelHandler extends ServerChannelHandler { response.setHeader(Exchange.CONTENT_TYPE, "text/plain"); response.setHeader(Exchange.CONTENT_LENGTH, 0); response.setContent(ChannelBuffers.copiedBuffer(new byte[]{})); - messageEvent.getChannel().write(response); + messageEvent.getChannel().write(response).syncUninterruptibly(); + messageEvent.getChannel().close(); return; } else { LOG.debug("Http Basic Auth authorized for username: {}", principal.getUsername()); http://git-wip-us.apache.org/repos/asf/camel/blob/e9dded76/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java index 5075170..3498dc4 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java @@ -107,7 +107,9 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand response.setHeader(Exchange.CONTENT_TYPE, "text/plain"); response.setHeader(Exchange.CONTENT_LENGTH, 0); response.setContent(ChannelBuffers.copiedBuffer(new byte[]{})); - messageEvent.getChannel().write(response); + messageEvent.getChannel().write(response).syncUninterruptibly(); + // close the channel after send error message + messageEvent.getChannel().close(); } } @@ -125,7 +127,9 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand response.headers().set(Exchange.CONTENT_LENGTH, 0); // Here we don't want to expose the exception detail to the client response.setContent(ChannelBuffers.copiedBuffer(new byte[]{})); - ctx.getChannel().write(response); + ctx.getChannel().write(response).syncUninterruptibly(); + // close the channel after send error message + ctx.getChannel().close(); } }
