You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/10/24 12:40:43 UTC

[5/6] camel git commit: CAMEL-9251: rest-dsl - Allow to configure api-doc route id

CAMEL-9251: rest-dsl - Allow to configure api-doc route id


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

Branch: refs/heads/master
Commit: 9ff11b57f5f5ea8efee195680617930d67d2c8d9
Parents: 041f7e5
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Oct 24 12:37:58 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 24 12:43:22 2015 +0200

----------------------------------------------------------------------
 .../model/rest/RestConfigurationDefinition.java | 29 ++++++++++++++++++++
 .../apache/camel/model/rest/RestDefinition.java |  5 +++-
 .../org/apache/camel/spi/RestConfiguration.java | 16 +++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9ff11b57/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
index 7429fb1..155a513 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
@@ -61,6 +61,9 @@ public class RestConfigurationDefinition {
     private String apiContextPath;
 
     @XmlAttribute
+    private String apiContextRouteId;
+
+    @XmlAttribute
     private String apiContextIdPattern;
 
     @XmlAttribute
@@ -199,6 +202,21 @@ public class RestConfigurationDefinition {
         this.apiContextPath = contextPath;
     }
 
+    public String getApiContextRouteId() {
+        return apiContextRouteId;
+    }
+
+    /**
+     * Sets the route id to use for the route that services the REST API.
+     * <p/>
+     * The route will by default use an auto assigned route id.
+     *
+     * @param apiContextRouteId  the route id
+     */
+    public void setApiContextRouteId(String apiContextRouteId) {
+        this.apiContextRouteId = apiContextRouteId;
+    }
+
     public String getApiContextIdPattern() {
         return apiContextIdPattern;
     }
@@ -444,6 +462,14 @@ public class RestConfigurationDefinition {
     }
 
     /**
+     * Sets the route id to use for the route that services the REST API.
+     */
+    public RestConfigurationDefinition apiContextRouteId(String routeId) {
+        setApiContextRouteId(routeId);
+        return this;
+    }
+
+    /**
      * Sets an CamelContext id pattern to only allow Rest APIs from rest services within CamelContext's which name matches the pattern.
      * <p/>
      * The pattern uses the rules from {@link org.apache.camel.util.EndpointHelper#matchPattern(String, String)}
@@ -625,6 +651,9 @@ public class RestConfigurationDefinition {
         if (apiContextPath != null) {
             answer.setApiContextPath(CamelContextHelper.parseText(context, apiContextPath));
         }
+        if (apiContextRouteId != null) {
+            answer.setApiContextRouteId(CamelContextHelper.parseText(context, apiContextRouteId));
+        }
         if (apiContextIdPattern != null) {
             // special to allow #name# to refer to itself
             if ("#name#".equals(apiComponent)) {

http://git-wip-us.apache.org/repos/asf/camel/blob/9ff11b57/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 fd4970a..8bbbe71 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
@@ -550,7 +550,10 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
         // append options
         Map<String, Object> options = new HashMap<String, Object>();
 
-        String routeId = answer.idOrCreate(camelContext.getNodeIdFactory());
+        String routeId = configuration.getApiContextRouteId();
+        if (routeId == null) {
+            routeId = answer.idOrCreate(camelContext.getNodeIdFactory());
+        }
         options.put("routeId", routeId);
         if (configuration.getComponent() != null && !configuration.getComponent().isEmpty()) {
             options.put("componentName", configuration.getComponent());

http://git-wip-us.apache.org/repos/asf/camel/blob/9ff11b57/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java b/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
index 8c057ea..aec8453 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
@@ -44,6 +44,7 @@ public class RestConfiguration {
     private int port;
     private String contextPath;
     private String apiContextPath;
+    private String apiContextRouteId;
     private String apiContextIdPattern;
     private boolean apiContextListing;
     private RestHostNameResolver restHostNameResolver = RestHostNameResolver.localHostName;
@@ -187,6 +188,21 @@ public class RestConfiguration {
         this.apiContextPath = contextPath;
     }
 
+    public String getApiContextRouteId() {
+        return apiContextRouteId;
+    }
+
+    /**
+     * Sets the route id to use for the route that services the REST API.
+     * <p/>
+     * The route will by default use an auto assigned route id.
+     *
+     * @param apiContextRouteId  the route id
+     */
+    public void setApiContextRouteId(String apiContextRouteId) {
+        this.apiContextRouteId = apiContextRouteId;
+    }
+
     public String getApiContextIdPattern() {
         return apiContextIdPattern;
     }