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/21 10:44:32 UTC

[1/3] camel git commit: CAMEL-9089: rest-dsl when multiple candidates then use the most specific one.

Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x c80e57600 -> 194bdaf0d


CAMEL-9089: rest-dsl when multiple candidates then use the most specific one.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5a4b034a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5a4b034a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5a4b034a

Branch: refs/heads/camel-2.15.x
Commit: 5a4b034aab4e3010e3ea67ac926633327a2c5805
Parents: c80e576
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Aug 21 10:17:18 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Aug 21 10:25:11 2015 +0200

----------------------------------------------------------------------
 .../HttpServerMultiplexChannelHandler.java      | 61 ++++++++++++++-
 .../rest/RestNettyHttpGetWildcardsTest.java     | 80 ++++++++++++++++++++
 .../rest/RestServletGetWildcardsTest.java       |  4 +-
 3 files changed, 139 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5a4b034a/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 5b3ad93..32fd20c 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
@@ -200,18 +200,46 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl
             }
         }
 
-        // then match by non wildcard path
+        // 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();
                 }
             }
 
-            // there should only be one
-            if (candidates.size() == 1) {
+            // 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) {
+                            best = entry;
+                        } else {
+                            if (wildcards < bestWildcard) {
+                                bestWildcard = wildcards;
+                                best = entry;
+                            }
+                        }
+                    }
+                }
+
+                if (best != null) {
+                    // pick the best among the wildcards
+                    answer = best.getValue();
+                }
+            }
+
+            // if there is one left then its our answer
+            if (answer == null && candidates.size() == 1) {
                 answer = candidates.get(0).getValue();
             }
         }
