You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/02/05 11:16:18 UTC
[6/7] camel git commit: CAMEL-10788 : Fixed handler loop when
multiple endpoints on the same port have more then one handler
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/3618b97f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3618b97f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3618b97f
Branch: refs/heads/camel-2.17.x
Commit: 3618b97fb82c25dd87f56ef6c4607de71bb8a6a0
Parents: 019aa06
Author: Ton Swieb <to...@finalist.nl>
Authored: Sat Feb 4 19:58:24 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Feb 5 10:10:49 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/3618b97f/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 33fe88c..c5d13ed 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
@@ -1139,8 +1139,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);
}
@@ -1153,6 +1153,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/3618b97f/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);
+ }
+ });
};
};
}