This is an automated email from the ASF dual-hosted git repository.

ffang pushed a commit to branch camel-2.23.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.23.x by this push:
     new 5ea2541  [CAMEL-13724]camel route customized id isn't correct if there 
are more than one Rest DSL route availble
5ea2541 is described below

commit 5ea2541a33e156bdf275d7ad1b0e00ab001aebb1
Author: Freeman Fang <freeman.f...@gmail.com>
AuthorDate: Fri Jul 5 13:31:05 2019 -0400

    [CAMEL-13724]camel route customized id isn't correct if there are more than 
one Rest DSL route availble
    
    (cherry picked from commit 457479046dec039ffb1e23e69f15804df71d34b8)
    (cherry picked from commit 39ad88e5e0e2fe05f59dd7ab94d9fefed97f6ec0)
---
 .../java/org/apache/camel/model/RouteDefinitionHelper.java | 14 ++++++++++----
 .../org/apache/camel/impl/RouteIdRestDefinitionTest.java   |  4 +++-
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git 
a/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java 
b/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
index f109d4b..f91f85d 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
@@ -151,7 +151,6 @@ public final class RouteDefinitionHelper {
                         if (verb.hasCustomIdAssigned() && 
ObjectHelper.isNotEmpty(id) && !customIds.contains(id)) {
                             route.setId(id);
                             customIds.add(id);
-                            break;
                         }
                     }
                 }
@@ -225,13 +224,20 @@ public final class RouteDefinitionHelper {
      * Find verb associated with the route by mapping uri
      */
     private static VerbDefinition findVerbDefinition(RestDefinition rest, 
String endpointUri) {
+        VerbDefinition ret = null;
+        String preVerbUri = "";
         for (VerbDefinition verb : rest.getVerbs()) {
             String verbUri = rest.buildFromUri(verb);
-            if (endpointUri.startsWith(verbUri)) {
-                return verb;
+            if (endpointUri.startsWith(verbUri)
+                && preVerbUri.length() < verbUri.length()) {
+                //if there are multiple verb uri match, select the most 
specific one
+                //for example if the endpoint Uri is 
rest:get:/user:/{id}/user?produces=text%2Fplain
+                //then the verbUri rest:get:/user:/{id}/user should overweigh 
the est:get:/user:/{id}
+                preVerbUri = verbUri;
+                ret = verb;
             }
         }
-        return null;
+        return ret;
     }
 
     /**
diff --git 
a/camel-core/src/test/java/org/apache/camel/impl/RouteIdRestDefinitionTest.java 
b/camel-core/src/test/java/org/apache/camel/impl/RouteIdRestDefinitionTest.java
index 30b1327..20bf9d6 100644
--- 
a/camel-core/src/test/java/org/apache/camel/impl/RouteIdRestDefinitionTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/impl/RouteIdRestDefinitionTest.java
@@ -39,7 +39,8 @@ public class RouteIdRestDefinitionTest extends 
ContextTestSupport {
             public void configure() throws Exception {
                 from("direct:start1?timeout=30000").to("mock:result");
                 from("direct:start2").to("mock:result");
-                
rest("/say/hello").get("/bar").id("getSayHelloBar").to("mock:result");
+                
rest("/say/hello").get("/bar").id("getSayHelloBar").to("mock:result")
+                
.get("/bar/{user}").id("getSayHelloBarWithUser").to("mock:result");
             }
         };
     }
@@ -47,6 +48,7 @@ public class RouteIdRestDefinitionTest extends 
ContextTestSupport {
     @Test
     public void testSayHelloBar() {
         assertEquals("getSayHelloBar", 
context.getRouteDefinitions().get(2).getId());
+        assertEquals("getSayHelloBarWithUser", 
context.getRouteDefinitions().get(3).getId());
     }
     
 }
\ No newline at end of file

Reply via email to