You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/11/21 16:06:39 UTC
[1/2] camel git commit: CAMEL-8072 Camel Netty4 Http Server should
close the channel once it return an error message
Repository: camel
Updated Branches:
refs/heads/master 6edc6649f -> 1b79de058
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/1b79de05
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1b79de05
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1b79de05
Branch: refs/heads/master
Commit: 1b79de0588fdb8f488282c6a9a5471522aa7ec25
Parents: 4c1fd02
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Nov 21 23:03:11 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Nov 21 23:03:38 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/1b79de05/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/1b79de05/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();
}
}
[2/2] camel git commit: CAMEL-8072 Camel Netty Http Server should
close the channel once it return an error message
Posted by ni...@apache.org.
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/4c1fd028
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4c1fd028
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4c1fd028
Branch: refs/heads/master
Commit: 4c1fd0286c56eb62df80040fc43ed925f60091ca
Parents: 6edc664
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Nov 21 23:02:46 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Nov 21 23:03:38 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/4c1fd028/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/4c1fd028/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();
}
}