camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: CAMEL-7782 Close the channel when the authentication error is sent back to client
Date Fri, 05 Sep 2014 14:45:18 GMT
Repository: camel
Updated Branches:
  refs/heads/master d3c59647e -> 23ea202d3


CAMEL-7782 Close the channel when the authentication error is sent back to client


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

Branch: refs/heads/master
Commit: 23ea202d3c1a4e87da8ee98cd398ed7ac298a0bc
Parents: d3c5964
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Fri Sep 5 22:45:04 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Fri Sep 5 22:45:04 2014 +0800

----------------------------------------------------------------------
 .../netty4/http/handlers/HttpServerChannelHandler.java   |  2 ++
 .../netty4/http/NettyHttpSimpleBasicAuthTest.java        | 11 ++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/23ea202d/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 38e0798..eb33c4c 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
@@ -191,6 +191,8 @@ public class HttpServerChannelHandler extends ServerChannelHandler {
                     response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
                     response.headers().set(Exchange.CONTENT_LENGTH, 0);
                     ctx.writeAndFlush(response);
+                    // close the channel
+                    ctx.channel().close();
                     return;
                 } else {
                     LOG.debug("Http Basic Auth authorized for username: {}", principal.getUsername());

http://git-wip-us.apache.org/repos/asf/camel/blob/23ea202d/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthTest.java
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthTest.java
index bcdd107..cb74342 100644
--- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthTest.java
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthTest.java
@@ -36,8 +36,17 @@ public class NettyHttpSimpleBasicAuthTest extends BaseNettyTest {
 
     @Test
     public void testBasicAuth() throws Exception {
+        
+        try {
+            template.requestBody("netty4-http:http://localhost:{{port}}/foo", "Hello World",
String.class);
+            fail("Should send back 401");
+        } catch (CamelExecutionException e) {
+            NettyHttpOperationFailedException cause = assertIsInstanceOf(NettyHttpOperationFailedException.class,
e.getCause());
+            assertEquals(401, cause.getStatusCode());
+        }
+        
         getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");
-
+        
         // username:password is scott:secret
         String auth = "Basic c2NvdHQ6c2VjcmV0";
         String out = template.requestBodyAndHeader("netty4-http:http://localhost:{{port}}/foo",
"Hello World", "Authorization", auth, String.class);


Mime
View raw message