camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/7] camel git commit: CAMEL-10788 : Fixed handler loop when multiple endpoints on the same port have more then one handler
Date Sun, 05 Feb 2017 11:16:16 GMT
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/b02bb2fe
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b02bb2fe
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b02bb2fe

Branch: refs/heads/camel-2.18.x
Commit: b02bb2fe45074e0114fc0c916aa0a773b856333a
Parents: 799b78d
Author: Ton Swieb <ton.swieb@finalist.nl>
Authored: Sat Feb 4 19:58:24 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Feb 5 10:10:14 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/b02bb2fe/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 b89a90f..b7dee08 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
@@ -1245,8 +1245,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);
                     }
@@ -1259,6 +1259,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/b02bb2fe/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);
+                			}
+                		});
             };
         };
     }


Mime
View raw message