CAMEL-8072 Camel Netty4 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/6687fafa
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6687fafa
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6687fafa

Branch: refs/heads/camel-2.14.x
Commit: 6687fafad3adfc75f79b4d470756d7a68411660f
Parents: 4c91988
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Fri Nov 21 23:03:11 2014 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Fri Nov 21 23:07:28 2014 +0800

----------------------------------------------------------------------
 .../netty4/http/handlers/HttpServerChannelHandler.java   | 11 ++++++-----
 .../http/handlers/HttpServerMultiplexChannelHandler.java |  2 ++
 2 files changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6687fafa/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerChannelHandler.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerChannelHandler.java
 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerChannelHandler.java
index 7e72a86..cdbc999 100644
--- 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerChannelHandler.java
+++ 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerChannelHandler.java
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.component.netty4.http.handlers;
 
-import java.net.SocketAddress;
 import java.net.URI;
 import java.nio.channels.ClosedChannelException;
 import java.nio.charset.Charset;
@@ -26,16 +25,15 @@ import javax.security.auth.Subject;
 import javax.security.auth.login.LoginException;
 
 import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelFutureListener;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.base64.Base64;
 import io.netty.handler.codec.http.DefaultHttpResponse;
 import io.netty.handler.codec.http.HttpHeaders;
 import io.netty.handler.codec.http.HttpRequest;
 import io.netty.handler.codec.http.HttpResponse;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.LoggingLevel;
-import org.apache.camel.component.netty4.NettyConsumer;
 import org.apache.camel.component.netty4.NettyConverter;
 import org.apache.camel.component.netty4.NettyHelper;
 import org.apache.camel.component.netty4.handlers.ServerChannelHandler;
@@ -47,14 +45,13 @@ import org.apache.camel.util.CamelLogger;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import static io.netty.handler.codec.http.HttpHeaders.isKeepAlive;
+
 import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
 import static 
io.netty.handler.codec.http.HttpResponseStatus.METHOD_NOT_ALLOWED;
 import static io.netty.handler.codec.http.HttpResponseStatus.OK;
 import static 
io.netty.handler.codec.http.HttpResponseStatus.SERVICE_UNAVAILABLE;
 import static io.netty.handler.codec.http.HttpResponseStatus.UNAUTHORIZED;
 import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
-
 /**
  * Netty HTTP {@link ServerChannelHandler} that handles the incoming HTTP 
requests and routes
  * the received message in Camel.
@@ -89,6 +86,7 @@ public class HttpServerChannelHandler extends 
ServerChannelHandler {
             response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
             response.headers().set(Exchange.CONTENT_LENGTH, 0);
             ctx.writeAndFlush(response);
+            ctx.channel().close();
             return;
         }
 
@@ -114,6 +112,7 @@ public class HttpServerChannelHandler extends 
ServerChannelHandler {
             response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
             response.headers().set(Exchange.CONTENT_LENGTH, 0);
             ctx.writeAndFlush(response);
+            ctx.channel().close();
             return;
         }
         if ("TRACE".equals(request.getMethod().name()) && 
!consumer.getEndpoint().isTraceEnabled()) {
@@ -121,6 +120,7 @@ public class HttpServerChannelHandler extends 
ServerChannelHandler {
             response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
             response.headers().set(Exchange.CONTENT_LENGTH, 0);
             ctx.writeAndFlush(response);
+            ctx.channel().close();
             return;
         }
         // must include HOST header as required by HTTP 1.1
@@ -130,6 +130,7 @@ public class HttpServerChannelHandler extends 
ServerChannelHandler {
             response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
             response.headers().set(Exchange.CONTENT_LENGTH, 0);
             ctx.writeAndFlush(response);
+            ctx.channel().close();
             return;
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/6687fafa/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
----------------------------------------------------------------------
diff --git 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
index 348641f..601d689 100644
--- 
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
+++ 
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
@@ -122,6 +122,7 @@ public class HttpServerMultiplexChannelHandler extends 
SimpleChannelInboundHandl
             response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
             response.headers().set(Exchange.CONTENT_LENGTH, 0);
             ctx.writeAndFlush(response);
+            ctx.close();
         }
     }
 
@@ -139,6 +140,7 @@ public class HttpServerMultiplexChannelHandler extends 
SimpleChannelInboundHandl
             response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
             response.headers().set(Exchange.CONTENT_LENGTH, 0);
             ctx.writeAndFlush(response);
+            ctx.close();
         }
     }
 

Reply via email to