@@ -229,6 +257,33 @@ 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 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("/")) {

http://git-wip-us.apache.org/repos/asf/camel/blob/5a4b034a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpGetWildcardsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpGetWildcardsTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpGetWildcardsTest.java
new file mode 100644
index 0000000..176c6e9
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpGetWildcardsTest.java
@@ -0,0 +1,80 @@
+/**
+ * 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.rest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.netty4.http.BaseNettyTest;
+import org.apache.camel.component.netty4.http.RestNettyHttpBinding;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Test;
+
+public class RestNettyHttpGetWildcardsTest extends BaseNettyTest {
+    
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("mybinding", new RestNettyHttpBinding());
+        return jndi;
+    }
+
+    @Test
+    public void testProducerGet() throws Exception {
+        String out = template.requestBody("netty4-http:http://localhost:{{port}}/users/123/basic", null, String.class);
+        assertEquals("123;Donald Duck", out);
+    }
+
+    @Test
+    public void testServletProducerGetWildcards() throws Exception {
+        String out = template.requestBody("netty4-http:http://localhost:{{port}}/users/456/name=g*", null, String.class);
+        assertEquals("456;Goofy", out);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // configure to use netty4-http on localhost with the given port
+                restConfiguration().component("netty4-http").host("localhost").port(getPort()).endpointProperty("nettyHttpBinding", "#mybinding");
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                    .get("{id}/{query}")
+                        .route()
+                        .to("log:query")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                String id = exchange.getIn().getHeader("id", String.class);
+                                exchange.getOut().setBody(id + ";Goofy");
+                            }
+                        }).endRest()
+                    .get("{id}/basic")
+                        .route()
+                        .to("log:input")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                String id = exchange.getIn().getHeader("id", String.class);
+                                exchange.getOut().setBody(id + ";Donald Duck");
+                            }
+                        }).endRest();
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/5a4b034a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletGetWildcardsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletGetWildcardsTest.java b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletGetWildcardsTest.java
index 2a49836..e382601 100644
--- a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletGetWildcardsTest.java
+++ b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletGetWildcardsTest.java
@@ -26,7 +26,6 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.servlet.ServletCamelRouterTestSupport;
 import org.apache.camel.component.servlet.ServletRestHttpBinding;
 import org.apache.camel.impl.JndiRegistry;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class RestServletGetWildcardsTest extends ServletCamelRouterTestSupport {
@@ -51,7 +50,6 @@ public class RestServletGetWildcardsTest extends ServletCamelRouterTestSupport {
     }
 
     @Test
-    @Ignore
     public void testServletProducerGetWildcards() throws Exception {
         WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/users/456/name=g*");
         ServletUnitClient client = newClient();
@@ -82,7 +80,7 @@ public class RestServletGetWildcardsTest extends ServletCamelRouterTestSupport {
                                 exchange.getOut().setBody(id + ";Goofy");
                             }
                         }).endRest()
-                .get("{id}/basic")
+                    .get("{id}/basic")
                         .route()
                         .to("mock:input")
                         .process(new Processor() {


[2/3] camel git commit: CAMEL-9089: rest-dsl when multiple candidates then use the most specific one.

Posted by da...@apache.org.
CAMEL-9089: rest-dsl when multiple candidates then use the most specific one.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b305eb67
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b305eb67
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b305eb67

Branch: refs/heads/camel-2.15.x
Commit: b305eb677a16133cf8859be2513ec3e3973b4bac
Parents: 5a4b034
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Aug 21 10:24:41 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Aug 21 10:25:17 2015 +0200

----------------------------------------------------------------------
 .../HttpServerMultiplexChannelHandler.java      | 61 ++++++++++++++-
 .../rest/RestNettyHttpGetWildcardsTest.java     | 79 ++++++++++++++++++++
 .../HttpServerMultiplexChannelHandler.java      |  2 +-
 3 files changed, 138 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b305eb67/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
index 2bcac76..747b242 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
@@ -203,18 +203,46 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
             }
         }
 
-        // then match by non wildcard path
+        // 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();
                 }
             }
 
-            // there should only be one
-            if (candidates.size() == 1) {
+            // 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) {
+                            best = entry;
+                        } else {
+                            if (wildcards < bestWildcard) {
+                                bestWildcard = wildcards;
+                                best = entry;
+                            }
+                        }
+                    }
+                }
+
+                if (best != null) {
+                    // pick the best among the wildcards
+                    answer = best.getValue();
+                }
+            }
+
+            // if there is one left then its our answer
+            if (answer == null && candidates.size() == 1) {
                 answer = candidates.get(0).getValue();
             }
         }
@@ -232,6 +260,33 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
         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("/")) {

http://git-wip-us.apache.org/repos/asf/camel/blob/b305eb67/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpGetWildcardsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpGetWildcardsTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpGetWildcardsTest.java
new file mode 100644
index 0000000..403bc8f
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpGetWildcardsTest.java
@@ -0,0 +1,79 @@
+/**
+ * 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.rest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.netty.http.BaseNettyTest;
+import org.apache.camel.component.netty.http.RestNettyHttpBinding;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Test;
+
+public class RestNettyHttpGetWildcardsTest extends BaseNettyTest {
+    
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("mybinding", new RestNettyHttpBinding());
+        return jndi;
+    }
+
+    @Test
+    public void testProducerGet() throws Exception {
+        String out = template.requestBody("netty-http:http://localhost:{{port}}/users/123/basic", null, String.class);
+        assertEquals("123;Donald Duck", out);
+    }
+
+    @Test
+    public void testServletProducerGetWildcards() throws Exception {
+        String out = template.requestBody("netty-http:http://localhost:{{port}}/users/456/name=g*", null, String.class);
+        assertEquals("456;Goofy", out);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // configure to use netty4-http on localhost with the given port
+                restConfiguration().component("netty-http").host("localhost").port(getPort()).endpointProperty("nettyHttpBinding", "#mybinding");
+
+                // use the rest DSL to define the rest services
+                rest("/users/")
+                        .get("{id}/{query}")
+                        .route()
+                        .to("log:query")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                String id = exchange.getIn().getHeader("id", String.class);
+                                exchange.getOut().setBody(id + ";Goofy");
+                            }
+                        }).endRest()
+                        .get("{id}/basic")
+                        .route()
+                        .to("log:input")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                String id = exchange.getIn().getHeader("id", String.class);
+                                exchange.getOut().setBody(id + ";Donald Duck");
+                            }
+                        }).endRest();
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/b305eb67/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 32fd20c..68bb656 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
@@ -263,7 +263,7 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl
      * @param consumerPath  the consumer path which may use { } tokens
      * @return number of wildcards, or <tt>0</tt> if no wildcards
      */
-    private int countWildcards(String consumerPath) {
+    private static int countWildcards(String consumerPath) {
         int wildcards = 0;
 
         // remove starting/ending slashes


[3/3] camel git commit: CAMEL-9089: rest-dsl when multiple candidates then use the most specific one.

Posted by da...@apache.org.
CAMEL-9089: rest-dsl when multiple candidates then use the most specific one.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/194bdaf0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/194bdaf0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/194bdaf0

Branch: refs/heads/camel-2.15.x
Commit: 194bdaf0d9492602e0ed73608445a163e36f4bc5
Parents: b305eb6
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Aug 21 10:46:28 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Aug 21 10:52:23 2015 +0200

----------------------------------------------------------------------
 .../HttpServerMultiplexChannelHandler.java      |  8 ++-----
 .../HttpServerMultiplexChannelHandler.java      |  8 ++-----
 ...rvletRestServletResolveConsumerStrategy.java | 25 +++++++++++++-------
 .../rest/RestServletGetWildcardsTest.java       | 12 +++++-----
 4 files changed, 26 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/194bdaf0/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
index 747b242..de443d6 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
@@ -224,13 +224,9 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
                     String consumerPath = entry.getValue().getConsumer().getConfiguration().getPath();
                     int wildcards = countWildcards(consumerPath);
                     if (wildcards > 0) {
-                        if (best == null) {
+                        if (best == null || wildcards < bestWildcard) {
                             best = entry;
-                        } else {
-                            if (wildcards < bestWildcard) {
-                                bestWildcard = wildcards;
-                                best = entry;
-                            }
+                            bestWildcard = wildcards;
                         }
                     }
                 }

http://git-wip-us.apache.org/repos/asf/camel/blob/194bdaf0/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 68bb656..30dae07 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
@@ -221,13 +221,9 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl
                     String consumerPath = entry.getValue().getConsumer().getConfiguration().getPath();
                     int wildcards = countWildcards(consumerPath);
                     if (wildcards > 0) {
-                        if (best == null) {
+                        if (best == null || wildcards < bestWildcard) {
                             best = entry;
-                        } else {
-                            if (wildcards < bestWildcard) {
-                                bestWildcard = wildcards;
-                                best = entry;
-                            }
+                            bestWildcard = wildcards;
                         }
                     }
                 }

http://git-wip-us.apache.org/repos/asf/camel/blob/194bdaf0/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 d2a79f7..1d1563c 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
@@ -77,24 +77,31 @@ public class ServletRestServletResolveConsumerStrategy extends HttpServletResolv
                 }
             }
 
-            // if there is multiple candidates then pick anyone with the least number of wildcards
-            int best = -1;
+            // 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 consumer = it.next();
-                    String consumerPath = consumer.getPath();
+                    HttpConsumer entry = it.next();
+                    String consumerPath = entry.getPath();
                     int wildcards = countWildcards(consumerPath);
-                    if (best != -1 && wildcards >= best) {
-                        it.remove();
-                    } else {
-                        best = wildcards;
+                    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 (candidates.size() == 1) {
+            if (answer == null && candidates.size() == 1) {
                 answer = candidates.get(0);
             }
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/194bdaf0/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletGetWildcardsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletGetWildcardsTest.java b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletGetWildcardsTest.java
index e382601..67a1b7a 100644
--- a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletGetWildcardsTest.java
+++ b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletGetWildcardsTest.java
@@ -71,22 +71,22 @@ public class RestServletGetWildcardsTest extends ServletCamelRouterTestSupport {
                 
                 // use the rest DSL to define the rest services
                 rest("/users/")
-                    .get("{id}/{query}")
+                    .get("{id}/basic")
                         .route()
-                        .to("mock:query")
+                        .to("mock:input")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
                                 String id = exchange.getIn().getHeader("id", String.class);
-                                exchange.getOut().setBody(id + ";Goofy");
+                                exchange.getOut().setBody(id + ";Donald Duck");
                             }
                         }).endRest()
-                    .get("{id}/basic")
+                    .get("{id}/{query}")
                         .route()
-                        .to("mock:input")
+                        .to("mock:query")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
                                 String id = exchange.getIn().getHeader("id", String.class);
-                                exchange.getOut().setBody(id + ";Donald Duck");
+                                exchange.getOut().setBody(id + ";Goofy");
                             }
                         }).endRest();
             }