Repository: camel Updated Branches: refs/heads/camel-2.13.x 8a50d4278 -> e9dded769 refs/heads/camel-2.14.x d59eabb0e -> 6687fafad
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/4c919880 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4c919880 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4c919880 Branch: refs/heads/camel-2.14.x Commit: 4c919880c8e9c89bcfca35a9c1257a5073c2cf88 Parents: d59eabb Author: Willem Jiang <willem.ji...@gmail.com> Authored: Fri Nov 21 23:02:46 2014 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Fri Nov 21 23:07:11 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/4c919880/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 cb92d44..207bf57 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 @@ -90,7 +90,8 @@ public class HttpServerChannelHandler extends ServerChannelHandler { response.headers().set(Exchange.CONTENT_TYPE, "text/plain"); response.headers().set(Exchange.CONTENT_LENGTH, 0); response.setContent(ChannelBuffers.copiedBuffer(new byte[]{})); - messageEvent.getChannel().write(response); + messageEvent.getChannel().write(response).syncUninterruptibly(); + messageEvent.getChannel().close(); return; } @@ -118,7 +119,8 @@ public class HttpServerChannelHandler extends ServerChannelHandler { response.headers().set(Exchange.CONTENT_TYPE, "text/plain"); response.headers().set(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()) { @@ -127,7 +129,8 @@ public class HttpServerChannelHandler extends ServerChannelHandler { response.headers().set(Exchange.CONTENT_TYPE, "text/plain"); response.headers().set(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 @@ -137,7 +140,8 @@ public class HttpServerChannelHandler extends ServerChannelHandler { response.headers().set(Exchange.CONTENT_TYPE, "text/plain"); response.headers().set(Exchange.CONTENT_LENGTH, 0); response.setContent(ChannelBuffers.copiedBuffer(new byte[]{})); - messageEvent.getChannel().write(response); + messageEvent.getChannel().write(response).syncUninterruptibly(); + messageEvent.getChannel().close(); return; } @@ -199,7 +203,8 @@ public class HttpServerChannelHandler extends ServerChannelHandler { response.headers().set(Exchange.CONTENT_TYPE, "text/plain"); response.headers().set(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/4c919880/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 8c835e2..71b777e 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 @@ -114,7 +114,9 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand response.headers().set(Exchange.CONTENT_TYPE, "text/plain"); response.headers().set(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(); } } @@ -132,7 +134,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(); } }