camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/6] camel git commit: CAMEL-9247: rest-dsl with api-doc should allow multiple rest's
Date Sat, 24 Oct 2015 10:40:41 GMT
CAMEL-9247: rest-dsl with api-doc should allow multiple rest's


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

Branch: refs/heads/camel-2.16.x
Commit: 73cc80e117b420fc538a6e3551686c2fe45c4427
Parents: 979e9a3
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Oct 24 12:32:36 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Oct 24 12:42:47 2015 +0200

----------------------------------------------------------------------
 .../org/apache/camel/builder/RouteBuilder.java  | 20 +++++++++++++----
 .../apache/camel/model/rest/RestDefinition.java | 23 ++++++++++----------
 2 files changed, 28 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/73cc80e1/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 a5872e9..984e7cf 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
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.builder;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -436,13 +437,24 @@ public abstract class RouteBuilder extends BuilderSupport implements
RoutesBuild
         }
         camelContext.addRestDefinitions(getRestCollection().getRests());
 
-        // convert rests into routes so we reuse routes for runtime
+        // convert rests into routes so we they are routes for runtime
+        List<RouteDefinition> routes = new ArrayList<RouteDefinition>();
         for (RestDefinition rest : getRestCollection().getRests()) {
-            List<RouteDefinition> routes = rest.asRouteDefinition(getContext());
-            for (RouteDefinition route : routes) {
-                getRouteCollection().route(route);
+            List<RouteDefinition> list = rest.asRouteDefinition(getContext());
+            routes.addAll(list);
+        }
+        // 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);
             }
         }
+
+        // add the rest routes
+        for (RouteDefinition route : routes) {
+            getRouteCollection().route(route);
+        }
     }
 
     public RestsDefinition getRestCollection() {

http://git-wip-us.apache.org/repos/asf/camel/blob/73cc80e1/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
----------------------------------------------------------------------
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 e2b1895..fd4970a 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
@@ -533,15 +533,16 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
         }
         for (RestConfiguration config : camelContext.getRestConfigurations()) {
             addRouteDefinition(camelContext, answer, config.getComponent());
-            if (config.getApiContextPath() != null) {
-                addApiRouteDefinition(camelContext, answer, config);
-            }
         }
         return answer;
     }
 
-    private void addApiRouteDefinition(CamelContext camelContext, List<RouteDefinition>
answer, RestConfiguration configuration) {
-        RouteDefinition route = new RouteDefinition();
+    /**
+     * Transforms the rest api configuration into a {@link org.apache.camel.model.RouteDefinition}
which
+     * Camel routing engine uses to service the rest api docs.
+     */
+    public static RouteDefinition asRouteApiDefinition(CamelContext camelContext, RestConfiguration
configuration) {
+        RouteDefinition answer = new RouteDefinition();
 
         // create the from endpoint uri which is using the rest-api component
         String from = "rest-api:" + configuration.getApiContextPath();
@@ -549,7 +550,7 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
         // append options
         Map<String, Object> options = new HashMap<String, Object>();
 
-        String routeId = "rest-api-" + route.idOrCreate(camelContext.getNodeIdFactory());
+        String routeId = answer.idOrCreate(camelContext.getNodeIdFactory());
         options.put("routeId", routeId);
         if (configuration.getComponent() != null && !configuration.getComponent().isEmpty())
{
             options.put("componentName", configuration.getComponent());
@@ -570,12 +571,11 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
 
         // we use the same uri as the producer (so we have a little route for the rest api)
         String to = from;
+        answer.fromRest(from);
+        answer.id(routeId);
+        answer.to(to);
 
-        // the route should be from this rest endpoint
-        route.fromRest(from);
-        route.to(to);
-        route.setRestDefinition(this);
-        answer.add(route);
+        return answer;
     }
 
     private void addRouteDefinition(CamelContext camelContext, List<RouteDefinition>
answer, String component) {
@@ -738,6 +738,7 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
 
             // the route should be from this rest endpoint
             route.fromRest(from);
+            route.id(routeId);
             route.setRestDefinition(this);
             answer.add(route);
         }


Mime
View raw message