Repository: camel
Updated Branches:
  refs/heads/camel-2.13.x ad87828b4 -> e8aec2d5b
  refs/heads/camel-2.14.x 53d87f5db -> 2bb612837


CAMEL-8289 Don't send out error message to the client if the connection is 
closed.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/383b4c46
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/383b4c46
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/383b4c46

Branch: refs/heads/camel-2.14.x
Commit: 383b4c46925bd0b334f441cf24d83e117ef9cda9
Parents: 53d87f5
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Wed Jan 28 16:57:51 2015 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Wed Jan 28 17:47:26 2015 +0800

----------------------------------------------------------------------
 .../HttpServerMultiplexChannelHandler.java      | 30 ++++++++++++--------
 1 file changed, 18 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/383b4c46/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 71b777e..07de856 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
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.netty.http.handlers;
 
+import java.nio.channels.ClosedChannelException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -40,7 +41,6 @@ import org.jboss.netty.handler.codec.http.HttpRequest;
 import org.jboss.netty.handler.codec.http.HttpResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import static org.jboss.netty.handler.codec.http.HttpResponseStatus.NOT_FOUND;
 import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
 
@@ -126,17 +126,23 @@ public class HttpServerMultiplexChannelHandler extends 
SimpleChannelUpstreamHand
         if (handler != null) {
             handler.exceptionCaught(ctx, e);
         } else {
-            // we cannot throw the exception here
-            LOG.warn("HttpServerChannelHandler is not found as attachment to 
handle exception, send 404 back to the client.", e.getCause());
-            // Now we just send 404 back to the client
-            HttpResponse response = new DefaultHttpResponse(HTTP_1_1, 
NOT_FOUND);
-            response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
-            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).syncUninterruptibly();
-            // close the channel after send error message
-            ctx.getChannel().close();
+            if (e.getCause() instanceof ClosedChannelException) {
+                // The channel is closed so we do nothing here
+                LOG.debug("Channel already closed. Ignoring this exception.");
+                return;
+            } else {
+                // we cannot throw the exception here
+                LOG.warn("HttpServerChannelHandler is not found as attachment 
to handle exception, send 404 back to the client.", e.getCause());
+                // Now we just send 404 back to the client
+                HttpResponse response = new DefaultHttpResponse(HTTP_1_1, 
NOT_FOUND);
+                response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
+                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).syncUninterruptibly();
+                // close the channel after send error message
+                ctx.getChannel().close();
+            }
         }
     }
 

Reply via email to