camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/5] camel git commit: CAMEL-9426: rest-api route should only be added once
Date Wed, 16 Dec 2015 08:29:51 GMT
CAMEL-9426: rest-api route should only be added once


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

Branch: refs/heads/camel-2.16.x
Commit: fd7f890b346f001e13321233f2a35b54c9513637
Parents: 0d8e71d
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Dec 16 09:28:13 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Dec 16 09:28:50 2015 +0100

----------------------------------------------------------------------
 .../org/apache/camel/builder/RouteBuilder.java    | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/fd7f890b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index 984e7cf..bc5b61f 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -26,6 +26,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.model.FromDefinition;
 import org.apache.camel.model.InterceptDefinition;
 import org.apache.camel.model.InterceptFromDefinition;
 import org.apache.camel.model.InterceptSendToEndpointDefinition;
@@ -446,8 +447,21 @@ public abstract class RouteBuilder extends BuilderSupport implements
RoutesBuild
         // convert rests api-doc into routes so they are routes for runtime
         for (RestConfiguration config : camelContext.getRestConfigurations()) {
             if (config.getApiContextPath() != null) {
-                RouteDefinition route = RestDefinition.asRouteApiDefinition(camelContext,
config);
-                routes.add(route);
+                // avoid adding rest-api multiple times, in case multiple RouteBuilder classes
is added
+                // to the CamelContext, as we only want to setup rest-api once
+                // so we check all existing routes if they have rest-api route already added
+                boolean hasRestApi = false;
+                for (RouteDefinition route : camelContext.getRouteDefinitions()) {
+                    FromDefinition from = route.getInputs().get(0);
+                    if (from.getUri() != null && from.getUri().startsWith("rest-api:"))
{
+                        hasRestApi = true;
+                    }
+                }
+                if (!hasRestApi) {
+                    RouteDefinition route = RestDefinition.asRouteApiDefinition(camelContext,
config);
+                    log.debug("Adding routeId: {} as rest-api route", route.getId());
+                    routes.add(route);
+                }
             }
         }
 


Mime
View raw message