Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1DDF21121C for ; Fri, 5 Sep 2014 14:45:19 +0000 (UTC) Received: (qmail 85326 invoked by uid 500); 5 Sep 2014 14:45:19 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 85275 invoked by uid 500); 5 Sep 2014 14:45:18 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 85266 invoked by uid 99); 5 Sep 2014 14:45:18 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 05 Sep 2014 14:45:18 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 7E9D2A0A325; Fri, 5 Sep 2014 14:45:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ningjiang@apache.org To: commits@camel.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: CAMEL-7782 Close the channel when the authentication error is sent back to client Date: Fri, 5 Sep 2014 14:45:18 +0000 (UTC) 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 Authored: Fri Sep 5 22:45:04 2014 +0800 Committer: Willem Jiang 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);