Repository: camel Updated Branches: refs/heads/master 90b224e86 -> 1e9ab5446
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/1e9ab544 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1e9ab544 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1e9ab544 Branch: refs/heads/master Commit: 1e9ab544609069a18b279fb40e6c77c7da8aca67 Parents: 5b72f0a Author: Willem Jiang <[email protected]> Authored: Wed Jan 28 16:58:13 2015 +0800 Committer: Willem Jiang <[email protected]> Committed: Wed Jan 28 17:19:17 2015 +0800 ---------------------------------------------------------------------- .../HttpServerMultiplexChannelHandler.java | 23 +++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/1e9ab544/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 601d689..a6027e4 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 @@ -16,6 +16,7 @@ */ package org.apache.camel.component.netty4.http.handlers; +import java.nio.channels.ClosedChannelException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -133,14 +134,20 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl if (handler != null) { handler.exceptionCaught(ctx, cause); } else { - // we cannot throw the exception here - LOG.warn("HttpServerChannelHandler is not found as attachment to handle exception, send 404 back to the client.", cause); - // 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); - ctx.writeAndFlush(response); - ctx.close(); + if (cause 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.", cause); + // 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); + ctx.writeAndFlush(response); + ctx.close(); + } } }
