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:23:00 UTC
[2/5] camel git commit: CAMEL-9096: rest-dsl - Reuse logic for
matching best rest path to use
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));
- }
-}