You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ff...@apache.org on 2019/07/04 21:32:57 UTC
[camel] branch master updated: [CAMEL-13724]camel route customized
id isn't correct if there are more than one Rest DSL route availble
This is an automated email from the ASF dual-hosted git repository.
ffang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 414a712 [CAMEL-13724]camel route customized id isn't correct if there are more than one Rest DSL route availble
414a712 is described below
commit 414a7121f0b573c9f3ce39f880d7569e7a826cc2
Author: Freeman Fang <fr...@gmail.com>
AuthorDate: Thu Jul 4 17:32:33 2019 -0400
[CAMEL-13724]camel route customized id isn't correct if there are more than one Rest DSL route availble
---
.../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/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java b/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
index 0a46539..ed83a26 100644
--- a/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
+++ b/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
@@ -152,7 +152,6 @@ public final class RouteDefinitionHelper {
if (verb.hasCustomIdAssigned() && ObjectHelper.isNotEmpty(id) && !customIds.contains(id)) {
route.setId(id);
customIds.add(id);
- break;
}
}
}
@@ -224,13 +223,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/core/camel-core/src/test/java/org/apache/camel/impl/RouteIdRestDefinitionTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/RouteIdRestDefinitionTest.java
index 8630a92..74c811b 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/RouteIdRestDefinitionTest.java
+++ b/core/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