[ 
https://issues.apache.org/jira/browse/CAMEL-12908?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16689182#comment-16689182
 ] 

ASF GitHub Bot commented on CAMEL-12908:
----------------------------------------

dmvolod closed pull request #2612: CAMEL-12908: Cannot start route using rest 
dsl due to a mysterious  duplicate route id
URL: https://github.com/apache/camel/pull/2612
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 041bdc212dc..b0059553bae 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
@@ -19,14 +19,18 @@
 import java.io.UnsupportedEncodingException;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.builder.ErrorHandlerBuilder;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.model.rest.VerbDefinition;
 import org.apache.camel.util.CamelContextHelper;
 import org.apache.camel.util.EndpointHelper;
 import org.apache.camel.util.ObjectHelper;
@@ -145,10 +149,11 @@ public void run() {
         for (final RouteDefinition route : routes) {
             if (route.getId() == null) {
                 // keep assigning id's until we find a free name
+                
                 boolean done = false;
                 String id = null;
                 while (!done) {
-                    id = context.getNodeIdFactory().createId(route);
+                    id = route.idOrCreate(context.getNodeIdFactory());
                     done = !customIds.contains(id);
                 }
                 route.setId(id);
@@ -162,6 +167,32 @@ public void run() {
                 route.setCustomId(false);
                 customIds.add(route.getId());
             }
+            RestDefinition rest = route.getRestDefinition();
+            if (rest != null && route.isRest()) {
+                for (VerbDefinition verb : rest.getVerbs()) {
+                    String id = verb.idOrCreate(context.getNodeIdFactory());
+                    if (!verb.getUsedForGeneratingNodeId()) {
+                        id = route.getId();
+                    }
+                    verb.setRouteId(id);
+                }
+                List<FromDefinition> fromDefinitions = route.getInputs();
+                
+                if (ObjectHelper.isNotEmpty(fromDefinitions)) {
+                    FromDefinition fromDefinition = fromDefinitions.get(0);
+                    String endpointUri = fromDefinition.getEndpointUri();
+                    if (ObjectHelper.isNotEmpty(endpointUri)) {
+                        Map<String, Object> options = new HashMap<String, 
Object>();
+                        options.put("routeId", route.getId());
+                        endpointUri = 
URISupport.appendParametersToURI(endpointUri, options);
+                     
+                        // replace uri with new routeId
+                        fromDefinition.setUri(endpointUri);
+                        fromDefinitions.set(0, fromDefinition);
+                        route.setInputs(fromDefinitions);
+                    }
+                }
+            }
         }
     }
 
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
index 946fb76c16e..5fcce056d7b 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
@@ -902,23 +902,7 @@ private void addRouteDefinition(CamelContext camelContext, 
List<RouteDefinition>
             if (outType != null) {
                 options.put("outType", outType);
             }
-            // if no route id has been set, then use the verb id as route id
-            if (!route.hasCustomIdAssigned()) {
-                // use id of verb as route id
-                String id = verb.getId();
-                if (id != null) {
-                    route.setId(id);
-                }
-            }
-
-            String routeId = verb.idOrCreate(camelContext.getNodeIdFactory());
-
-            if (!verb.getUsedForGeneratingNodeId()) {
-                routeId = route.idOrCreate(camelContext.getNodeIdFactory());
-            }
 
-            verb.setRouteId(routeId);
-            options.put("routeId", routeId);
             if (component != null && !component.isEmpty()) {
                 options.put("componentName", component);
             }
@@ -1012,7 +996,6 @@ private void addRouteDefinition(CamelContext camelContext, 
List<RouteDefinition>
 
             // the route should be from this rest endpoint
             route.fromRest(from);
-            route.routeId(routeId);
             route.setRestDefinition(this);
             answer.add(route);
         }
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
index bf56005782e..acbe38a6b4b 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
@@ -141,7 +141,7 @@ public void setParams(List<RestOperationParamDefinition> 
params) {
     /**
      * Sets swagger operation response messages.
      */
-    public void setResponseMsgs(List<RestOperationResponseMsgDefinition> 
params) {
+    public void setResponseMsgs(List<RestOperationResponseMsgDefinition> 
responseMsgs) {
         this.responseMsgs = responseMsgs;
     }
 
diff --git 
a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/RestRefTest.xml
 
b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/RestRefTest.xml
index c53d943f7d2..246c2a90799 100644
--- 
a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/RestRefTest.xml
+++ 
b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/RestRefTest.xml
@@ -54,7 +54,7 @@
         <constant>Hello World</constant>
       </transform>
     </route>
-    <route>
+    <route id="route1">
       <from uri="direct:bye"/>
       <transform>
         <constant>Bye World</constant>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Cannot start route using rest dsl due to a mysterious duplicate route id
> ------------------------------------------------------------------------
>
>                 Key: CAMEL-12908
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12908
>             Project: Camel
>          Issue Type: Bug
>          Components: rest
>    Affects Versions: 2.21.0
>            Reporter: Aurélien Pupier
>            Assignee: Dmitry Volodin
>            Priority: Major
>         Attachments: example-fixedVersionsAndRepositories.zip
>
>
> issue came from investigation on 
> https://github.com/jboss-fuse/fuse-apicurito-generator/issues/12
> the Camel files contains a single route id _route2_ but there is an error 
> while trying to start the application mentioning a duplicate id _route2_
> {noformat}
> org.apache.camel.RuntimeCamelException: 
> org.apache.camel.FailedToStartRouteException: Failed to start route route2 
> because of duplicate id detected: route2. Please correct ids to be unique 
> among all your routes.
>       at 
> org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1830)
>  ~[camel-core-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:136) 
> ~[camel-spring-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.spring.CamelContextFactoryBean.start(CamelContextFactoryBean.java:369)
>  ~[camel-spring-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:416)
>  ~[camel-spring-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:94)
>  ~[camel-spring-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
>  ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
>       at 
> org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
>  ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
>       at 
> org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
>  ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
>       at 
> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393)
>  ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
>       at 
> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:399)
>  ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
>       at 
> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347)
>  ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
>       at 
> org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883)
>  ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
>       at 
> org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
>  ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
>       at 
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
>  ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
>       at 
> org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
>  ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
>       at 
> org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration.createChildManagementContext(EndpointWebMvcAutoConfiguration.java:193)
>  ~[spring-boot-actuator-1.5.13.RELEASE.jar:1.5.13.RELEASE]
>       at 
> org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration.afterSingletonsInstantiated(EndpointWebMvcAutoConfiguration.java:156)
>  ~[spring-boot-actuator-1.5.13.RELEASE.jar:1.5.13.RELEASE]
>       at 
> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:781)
>  ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
>       at 
> org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
>  ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
>       at 
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
>  ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
>       at 
> org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
>  ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
>       at 
> org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
>  [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
>       at 
> org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
>  [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
>       at 
> org.springframework.boot.SpringApplication.run(SpringApplication.java:303) 
> [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
>       at 
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) 
> [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
>       at 
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) 
> [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
>       at io.example.openapi.Application.main(Application.java:31) 
> [classes/:na]
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[na:1.8.0_181]
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[na:1.8.0_181]
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[na:1.8.0_181]
>       at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
>       at 
> org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:527)
>  [spring-boot-maven-plugin-1.5.13.RELEASE.jar:1.5.13.RELEASE]
>       at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
> Caused by: org.apache.camel.FailedToStartRouteException: Failed to start 
> route route2 because of duplicate id detected: route2. Please correct ids to 
> be unique among all your routes.
>       at 
> org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1132)
>  ~[camel-core-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3729)
>  ~[camel-core-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3443)
>  ~[camel-core-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:209)
>  ~[camel-core-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3251)
>  ~[camel-core-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3247)
>  ~[camel-core-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3270)
>  ~[camel-core-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3247)
>  ~[camel-core-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) 
> ~[camel-core-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3163)
>  ~[camel-core-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       at 
> org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:133) 
> ~[camel-spring-2.21.0.fuse-720024.jar:2.21.0.fuse-720024]
>       ... 31 common frames omitted
> {noformat}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to