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 2015/08/22 12:22:59 UTC
[1/5] camel git commit: CAMEL-9096: rest-dsl - Reuse logic for
matching best rest path to use
Repository: camel
Updated Branches:
refs/heads/master f7d6de04c -> e36adb2fd
CAMEL-9096: rest-dsl - Reuse logic for matching best rest path to use
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0205fc92
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0205fc92
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0205fc92
Branch: refs/heads/master
Commit: 0205fc929934a358ee1f90f88c5194ee7c385c8c
Parents: f5aa83c
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Aug 21 14:07:42 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Aug 22 09:01:47 2015 +0200
----------------------------------------------------------------------
.../HttpRestServletResolveConsumerStrategy.java | 78 +++++++++++++++++++
.../component/jetty/JettyHttpComponent.java | 3 +-
...JettyRestServletResolveConsumerStrategy.java | 81 --------------------
.../servlet/CamelHttpTransportServlet.java | 3 +-
...rvletRestServletResolveConsumerStrategy.java | 80 -------------------
5 files changed, 82 insertions(+), 163 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0205fc92/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpRestServletResolveConsumerStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpRestServletResolveConsumerStrategy.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpRestServletResolveConsumerStrategy.java
new file mode 100644
index 0000000..7fa07cd
--- /dev/null
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpRestServletResolveConsumerStrategy.java
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.http.common;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.camel.support.RestConsumerContextPathMatcher;
+
+/**
+ * A {@link org.apache.camel.http.common.HttpServletResolveConsumerStrategy} that supports the Rest DSL.
+ */
+public class HttpRestServletResolveConsumerStrategy extends HttpServletResolveConsumerStrategy {
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public HttpConsumer resolve(HttpServletRequest request, Map<String, HttpConsumer> consumers) {
+ HttpConsumer answer = null;
+
+ String path = request.getPathInfo();
+ if (path == null) {
+ return null;
+ }
+ String method = request.getMethod();
+ if (method == null) {
+ return null;
+ }
+
+ List<RestConsumerContextPathMatcher.ConsumerPath> paths = new ArrayList<RestConsumerContextPathMatcher.ConsumerPath>();
+ for (final Map.Entry<String, HttpConsumer> entry : consumers.entrySet()) {
+ paths.add(new RestConsumerContextPathMatcher.ConsumerPath<HttpConsumer>() {
+ @Override
+ public String getRestrictMethod() {
+ return entry.getValue().getEndpoint().getHttpMethodRestrict();
+ }
+
+ @Override
+ public String getConsumerPath() {
+ return entry.getValue().getPath();
+ }
+
+ @Override
+ public HttpConsumer getConsumer() {
+ return entry.getValue();
+ }
+ });
+ }
+
+ RestConsumerContextPathMatcher.ConsumerPath<HttpConsumer> best = RestConsumerContextPathMatcher.matchBestPath(method, path, paths);
+ if (best != null) {
+ answer = best.getConsumer();
+ }
+
+ if (answer == null) {
+ // fallback to default
+ answer = super.resolve(request, consumers);
+ }
+
+ return answer;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0205fc92/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 dafc0f7..0a6c454 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
@@ -46,6 +46,7 @@ import org.apache.camel.http.common.HttpCommonComponent;
import org.apache.camel.http.common.HttpCommonEndpoint;
import org.apache.camel.http.common.HttpConfiguration;
import org.apache.camel.http.common.HttpConsumer;
+import org.apache.camel.http.common.HttpRestServletResolveConsumerStrategy;
import org.apache.camel.http.common.UrlRewrite;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.spi.ManagementAgent;
@@ -1116,7 +1117,7 @@ public abstract class JettyHttpComponent extends HttpCommonComponent implements
context.addServlet(holder, "/*");
// use rest enabled resolver in case we use rest
- camelServlet.setServletResolveConsumerStrategy(new JettyRestServletResolveConsumerStrategy());
+ camelServlet.setServletResolveConsumerStrategy(new HttpRestServletResolveConsumerStrategy());
return camelServlet;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0205fc92/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
deleted file mode 100644
index 5f15266..0000000
--- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.jetty;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.camel.http.common.HttpConsumer;
-import org.apache.camel.http.common.HttpServletResolveConsumerStrategy;
-import org.apache.camel.support.RestConsumerContextPathMatcher;
-
-/**
- * A {@link org.apache.camel.http.common.HttpServletResolveConsumerStrategy} that supports the Rest DSL.
- */
-public class JettyRestServletResolveConsumerStrategy extends HttpServletResolveConsumerStrategy {
-
- @Override
- @SuppressWarnings("unchecked")
- public HttpConsumer resolve(HttpServletRequest request, Map<String, HttpConsumer> consumers) {
- HttpConsumer answer = null;
-
- String path = request.getPathInfo();
- if (path == null) {
- return null;
- }
- String method = request.getMethod();
- if (method == null) {
- return null;
- }
-
- List<RestConsumerContextPathMatcher.ConsumerPath> paths = new ArrayList<RestConsumerContextPathMatcher.ConsumerPath>();
- for (final Map.Entry<String, HttpConsumer> entry : consumers.entrySet()) {
- paths.add(new RestConsumerContextPathMatcher.ConsumerPath<HttpConsumer>() {
- @Override
- public String getRestrictMethod() {
- return entry.getValue().getEndpoint().getHttpMethodRestrict();
- }
-
- @Override
- public String getConsumerPath() {
- return entry.getValue().getPath();
- }
-
- @Override
- public HttpConsumer getConsumer() {
- return entry.getValue();
- }
- });
- }
-
- RestConsumerContextPathMatcher.ConsumerPath<HttpConsumer> best = RestConsumerContextPathMatcher.matchBestPath(method, path, paths);
- if (best != null) {
- answer = best.getConsumer();
- }
-
- if (answer == null) {
- // fallback to default
- answer = super.resolve(request, consumers);
- }
-
- return answer;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/0205fc92/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java
index 67fcc89..dee46e7 100644
--- a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java
+++ b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/CamelHttpTransportServlet.java
@@ -22,6 +22,7 @@ import javax.servlet.ServletException;
import org.apache.camel.converter.ObjectConverter;
import org.apache.camel.http.common.CamelServlet;
import org.apache.camel.http.common.HttpConsumer;
+import org.apache.camel.http.common.HttpRestServletResolveConsumerStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,7 +41,7 @@ public class CamelHttpTransportServlet extends CamelServlet {
super.init(config);
// use rest enabled resolver in case we use rest
- this.setServletResolveConsumerStrategy(new ServletRestServletResolveConsumerStrategy());
+ this.setServletResolveConsumerStrategy(new HttpRestServletResolveConsumerStrategy());
String ignore = config.getInitParameter("ignoreDuplicateServletName");
Boolean bool = ObjectConverter.toBoolean(ignore);
http://git-wip-us.apache.org/repos/asf/camel/blob/0205fc92/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java
deleted file mode 100644
index bb518b3..0000000
--- a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.servlet;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.camel.http.common.HttpConsumer;
-import org.apache.camel.http.common.HttpServletResolveConsumerStrategy;
-import org.apache.camel.support.RestConsumerContextPathMatcher;
-
-/**
- * A {@link org.apache.camel.http.common.HttpServletResolveConsumerStrategy} that supports the Rest DSL.
- */
-public class ServletRestServletResolveConsumerStrategy extends HttpServletResolveConsumerStrategy {
-
- @Override
- @SuppressWarnings("unchecked")
- public HttpConsumer resolve(HttpServletRequest request, Map<String, HttpConsumer> consumers) {
- HttpConsumer answer = null;
-
- String path = request.getPathInfo();
- if (path == null) {
- return null;
- }
- String method = request.getMethod();
- if (method == null) {
- return null;
- }
-
- List<RestConsumerContextPathMatcher.ConsumerPath> paths = new ArrayList<RestConsumerContextPathMatcher.ConsumerPath>();
- for (final Map.Entry<String, HttpConsumer> entry : consumers.entrySet()) {
- paths.add(new RestConsumerContextPathMatcher.ConsumerPath<HttpConsumer>() {
- @Override
- public String getRestrictMethod() {
- return entry.getValue().getEndpoint().getHttpMethodRestrict();
- }
-
- @Override
- public String getConsumerPath() {
- return entry.getValue().getPath();
- }
-
- @Override
- public HttpConsumer getConsumer() {
- return entry.getValue();
- }
- });
- }
-
- RestConsumerContextPathMatcher.ConsumerPath<HttpConsumer> best = RestConsumerContextPathMatcher.matchBestPath(method, path, paths);
- if (best != null) {
- answer = best.getConsumer();
- }
-
- if (answer == null) {
- // fallback to default
- answer = super.resolve(request, consumers);
- }
-
- return answer;
- }
-
-}
[5/5] camel git commit: CAMEL-9096: rest-dsl - Reuse logic for
matching best rest path to use
Posted by da...@apache.org.
CAMEL-9096: rest-dsl - Reuse logic for matching best rest path to use
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e36adb2f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e36adb2f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e36adb2f
Branch: refs/heads/master
Commit: e36adb2fd8dbfdc05deb43bc33618565a7f5ed15
Parents: abcd5df
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Aug 22 11:32:51 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Aug 22 11:32:51 2015 +0200
----------------------------------------------------------------------
.../apache/camel/support/RestConsumerContextPathMatcher.java | 7 +------
.../netty4/http/NettyHttpRestContextPathMatcherTest.java | 4 ----
2 files changed, 1 insertion(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e36adb2f/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java b/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
index 6d949a0..2cbbf9c 100644
--- a/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
+++ b/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
@@ -168,12 +168,7 @@ public final class RestConsumerContextPathMatcher {
return true;
}
- // always match OPTIONS as some REST clients uses that prior to calling the service
- if ("OPTIONS".equals(method)) {
- return true;
- }
-
- return restrict.toLowerCase(Locale.US).contains(method.toLowerCase(Locale.US));
+ return restrict.toLowerCase(Locale.ENGLISH).contains(method.toLowerCase(Locale.ENGLISH));
}
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/e36adb2f/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRestContextPathMatcherTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRestContextPathMatcherTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRestContextPathMatcherTest.java
index 06108d2..8fd2a7b 100644
--- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRestContextPathMatcherTest.java
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRestContextPathMatcherTest.java
@@ -17,16 +17,12 @@
package org.apache.camel.component.netty4.http;
import org.apache.camel.builder.RouteBuilder;
-import org.junit.Ignore;
import org.junit.Test;
import static org.apache.camel.Exchange.HTTP_METHOD;
-@Ignore
public class NettyHttpRestContextPathMatcherTest extends BaseNettyTest {
- // TODO: implement the logic for this in a better way
-
@Test
public void shouldReturnCustomResponseForOptions() throws Exception {
String response = template.requestBodyAndHeader("netty4-http:http://localhost:{{port}}/foo", "", HTTP_METHOD, "OPTIONS", String.class);
[3/5] camel git commit: CAMEL-9096: rest-dsl - Reuse logic for
matching best rest path to use
Posted by da...@apache.org.
CAMEL-9096: rest-dsl - Reuse logic for matching best rest path to use
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6d43390c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6d43390c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6d43390c
Branch: refs/heads/master
Commit: 6d43390c00ef057ea33869288dc045ccd1c4d7aa
Parents: f7d6de0
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Aug 21 13:51:11 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Aug 22 09:01:47 2015 +0200
----------------------------------------------------------------------
.../support/RestConsumerContextPathMatcher.java | 197 +++++++++++++++++++
...JettyRestServletResolveConsumerStrategy.java | 170 ++--------------
...rvletRestServletResolveConsumerStrategy.java | 172 ++--------------
3 files changed, 234 insertions(+), 305 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/6d43390c/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java b/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
new file mode 100644
index 0000000..ed49bac
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
@@ -0,0 +1,197 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.support;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+
+public final class RestConsumerContextPathMatcher {
+
+ public interface ConsumerPath<T> {
+
+ String getRestrictMethod();
+
+ String getConsumerPath();
+
+ T getConsumer();
+
+ }
+
+ public static ConsumerPath matchBestPath(String requestMethod, String requestPath, List<ConsumerPath> consumerPaths) {
+ ConsumerPath answer = null;
+
+ List<ConsumerPath> candidates = new ArrayList<ConsumerPath>();
+
+ // first match by http method
+ for (ConsumerPath entry : consumerPaths) {
+ if (matchRestMethod(requestMethod, entry.getRestrictMethod())) {
+ candidates.add(entry);
+ }
+ }
+
+ // then see if we got a direct match
+ Iterator<ConsumerPath> it = candidates.iterator();
+ while (it.hasNext()) {
+ ConsumerPath consumer = it.next();
+ if (matchRestPath(requestPath, consumer.getConsumerPath(), false)) {
+ answer = consumer;
+ break;
+ }
+ }
+
+ // then match by wildcard path
+ if (answer == null) {
+ it = candidates.iterator();
+ while (it.hasNext()) {
+ ConsumerPath consumer = it.next();
+ // filter non matching paths
+ if (!matchRestPath(requestPath, consumer.getConsumerPath(), true)) {
+ it.remove();
+ }
+ }
+
+ // if there is multiple candidates with wildcards then pick anyone with the least number of wildcards
+ int bestWildcard = Integer.MAX_VALUE;
+ ConsumerPath best = null;
+ if (candidates.size() > 1) {
+ it = candidates.iterator();
+ while (it.hasNext()) {
+ ConsumerPath entry = it.next();
+ int wildcards = countWildcards(entry.getConsumerPath());
+ if (wildcards > 0) {
+ if (best == null || wildcards < bestWildcard) {
+ best = entry;
+ bestWildcard = wildcards;
+ }
+ }
+ }
+
+ if (best != null) {
+ // pick the best among the wildcards
+ answer = best;
+ }
+ }
+
+ // if there is one left then its our answer
+ if (answer == null && candidates.size() == 1) {
+ answer = candidates.get(0);
+ }
+ }
+
+ return answer;
+ }
+
+ /**
+ * Matches the given request HTTP method with the configured HTTP method of the consumer
+ *
+ * @param method the request HTTP method
+ * @param restrict the consumer configured HTTP restrict method
+ * @return <tt>true</tt> if matched, <tt>false</tt> otherwise
+ */
+ private static boolean matchRestMethod(String method, String restrict) {
+ if (restrict == null) {
+ return true;
+ }
+
+ // always match OPTIONS as some REST clients uses that prior to calling the service
+ if ("OPTIONS".equals(method)) {
+ return true;
+ }
+
+ return restrict.toLowerCase(Locale.US).contains(method.toLowerCase(Locale.US));
+ }
+
+ /**
+ * Matches the given request path with the configured consumer path
+ *
+ * @param requestPath the request path
+ * @param consumerPath the consumer path which may use { } tokens
+ * @return <tt>true</tt> if matched, <tt>false</tt> otherwise
+ */
+ private static boolean matchRestPath(String requestPath, String consumerPath, boolean wildcard) {
+ // remove starting/ending slashes
+ if (requestPath.startsWith("/")) {
+ requestPath = requestPath.substring(1);
+ }
+ if (requestPath.endsWith("/")) {
+ requestPath = requestPath.substring(0, requestPath.length() - 1);
+ }
+ // remove starting/ending slashes
+ if (consumerPath.startsWith("/")) {
+ consumerPath = consumerPath.substring(1);
+ }
+ if (consumerPath.endsWith("/")) {
+ consumerPath = consumerPath.substring(0, consumerPath.length() - 1);
+ }
+
+ // split using single char / is optimized in the jdk
+ String[] requestPaths = requestPath.split("/");
+ String[] consumerPaths = consumerPath.split("/");
+
+ // must be same number of path's
+ if (requestPaths.length != consumerPaths.length) {
+ return false;
+ }
+
+ for (int i = 0; i < requestPaths.length; i++) {
+ String p1 = requestPaths[i];
+ String p2 = consumerPaths[i];
+
+ if (wildcard && p2.startsWith("{") && p2.endsWith("}")) {
+ // always matches
+ continue;
+ }
+
+ if (!p1.equals(p2)) {
+ return false;
+ }
+ }
+
+ // assume matching
+ return true;
+ }
+
+ /**
+ * Counts the number of wildcards in the path
+ *
+ * @param consumerPath the consumer path which may use { } tokens
+ * @return number of wildcards, or <tt>0</tt> if no wildcards
+ */
+ private static int countWildcards(String consumerPath) {
+ int wildcards = 0;
+
+ // remove starting/ending slashes
+ if (consumerPath.startsWith("/")) {
+ consumerPath = consumerPath.substring(1);
+ }
+ if (consumerPath.endsWith("/")) {
+ consumerPath = consumerPath.substring(0, consumerPath.length() - 1);
+ }
+
+ String[] consumerPaths = consumerPath.split("/");
+ for (String p2 : consumerPaths) {
+ if (p2.startsWith("{") && p2.endsWith("}")) {
+ wildcards++;
+ }
+ }
+
+ return wildcards;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6d43390c/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
index b49debb..21c26c3 100644
--- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
+++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
@@ -17,14 +17,13 @@
package org.apache.camel.component.jetty;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.camel.http.common.HttpConsumer;
import org.apache.camel.http.common.HttpServletResolveConsumerStrategy;
+import org.apache.camel.support.RestConsumerContextPathMatcher;
/**
* A {@link org.apache.camel.http.common.HttpServletResolveConsumerStrategy} that supports the Rest DSL.
@@ -44,66 +43,29 @@ public class JettyRestServletResolveConsumerStrategy extends HttpServletResolveC
return null;
}
- List<HttpConsumer> candidates = new ArrayList<HttpConsumer>();
-
- // first match by http method
- for (Map.Entry<String, HttpConsumer> entry : consumers.entrySet()) {
- String restrict = entry.getValue().getEndpoint().getHttpMethodRestrict();
- if (matchRestMethod(method, restrict)) {
- candidates.add(entry.getValue());
- }
- }
-
- // then see if we got a direct match
- Iterator<HttpConsumer> it = candidates.iterator();
- while (it.hasNext()) {
- HttpConsumer consumer = it.next();
- String consumerPath = consumer.getPath();
- if (matchRestPath(path, consumerPath, false)) {
- answer = consumer;
- break;
- }
- }
-
- // then match by wildcard path
- if (answer == null) {
- it = candidates.iterator();
- while (it.hasNext()) {
- HttpConsumer consumer = it.next();
- String consumerPath = consumer.getPath();
- // filter non matching paths
- if (!matchRestPath(path, consumerPath, true)) {
- it.remove();
+ List<RestConsumerContextPathMatcher.ConsumerPath> paths = new ArrayList<RestConsumerContextPathMatcher.ConsumerPath>();
+ for (final Map.Entry<String, HttpConsumer> entry : consumers.entrySet()) {
+ paths.add(new RestConsumerContextPathMatcher.ConsumerPath<HttpConsumer>() {
+ @Override
+ public String getRestrictMethod() {
+ return entry.getValue().getEndpoint().getHttpMethodRestrict();
}
- }
- // if there is multiple candidates with wildcards then pick anyone with the least number of wildcards
- int bestWildcard = Integer.MAX_VALUE;
- HttpConsumer best = null;
- if (candidates.size() > 1) {
- it = candidates.iterator();
- while (it.hasNext()) {
- HttpConsumer entry = it.next();
- String consumerPath = entry.getPath();
- int wildcards = countWildcards(consumerPath);
- if (wildcards > 0) {
- if (best == null || wildcards < bestWildcard) {
- best = entry;
- bestWildcard = wildcards;
- }
- }
+ @Override
+ public String getConsumerPath() {
+ return entry.getValue().getPath();
}
- if (best != null) {
- // pick the best among the wildcards
- answer = best;
+ @Override
+ public HttpConsumer getConsumer() {
+ return entry.getValue();
}
- }
+ });
+ }
- // if there is one left then its our answer
- if (answer == null && candidates.size() == 1) {
- answer = candidates.get(0);
- }
+ RestConsumerContextPathMatcher.ConsumerPath<HttpConsumer> best = RestConsumerContextPathMatcher.matchBestPath(method, path, paths);
+ if (best != null) {
+ answer = best.getConsumer();
}
if (answer == null) {
@@ -114,101 +76,5 @@ public class JettyRestServletResolveConsumerStrategy extends HttpServletResolveC
return answer;
}
- /**
- * Matches the given request path with the configured consumer path
- *
- * @param requestPath the request path
- * @param consumerPath the consumer path which may use { } tokens
- * @return <tt>true</tt> if matched, <tt>false</tt> otherwise
- */
- public boolean matchRestPath(String requestPath, String consumerPath, boolean wildcard) {
- // remove starting/ending slashes
- if (requestPath.startsWith("/")) {
- requestPath = requestPath.substring(1);
- }
- if (requestPath.endsWith("/")) {
- requestPath = requestPath.substring(0, requestPath.length() - 1);
- }
- // remove starting/ending slashes
- if (consumerPath.startsWith("/")) {
- consumerPath = consumerPath.substring(1);
- }
- if (consumerPath.endsWith("/")) {
- consumerPath = consumerPath.substring(0, consumerPath.length() - 1);
- }
-
- // split using single char / is optimized in the jdk
- String[] requestPaths = requestPath.split("/");
- String[] consumerPaths = consumerPath.split("/");
-
- // must be same number of path's
- if (requestPaths.length != consumerPaths.length) {
- return false;
- }
-
- for (int i = 0; i < requestPaths.length; i++) {
- String p1 = requestPaths[i];
- String p2 = consumerPaths[i];
-
- if (wildcard && p2.startsWith("{") && p2.endsWith("}")) {
- // always matches
- continue;
- }
-
- if (!p1.equals(p2)) {
- return false;
- }
- }
-
- // assume matching
- return true;
- }
-
- /**
- * Counts the number of wildcards in the path
- *
- * @param consumerPath the consumer path which may use { } tokens
- * @return number of wildcards, or <tt>0</tt> if no wildcards
- */
- public int countWildcards(String consumerPath) {
- int wildcards = 0;
-
- // remove starting/ending slashes
- if (consumerPath.startsWith("/")) {
- consumerPath = consumerPath.substring(1);
- }
- if (consumerPath.endsWith("/")) {
- consumerPath = consumerPath.substring(0, consumerPath.length() - 1);
- }
-
- String[] consumerPaths = consumerPath.split("/");
- for (String p2 : consumerPaths) {
- if (p2.startsWith("{") && p2.endsWith("}")) {
- wildcards++;
- }
- }
-
- return wildcards;
- }
-
- /**
- * Matches the given request HTTP method with the configured HTTP method of the consumer
- *
- * @param method the request HTTP method
- * @param restrict the consumer configured HTTP restrict method
- * @return <tt>true</tt> if matched, <tt>false</tt> otherwise
- */
- public boolean matchRestMethod(String method, String restrict) {
- if (restrict == null) {
- return true;
- }
-
- // always match OPTIONS as some REST clients uses that prior to calling the service
- if ("OPTIONS".equals(method)) {
- return true;
- }
-
- return restrict.toLowerCase(Locale.US).contains(method.toLowerCase(Locale.US));
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6d43390c/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java
index 71e3f96..bb518b3 100644
--- a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java
+++ b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletRestServletResolveConsumerStrategy.java
@@ -17,14 +17,13 @@
package org.apache.camel.component.servlet;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.camel.http.common.HttpConsumer;
import org.apache.camel.http.common.HttpServletResolveConsumerStrategy;
+import org.apache.camel.support.RestConsumerContextPathMatcher;
/**
* A {@link org.apache.camel.http.common.HttpServletResolveConsumerStrategy} that supports the Rest DSL.
@@ -32,6 +31,7 @@ import org.apache.camel.http.common.HttpServletResolveConsumerStrategy;
public class ServletRestServletResolveConsumerStrategy extends HttpServletResolveConsumerStrategy {
@Override
+ @SuppressWarnings("unchecked")
public HttpConsumer resolve(HttpServletRequest request, Map<String, HttpConsumer> consumers) {
HttpConsumer answer = null;
@@ -44,66 +44,29 @@ public class ServletRestServletResolveConsumerStrategy extends HttpServletResolv
return null;
}
- List<HttpConsumer> candidates = new ArrayList<HttpConsumer>();
-
- // first match by http method
- for (Map.Entry<String, HttpConsumer> entry : consumers.entrySet()) {
- String restrict = entry.getValue().getEndpoint().getHttpMethodRestrict();
- if (matchRestMethod(method, restrict)) {
- candidates.add(entry.getValue());
- }
- }
-
- // then see if we got a direct match
- Iterator<HttpConsumer> it = candidates.iterator();
- while (it.hasNext()) {
- HttpConsumer consumer = it.next();
- String consumerPath = consumer.getPath();
- if (matchRestPath(path, consumerPath, false)) {
- answer = consumer;
- break;
- }
- }
-
- // then match by wildcard path
- if (answer == null) {
- it = candidates.iterator();
- while (it.hasNext()) {
- HttpConsumer consumer = it.next();
- String consumerPath = consumer.getPath();
- // filter non matching paths
- if (!matchRestPath(path, consumerPath, true)) {
- it.remove();
+ List<RestConsumerContextPathMatcher.ConsumerPath> paths = new ArrayList<RestConsumerContextPathMatcher.ConsumerPath>();
+ for (final Map.Entry<String, HttpConsumer> entry : consumers.entrySet()) {
+ paths.add(new RestConsumerContextPathMatcher.ConsumerPath<HttpConsumer>() {
+ @Override
+ public String getRestrictMethod() {
+ return entry.getValue().getEndpoint().getHttpMethodRestrict();
}
- }
- // if there is multiple candidates with wildcards then pick anyone with the least number of wildcards
- int bestWildcard = Integer.MAX_VALUE;
- HttpConsumer best = null;
- if (candidates.size() > 1) {
- it = candidates.iterator();
- while (it.hasNext()) {
- HttpConsumer entry = it.next();
- String consumerPath = entry.getPath();
- int wildcards = countWildcards(consumerPath);
- if (wildcards > 0) {
- if (best == null || wildcards < bestWildcard) {
- best = entry;
- bestWildcard = wildcards;
- }
- }
+ @Override
+ public String getConsumerPath() {
+ return entry.getValue().getPath();
}
- if (best != null) {
- // pick the best among the wildcards
- answer = best;
+ @Override
+ public HttpConsumer getConsumer() {
+ return entry.getValue();
}
- }
+ });
+ }
- // if there is one left then its our answer
- if (answer == null && candidates.size() == 1) {
- answer = candidates.get(0);
- }
+ RestConsumerContextPathMatcher.ConsumerPath<HttpConsumer> best = RestConsumerContextPathMatcher.matchBestPath(method, path, paths);
+ if (best != null) {
+ answer = best.getConsumer();
}
if (answer == null) {
@@ -114,101 +77,4 @@ public class ServletRestServletResolveConsumerStrategy extends HttpServletResolv
return answer;
}
- /**
- * Matches the given request path with the configured consumer path
- *
- * @param requestPath the request path
- * @param consumerPath the consumer path which may use { } tokens
- * @return <tt>true</tt> if matched, <tt>false</tt> otherwise
- */
- public boolean matchRestPath(String requestPath, String consumerPath, boolean wildcard) {
- // remove starting/ending slashes
- if (requestPath.startsWith("/")) {
- requestPath = requestPath.substring(1);
- }
- if (requestPath.endsWith("/")) {
- requestPath = requestPath.substring(0, requestPath.length() - 1);
- }
- // remove starting/ending slashes
- if (consumerPath.startsWith("/")) {
- consumerPath = consumerPath.substring(1);
- }
- if (consumerPath.endsWith("/")) {
- consumerPath = consumerPath.substring(0, consumerPath.length() - 1);
- }
-
- // split using single char / is optimized in the jdk
- String[] requestPaths = requestPath.split("/");
- String[] consumerPaths = consumerPath.split("/");
-
- // must be same number of path's
- if (requestPaths.length != consumerPaths.length) {
- return false;
- }
-
- for (int i = 0; i < requestPaths.length; i++) {
- String p1 = requestPaths[i];
- String p2 = consumerPaths[i];
-
- if (wildcard && p2.startsWith("{") && p2.endsWith("}")) {
- // always matches
- continue;
- }
-
- if (!p1.equals(p2)) {
- return false;
- }
- }
-
- // assume matching
- return true;
- }
-
- /**
- * Counts the number of wildcards in the path
- *
- * @param consumerPath the consumer path which may use { } tokens
- * @return number of wildcards, or <tt>0</tt> if no wildcards
- */
- public int countWildcards(String consumerPath) {
- int wildcards = 0;
-
- // remove starting/ending slashes
- if (consumerPath.startsWith("/")) {
- consumerPath = consumerPath.substring(1);
- }
- if (consumerPath.endsWith("/")) {
- consumerPath = consumerPath.substring(0, consumerPath.length() - 1);
- }
-
- String[] consumerPaths = consumerPath.split("/");
- for (String p2 : consumerPaths) {
- if (p2.startsWith("{") && p2.endsWith("}")) {
- wildcards++;
- }
- }
-
- return wildcards;
- }
-
- /**
- * Matches the given request HTTP method with the configured HTTP method of the consumer
- *
- * @param method the request HTTP method
- * @param restrict the consumer configured HTTP restrict method
- * @return <tt>true</tt> if matched, <tt>false</tt> otherwise
- */
- public boolean matchRestMethod(String method, String restrict) {
- if (restrict == null) {
- return true;
- }
-
- // always match OPTIONS as some REST clients uses that prior to calling the service
- if ("OPTIONS".equals(method)) {
- return true;
- }
-
- return restrict.toLowerCase(Locale.US).contains(method.toLowerCase(Locale.US));
- }
-
}
[4/5] camel git commit: CAMEL-9096: rest-dsl - Reuse logic for
matching best rest path to use
Posted by da...@apache.org.
CAMEL-9096: rest-dsl - Reuse logic for matching best rest path to use
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/abcd5dfe
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/abcd5dfe
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/abcd5dfe
Branch: refs/heads/master
Commit: abcd5dfee034792bb740b5d5a18a77232add7619
Parents: 0205fc9
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Aug 22 09:01:38 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Aug 22 09:01:48 2015 +0200
----------------------------------------------------------------------
.../support/RestConsumerContextPathMatcher.java | 49 +++++-
.../HttpServletResolveConsumerStrategy.java | 6 +-
.../component/jetty/JettyHandle404Test.java | 1 +
...tpProducerBridgePathWithSpacesAtEndTest.java | 54 ------
.../http/handlers/HttpServerChannelHandler.java | 1 +
.../HttpServerMultiplexChannelHandler.java | 168 ++++---------------
...tpProducerBridgePathWithSpacesAtEndTest.java | 54 ------
.../NettyHttpRestContextPathMatcherTest.java | 4 +
8 files changed, 86 insertions(+), 251 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/abcd5dfe/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java b/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
index b709680..6d949a0 100644
--- a/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
+++ b/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
@@ -54,11 +54,42 @@ public final class RestConsumerContextPathMatcher {
}
/**
+ * Does the incoming request match the given consumer path (ignore case)
+ *
+ * @param requestPath the incoming request context path
+ * @param consumerPath a consumer path
+ * @param matchOnUriPrefix whether to use the matchOnPrefix option
+ * @return <tt>true</tt> if matched, <tt>false</tt> otherwise
+ */
+ public static boolean matchPath(String requestPath, String consumerPath, boolean matchOnUriPrefix) {
+ // deal with null parameters
+ if (requestPath == null && consumerPath == null) {
+ return true;
+ }
+ if (requestPath == null || consumerPath == null) {
+ return false;
+ }
+
+ String p1 = requestPath.toLowerCase(Locale.ENGLISH);
+ String p2 = consumerPath.toLowerCase(Locale.ENGLISH);
+
+ if (p1.equals(p2)) {
+ return true;
+ }
+
+ if (matchOnUriPrefix && p1.startsWith(p2)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
* Finds the best matching of the list of consumer paths that should service the incoming request.
*
- * @param requestMethod the incoming request HTTP method
- * @param requestPath the incoming request context path
- * @param consumerPaths the list of consumer context path details
+ * @param requestMethod the incoming request HTTP method
+ * @param requestPath the incoming request context path
+ * @param consumerPaths the list of consumer context path details
* @return the best matched consumer, or <tt>null</tt> if none could be determined.
*/
public static ConsumerPath matchBestPath(String requestMethod, String requestPath, List<ConsumerPath> consumerPaths) {
@@ -128,8 +159,8 @@ public final class RestConsumerContextPathMatcher {
/**
* Matches the given request HTTP method with the configured HTTP method of the consumer
*
- * @param method the request HTTP method
- * @param restrict the consumer configured HTTP restrict method
+ * @param method the request HTTP method
+ * @param restrict the consumer configured HTTP restrict method
* @return <tt>true</tt> if matched, <tt>false</tt> otherwise
*/
private static boolean matchRestMethod(String method, String restrict) {
@@ -148,8 +179,8 @@ public final class RestConsumerContextPathMatcher {
/**
* Matches the given request path with the configured consumer path
*
- * @param requestPath the request path
- * @param consumerPath the consumer path which may use { } tokens
+ * @param requestPath the request path
+ * @param consumerPath the consumer path which may use { } tokens
* @return <tt>true</tt> if matched, <tt>false</tt> otherwise
*/
private static boolean matchRestPath(String requestPath, String consumerPath, boolean wildcard) {
@@ -186,7 +217,7 @@ public final class RestConsumerContextPathMatcher {
continue;
}
- if (!p1.equals(p2)) {
+ if (!matchPath(p1, p2, false)) {
return false;
}
}
@@ -198,7 +229,7 @@ public final class RestConsumerContextPathMatcher {
/**
* Counts the number of wildcards in the path
*
- * @param consumerPath the consumer path which may use { } tokens
+ * @param consumerPath the consumer path which may use { } tokens
* @return number of wildcards, or <tt>0</tt> if no wildcards
*/
private static int countWildcards(String consumerPath) {
http://git-wip-us.apache.org/repos/asf/camel/blob/abcd5dfe/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpServletResolveConsumerStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpServletResolveConsumerStrategy.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpServletResolveConsumerStrategy.java
index a48f4b6..027aca1 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpServletResolveConsumerStrategy.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpServletResolveConsumerStrategy.java
@@ -19,6 +19,8 @@ package org.apache.camel.http.common;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
+import org.apache.camel.support.RestConsumerContextPathMatcher;
+
/**
* A default implementation of {@link org.apache.camel.http.common.ServletResolveConsumerStrategy}.
*/
@@ -37,13 +39,15 @@ public class HttpServletResolveConsumerStrategy implements ServletResolveConsume
//We need to look up the consumer path here
String consumerPath = consumers.get(key).getPath();
HttpConsumer consumer = consumers.get(key);
+ boolean matchOnUriPrefix = consumer.getEndpoint().isMatchOnUriPrefix();
// Just make sure the we get the right consumer path first
- if (consumerPath.equals(path) || (consumer.getEndpoint().isMatchOnUriPrefix() && path.startsWith(consumerPath))) {
+ if (RestConsumerContextPathMatcher.matchPath(path, consumerPath, matchOnUriPrefix)) {
answer = consumers.get(key);
break;
}
}
}
+
return answer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/abcd5dfe/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java
index 7c5740c..0a8f407 100644
--- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java
+++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/JettyHandle404Test.java
@@ -50,6 +50,7 @@ public class JettyHandle404Test extends BaseJettyTest {
public void testCustomerErrorHandler() throws Exception {
String response = template.requestBody("http://localhost:{{port}}/myserver1?throwExceptionOnFailure=false", null, String.class);
// look for the error message which is sent by MyErrorHandler
+ log.info("Response: {}", response);
assertTrue("Get a wrong error message", response.indexOf("MyErrorHandler") > 0);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/abcd5dfe/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java
deleted file mode 100644
index 9baf2c8..0000000
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.netty.http;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.Test;
-
-public class NettyHttpProducerBridgePathWithSpacesAtEndTest extends BaseNettyTest {
-
- private int port1;
- private int port2;
-
- @Test
- public void testProxy() throws Exception {
- String reply = template.requestBody("netty-http:http://0.0.0.0:" + port1 + "/foo ", "World", String.class);
- assertEquals("Bye World", reply);
-
- // and with more spaces
- String reply2 = template.requestBody("netty-http:http://0.0.0.0:" + port1 + "/foo /bar baz", "Camel", String.class);
- assertEquals("Bye Camel", reply2);
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- port1 = getPort();
- port2 = getNextPort();
-
- from("netty-http:http://0.0.0.0:" + port1 + "/foo ?matchOnUriPrefix=true")
- .to("netty-http:http://0.0.0.0:" + port2 + "/proxy foo ?bridgeEndpoint=true&throwExceptionOnFailure=false");
-
- from("netty-http:http://0.0.0.0:" + port2 + "/proxy foo ?matchOnUriPrefix=true")
- .transform().simple("Bye ${body}");
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/abcd5dfe/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 4cb610f..d6dbf4a 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
@@ -52,6 +52,7 @@ import static io.netty.handler.codec.http.HttpResponseStatus.OK;
import static io.netty.handler.codec.http.HttpResponseStatus.SERVICE_UNAVAILABLE;
import static io.netty.handler.codec.http.HttpResponseStatus.UNAUTHORIZED;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
+
/**
* Netty HTTP {@link ServerChannelHandler} that handles the incoming HTTP requests and routes
* the received message in Camel.
http://git-wip-us.apache.org/repos/asf/camel/blob/abcd5dfe/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
index 30dae07..b000f5d 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
@@ -18,12 +18,9 @@ package org.apache.camel.component.netty4.http.handlers;
import java.nio.channels.ClosedChannelException;
import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandler.Sharable;
@@ -36,10 +33,9 @@ import io.netty.handler.codec.http.HttpResponse;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
import org.apache.camel.Exchange;
-import org.apache.camel.component.netty4.http.ContextPathMatcher;
import org.apache.camel.component.netty4.http.HttpServerConsumerChannelFactory;
import org.apache.camel.component.netty4.http.NettyHttpConsumer;
-import org.apache.camel.component.netty4.http.RestContextPathMatcher;
+import org.apache.camel.support.RestConsumerContextPathMatcher;
import org.apache.camel.util.UnsafeUriCharactersEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,7 +54,7 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl
// use NettyHttpConsumer as logger to make it easier to read the logs as this is part of the consumer
private static final Logger LOG = LoggerFactory.getLogger(NettyHttpConsumer.class);
private static final AttributeKey<HttpServerChannelHandler> SERVER_HANDLER_KEY = AttributeKey.valueOf("serverHandler");
- private final ConcurrentMap<ContextPathMatcher, HttpServerChannelHandler> consumers = new ConcurrentHashMap<ContextPathMatcher, HttpServerChannelHandler>();
+ private final Set<HttpServerChannelHandler> consumers = new CopyOnWriteArraySet<HttpServerChannelHandler>();
private int port;
private String token;
private int len;
@@ -74,19 +70,15 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl
}
public void addConsumer(NettyHttpConsumer consumer) {
- String rawPath = consumer.getConfiguration().getPath();
- String path = pathAsKey(consumer.getConfiguration().getPath());
- // use rest path matcher in case Rest DSL is in use
- ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getEndpoint().getHttpMethodRestrict(), consumer.getConfiguration().isMatchOnUriPrefix());
- consumers.put(matcher, new HttpServerChannelHandler(consumer));
+ consumers.add(new HttpServerChannelHandler(consumer));
}
public void removeConsumer(NettyHttpConsumer consumer) {
- String rawPath = consumer.getConfiguration().getPath();
- String path = pathAsKey(consumer.getConfiguration().getPath());
- // use rest path matcher in case Rest DSL is in use
- ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getEndpoint().getHttpMethodRestrict(), consumer.getConfiguration().isMatchOnUriPrefix());
- consumers.remove(matcher);
+ for (HttpServerChannelHandler handler : consumers) {
+ if (handler.getConsumer() == consumer) {
+ consumers.remove(handler);
+ }
+ }
}
public int consumers() {
@@ -153,6 +145,7 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl
}
}
+ @SuppressWarnings("unchecked")
private HttpServerChannelHandler getHandler(HttpRequest request) {
HttpServerChannelHandler answer = null;
@@ -170,81 +163,40 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl
// use the path as key to find the consumer handler to use
path = pathAsKey(path);
-
- List<Map.Entry<ContextPathMatcher, HttpServerChannelHandler>> candidates = new ArrayList<Map.Entry<ContextPathMatcher, HttpServerChannelHandler>>();
-
- // first match by http method
- for (Map.Entry<ContextPathMatcher, HttpServerChannelHandler> entry : consumers.entrySet()) {
- NettyHttpConsumer consumer = entry.getValue().getConsumer();
- String restrict = consumer.getEndpoint().getHttpMethodRestrict();
- if (entry.getKey().matchMethod(method, restrict)) {
- candidates.add(entry);
- }
- }
-
- // then see if we got a direct match
- List<HttpServerChannelHandler> directMatches = new LinkedList<HttpServerChannelHandler>();
- for (Map.Entry<ContextPathMatcher, HttpServerChannelHandler> entry : candidates) {
- if (entry.getKey().matchesRest(path, false)) {
- directMatches.add(entry.getValue());
- }
- }
- if (directMatches.size() == 1) { // Single match found, just return it without any further analysis.
- answer = directMatches.get(0);
- } else if (directMatches.size() > 1) { // possible if the prefix match occurred
- List<HttpServerChannelHandler> directMatchesWithOptions = handlersWithExplicitOptionsMethod(directMatches);
- if (!directMatchesWithOptions.isEmpty()) { // prefer options matches
- answer = handlerWithTheLongestMatchingPrefix(directMatchesWithOptions);
- } else {
- answer = handlerWithTheLongestMatchingPrefix(directMatches);
- }
- }
-
- // then match by wildcard path
- if (answer == null) {
- Iterator<Map.Entry<ContextPathMatcher, HttpServerChannelHandler>> it = candidates.iterator();
- while (it.hasNext()) {
- Map.Entry<ContextPathMatcher, HttpServerChannelHandler> entry = it.next();
- // filter non matching paths
- if (!entry.getKey().matchesRest(path, true)) {
- it.remove();
+ List<RestConsumerContextPathMatcher.ConsumerPath> paths = new ArrayList<RestConsumerContextPathMatcher.ConsumerPath>();
+ for (final HttpServerChannelHandler handler : consumers) {
+ paths.add(new RestConsumerContextPathMatcher.ConsumerPath<HttpServerChannelHandler>() {
+ @Override
+ public String getRestrictMethod() {
+ return handler.getConsumer().getEndpoint().getHttpMethodRestrict();
}
- }
- // if there is multiple candidates with wildcards then pick anyone with the least number of wildcards
- int bestWildcard = Integer.MAX_VALUE;
- Map.Entry<ContextPathMatcher, HttpServerChannelHandler> best = null;
- if (candidates.size() > 1) {
- it = candidates.iterator();
- while (it.hasNext()) {
- Map.Entry<ContextPathMatcher, HttpServerChannelHandler> entry = it.next();
- String consumerPath = entry.getValue().getConsumer().getConfiguration().getPath();
- int wildcards = countWildcards(consumerPath);
- if (wildcards > 0) {
- if (best == null || wildcards < bestWildcard) {
- best = entry;
- bestWildcard = wildcards;
- }
- }
+ @Override
+ public String getConsumerPath() {
+ return handler.getConsumer().getConfiguration().getPath();
}
- if (best != null) {
- // pick the best among the wildcards
- answer = best.getValue();
+ @Override
+ public HttpServerChannelHandler getConsumer() {
+ return handler;
}
- }
+ });
+ }
- // if there is one left then its our answer
- if (answer == null && candidates.size() == 1) {
- answer = candidates.get(0).getValue();
- }
+ RestConsumerContextPathMatcher.ConsumerPath<HttpServerChannelHandler> best = RestConsumerContextPathMatcher.matchBestPath(method, path, paths);
+ if (best != null) {
+ answer = best.getConsumer();
}
// fallback to regular matching
if (answer == null) {
- for (Map.Entry<ContextPathMatcher, HttpServerChannelHandler> entry : consumers.entrySet()) {
- if (entry.getKey().matches(path)) {
- answer = entry.getValue();
+ for (final HttpServerChannelHandler handler : consumers) {
+ NettyHttpConsumer consumer = handler.getConsumer();
+ String consumerPath = consumer.getConfiguration().getPath();
+ boolean matchOnUriPrefix = consumer.getEndpoint().getConfiguration().isMatchOnUriPrefix();
+ // Just make sure the we get the right consumer path first
+ if (RestConsumerContextPathMatcher.matchPath(path, consumerPath, matchOnUriPrefix)) {
+ answer = handler;
break;
}
}
@@ -253,33 +205,6 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl
return answer;
}
- /**
- * Counts the number of wildcards in the path
- *
- * @param consumerPath the consumer path which may use { } tokens
- * @return number of wildcards, or <tt>0</tt> if no wildcards
- */
- private static int countWildcards(String consumerPath) {
- int wildcards = 0;
-
- // remove starting/ending slashes
- if (consumerPath.startsWith("/")) {
- consumerPath = consumerPath.substring(1);
- }
- if (consumerPath.endsWith("/")) {
- consumerPath = consumerPath.substring(0, consumerPath.length() - 1);
- }
-
- String[] consumerPaths = consumerPath.split("/");
- for (String p2 : consumerPaths) {
- if (p2.startsWith("{") && p2.endsWith("}")) {
- wildcards++;
- }
- }
-
- return wildcards;
- }
-
private static String pathAsKey(String path) {
// cater for default path
if (path == null || path.equals("/")) {
@@ -300,27 +225,4 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl
return UnsafeUriCharactersEncoder.encodeHttpURI(path);
}
- private static List<HttpServerChannelHandler> handlersWithExplicitOptionsMethod(Iterable<HttpServerChannelHandler> handlers) {
- List<HttpServerChannelHandler> handlersWithOptions = new LinkedList<HttpServerChannelHandler>();
- for (HttpServerChannelHandler handler : handlers) {
- String consumerMethod = handler.getConsumer().getEndpoint().getHttpMethodRestrict();
- if (consumerMethod != null && consumerMethod.contains("OPTIONS")) {
- handlersWithOptions.add(handler);
- }
- }
- return handlersWithOptions;
- }
-
- private static HttpServerChannelHandler handlerWithTheLongestMatchingPrefix(Iterable<HttpServerChannelHandler> handlers) {
- HttpServerChannelHandler handlerWithTheLongestPrefix = handlers.iterator().next();
- for (HttpServerChannelHandler handler : handlers) {
- String consumerPath = handler.getConsumer().getConfiguration().getPath();
- String longestPath = handlerWithTheLongestPrefix.getConsumer().getConfiguration().getPath();
- if (consumerPath.length() > longestPath.length()) {
- handlerWithTheLongestPrefix = handler;
- }
- }
- return handlerWithTheLongestPrefix;
- }
-
}
http://git-wip-us.apache.org/repos/asf/camel/blob/abcd5dfe/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java
deleted file mode 100644
index dfdbc23..0000000
--- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpProducerBridgePathWithSpacesAtEndTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.netty4.http;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.Test;
-
-public class NettyHttpProducerBridgePathWithSpacesAtEndTest extends BaseNettyTest {
-
- private int port1;
- private int port2;
-
- @Test
- public void testProxy() throws Exception {
- String reply = template.requestBody("netty4-http:http://0.0.0.0:" + port1 + "/foo ", "World", String.class);
- assertEquals("Bye World", reply);
-
- // and with more spaces
- String reply2 = template.requestBody("netty4-http:http://0.0.0.0:" + port1 + "/foo /bar baz", "Camel", String.class);
- assertEquals("Bye Camel", reply2);
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- port1 = getPort();
- port2 = getNextPort();
-
- from("netty4-http:http://0.0.0.0:" + port1 + "/foo ?matchOnUriPrefix=true")
- .to("netty4-http:http://0.0.0.0:" + port2 + "/proxy foo ?bridgeEndpoint=true&throwExceptionOnFailure=false");
-
- from("netty4-http:http://0.0.0.0:" + port2 + "/proxy foo ?matchOnUriPrefix=true")
- .transform().simple("Bye ${body}");
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/abcd5dfe/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRestContextPathMatcherTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRestContextPathMatcherTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRestContextPathMatcherTest.java
index 8fd2a7b..06108d2 100644
--- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRestContextPathMatcherTest.java
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpRestContextPathMatcherTest.java
@@ -17,12 +17,16 @@
package org.apache.camel.component.netty4.http;
import org.apache.camel.builder.RouteBuilder;
+import org.junit.Ignore;
import org.junit.Test;
import static org.apache.camel.Exchange.HTTP_METHOD;
+@Ignore
public class NettyHttpRestContextPathMatcherTest extends BaseNettyTest {
+ // TODO: implement the logic for this in a better way
+
@Test
public void shouldReturnCustomResponseForOptions() throws Exception {
String response = template.requestBodyAndHeader("netty4-http:http://localhost:{{port}}/foo", "", HTTP_METHOD, "OPTIONS", String.class);
[2/5] camel git commit: CAMEL-9096: rest-dsl - Reuse logic for
matching best rest path to use
Posted by da...@apache.org.
CAMEL-9096: rest-dsl - Reuse logic for matching best rest path to use
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f5aa83c7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f5aa83c7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f5aa83c7
Branch: refs/heads/master
Commit: f5aa83c78ed11ec31a6faa5b2d1502ac981f4ede
Parents: 6d43390
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Aug 21 14:03:29 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Aug 22 09:01:47 2015 +0200
----------------------------------------------------------------------
.../support/RestConsumerContextPathMatcher.java | 28 +++++++
...JettyRestServletResolveConsumerStrategy.java | 1 +
.../jetty/rest/RestPathMatchingTest.java | 85 --------------------
3 files changed, 29 insertions(+), 85 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f5aa83c7/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java b/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
index ed49bac..b709680 100644
--- a/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
+++ b/camel-core/src/main/java/org/apache/camel/support/RestConsumerContextPathMatcher.java
@@ -21,18 +21,46 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+/**
+ * A context path matcher when using rest-dsl that allows components to reuse the same matching logic.
+ * <p/>
+ * The component should use the {@link #matchBestPath(String, String, java.util.List)} with the request details
+ * and the matcher returns the best matched, or <tt>null</tt> if none could be determined.
+ * <p/>
+ * The {@link ConsumerPath} is used for the components to provide the details to the matcher.
+ */
public final class RestConsumerContextPathMatcher {
+ /**
+ * Consumer path details which must be implemented and provided by the components.
+ */
public interface ConsumerPath<T> {
+ /**
+ * Any HTTP restrict method that would not be allowed
+ */
String getRestrictMethod();
+ /**
+ * The consumer context-path which may include wildcards
+ */
String getConsumerPath();
+ /**
+ * The consumer implementation
+ */
T getConsumer();
}
+ /**
+ * Finds the best matching of the list of consumer paths that should service the incoming request.
+ *
+ * @param requestMethod the incoming request HTTP method
+ * @param requestPath the incoming request context path
+ * @param consumerPaths the list of consumer context path details
+ * @return the best matched consumer, or <tt>null</tt> if none could be determined.
+ */
public static ConsumerPath matchBestPath(String requestMethod, String requestPath, List<ConsumerPath> consumerPaths) {
ConsumerPath answer = null;
http://git-wip-us.apache.org/repos/asf/camel/blob/f5aa83c7/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
index 21c26c3..5f15266 100644
--- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
+++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestServletResolveConsumerStrategy.java
@@ -31,6 +31,7 @@ import org.apache.camel.support.RestConsumerContextPathMatcher;
public class JettyRestServletResolveConsumerStrategy extends HttpServletResolveConsumerStrategy {
@Override
+ @SuppressWarnings("unchecked")
public HttpConsumer resolve(HttpServletRequest request, Map<String, HttpConsumer> consumers) {
HttpConsumer answer = null;
http://git-wip-us.apache.org/repos/asf/camel/blob/f5aa83c7/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestPathMatchingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestPathMatchingTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestPathMatchingTest.java
deleted file mode 100644
index 5e0d726..0000000
--- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestPathMatchingTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.jetty.rest;
-
-import junit.framework.TestCase;
-import org.apache.camel.component.jetty.JettyRestServletResolveConsumerStrategy;
-
-public class RestPathMatchingTest extends TestCase {
-
- private JettyRestServletResolveConsumerStrategy matcher = new JettyRestServletResolveConsumerStrategy();
-
- public void testRestPathMatcher() throws Exception {
- assertTrue(matcher.matchRestPath("/foo/", "/foo/", true));
- assertTrue(matcher.matchRestPath("/foo/", "foo/", true));
- assertTrue(matcher.matchRestPath("/foo/", "foo", true));
- assertTrue(matcher.matchRestPath("foo/", "foo", true));
- assertTrue(matcher.matchRestPath("foo", "foo", true));
- assertTrue(matcher.matchRestPath("foo/", "foo", true));
- assertTrue(matcher.matchRestPath("/foo/", "foo", true));
-
- assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014", true));
- assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014", true));
- assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014/", true));
- assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014/", true));
- assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/{year}", true));
-
- assertFalse(matcher.matchRestPath("/foo/", "/bar/", true));
- assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015", true));
- assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015", true));
- assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015/", true));
- assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015/", true));
- assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/", true));
-
- assertTrue(matcher.matchRestPath("/foo/1/list/2", "/foo/{user}/list/{year}", true));
- assertTrue(matcher.matchRestPath("/foo/1234567890/list/2", "/foo/{user}/list/{year}", true));
- assertTrue(matcher.matchRestPath("/foo/1234567890/list/1234567890", "/foo/{user}/list/{year}", true));
-
- assertTrue(matcher.matchRestPath("/123/list/2014", "/{user}/list/{year}", true));
- assertTrue(matcher.matchRestPath("/1234567890/list/2014", "/{user}/list/{year}", true));
- }
-
- public void testRestPathMatcherNoWildcard() throws Exception {
- assertTrue(matcher.matchRestPath("/foo/", "/foo/", false));
- assertTrue(matcher.matchRestPath("/foo/", "foo/", false));
- assertTrue(matcher.matchRestPath("/foo/", "foo", false));
- assertTrue(matcher.matchRestPath("foo/", "foo", false));
- assertTrue(matcher.matchRestPath("foo", "foo", false));
- assertTrue(matcher.matchRestPath("foo/", "foo", false));
- assertTrue(matcher.matchRestPath("/foo/", "foo", false));
-
- assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014", false));
- assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014", false));
- assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2014/", false));
- assertTrue(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2014/", false));
- assertTrue(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/{year}", true));
-
- assertFalse(matcher.matchRestPath("/foo/", "/bar/", false));
- assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015", false));
- assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015", false));
- assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/1234/list/2015/", false));
- assertFalse(matcher.matchRestPath("/foo/1234/list/2014/", "/foo/1234/list/2015/", false));
- assertFalse(matcher.matchRestPath("/foo/1234/list/2014", "/foo/{user}/list/", false));
-
- assertFalse(matcher.matchRestPath("/foo/1/list/2", "/foo/{user}/list/{year}", false));
- assertFalse(matcher.matchRestPath("/foo/1234567890/list/2", "/foo/{user}/list/{year}", false));
- assertFalse(matcher.matchRestPath("/foo/1234567890/list/1234567890", "/foo/{user}/list/{year}", false));
-
- assertFalse(matcher.matchRestPath("/123/list/2014", "/{user}/list/{year}", false));
- assertFalse(matcher.matchRestPath("/1234567890/list/2014", "/{user}/list/{year}", false));
- }
-}