Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 70427200C21 for ; Sun, 5 Feb 2017 12:16:16 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 6EEC0160B32; Sun, 5 Feb 2017 11:16:16 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7D7BE160B6A for ; Sun, 5 Feb 2017 12:16:15 +0100 (CET) Received: (qmail 12323 invoked by uid 500); 5 Feb 2017 11:16:14 -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 11863 invoked by uid 99); 5 Feb 2017 11:16:14 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Feb 2017 11:16:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A790AE041B; Sun, 5 Feb 2017 11:16:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Sun, 05 Feb 2017 11:16:14 -0000 Message-Id: <8af51cee937940a081e4b5106033916d@git.apache.org> In-Reply-To: <43b97f87a25b4425b914dc8f3ae9e0e0@git.apache.org> References: <43b97f87a25b4425b914dc8f3ae9e0e0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/7] camel git commit: CAMEL-10788 : Fixed handler loop when multiple endpoints on the same port have more then one handler archived-at: Sun, 05 Feb 2017 11:16:16 -0000 CAMEL-10788 : Fixed handler loop when multiple endpoints on the same port have more then one handler Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9596cc26 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9596cc26 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9596cc26 Branch: refs/heads/master Commit: 9596cc26fcae1c2b1e82e476f9545911f41987df Parents: 1d07f64 Author: Ton Swieb Authored: Sat Feb 4 19:58:24 2017 +0100 Committer: Claus Ibsen Committed: Sun Feb 5 09:07:17 2017 +0100 ---------------------------------------------------------------------- .../component/jetty/JettyHttpComponent.java | 19 ++++++++++++-- .../camel/component/jetty/HandlerTest.java | 26 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/9596cc26/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java index a9fc5e2..ef3228d 100644 --- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java +++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java @@ -1229,8 +1229,8 @@ public abstract class JettyHttpComponent extends HttpCommonComponent implements if (handlers != null && !handlers.isEmpty()) { for (Handler handler : handlers) { if (handler instanceof HandlerWrapper) { - // avoid setting the security handler more than once - if (!handler.equals(server.getHandler())) { + // avoid setting a handler more than once + if (!isHandlerInChain(server.getHandler(), handler)) { ((HandlerWrapper) handler).setHandler(server.getHandler()); server.setHandler(handler); } @@ -1243,6 +1243,21 @@ public abstract class JettyHttpComponent extends HttpCommonComponent implements } } } + + protected boolean isHandlerInChain(Handler current, Handler handler) { + + if (handler.equals(current)) { + //Found a match in the chain + return true; + } else if (current instanceof HandlerWrapper) { + //Inspect the next handler in the chain + return isHandlerInChain(((HandlerWrapper) current).getHandler(), handler); + } else { + //End of chain + return false; + } + + } protected Server createServer() { Server s = null; http://git-wip-us.apache.org/repos/asf/camel/blob/9596cc26/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HandlerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HandlerTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HandlerTest.java index 48d5198..7f309a9 100644 --- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HandlerTest.java +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HandlerTest.java @@ -69,6 +69,26 @@ public class HandlerTest extends BaseJettyTest { assertEquals(1, statisticsHandler3.getRequests()); } + @Test + public void testWithTwoHandlersTwoEndpointsOnSamePort() throws Exception { + // First test the situation where one should invoke the handler once + assertEquals(0, statisticsHandler1.getRequests()); + assertEquals(0, statisticsHandler2.getRequests()); + assertEquals(0, statisticsHandler3.getRequests()); + + InputStream html1 = (InputStream) template.requestBody("http://localhost:" + port2, ""); + BufferedReader br1 = IOHelper.buffered(new InputStreamReader(html1)); + assertEquals(htmlResponse, br1.readLine()); + + InputStream html2 = (InputStream) template.requestBody("http://localhost:" + port2 + "/endpoint2", ""); + BufferedReader br2 = IOHelper.buffered(new InputStreamReader(html2)); + assertEquals(htmlResponse, br2.readLine()); + + assertEquals(0, statisticsHandler1.getRequests()); + assertEquals(2, statisticsHandler2.getRequests()); + assertEquals(2, statisticsHandler3.getRequests()); + } + @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry jndi = super.createRegistry(); @@ -98,6 +118,12 @@ public class HandlerTest extends BaseJettyTest { exchange.getOut().setBody(htmlResponse); } }); + from("jetty:http://localhost:" + port2 + "/endpoint2?handlers=#statisticsHandler2,#statisticsHandler3") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setBody(htmlResponse); + } + }); }; }; }