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 2016/01/05 17:52:20 UTC

[2/4] camel git commit: Load REST DSL from XML files

Load REST DSL from XML files


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

Branch: refs/heads/master
Commit: b43c01c4c4a8c9e2671726e04a987df1d2c09a44
Parents: 976ae69
Author: Askannon <as...@flexarc.com>
Authored: Tue Jan 5 13:33:11 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 5 17:40:45 2016 +0100

----------------------------------------------------------------------
 .../boot/CamelConfigurationProperties.java      | 15 +++++++++
 .../camel/spring/boot/RoutesCollector.java      | 33 ++++++++++++++++++--
 2 files changed, 45 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b43c01c4/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
index 0aa0da3..be07ff1 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java
@@ -54,6 +54,12 @@ public class CamelConfigurationProperties {
      */
     private String xmlRoutes = "classpath:camel/*.xml";
 
+    /**
+     * Directory to scan for adding additional XML rests.
+     * You can turn this off by setting the value to <tt>false</tt>
+     */
+    private String xmlRests = "classpath:camel-rest/*.xml";
+
     // Getters & setters
 
     public boolean isJmxEnabled() {
@@ -103,4 +109,13 @@ public class CamelConfigurationProperties {
     public void setXmlRoutes(String xmlRoutes) {
         this.xmlRoutes = xmlRoutes;
     }
+
+	public String getXmlRests() {
+		return xmlRests;
+	}
+
+	public void setXmlRests(String xmlRests) {
+		this.xmlRests = xmlRests;
+	}
+    
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/b43c01c4/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
index 49a9015..33947c0 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
@@ -23,7 +23,10 @@ import java.util.List;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.RoutesBuilder;
+import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.model.rest.RestsDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.ApplicationContext;
@@ -32,8 +35,8 @@ import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.core.io.Resource;
 
 /**
- * Collects routes from the various sources (like Spring application context beans registry or opinionated classpath
- * locations) and injects these into the Camel context.
+ * Collects routes and rests from the various sources (like Spring application context beans registry or opinionated
+ * classpath locations) and injects these into the Camel context.
  */
 public class RoutesCollector implements ApplicationListener<ContextRefreshedEvent> {
 
@@ -91,6 +94,11 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
                         loadXmlRoutes(applicationContext, camelContext, configurationProperties.getXmlRoutes());
                     }
 
+                    boolean scanRests = !configurationProperties.getXmlRests().equals("false");
+                    if (scanRests) {
+                    	loadXmlRests(applicationContext, camelContext, configurationProperties.getXmlRests());
+                    }
+                    
                     for (CamelContextConfiguration camelContextConfiguration : camelContextConfigurations) {
                         LOG.debug("CamelContextConfiguration found. Invoking: {}", camelContextConfiguration);
                         camelContextConfiguration.beforeApplicationStart(camelContext);
@@ -125,8 +133,27 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
                 camelContext.addRouteDefinitions(xmlDefinition.getRoutes());
             }
         } catch (FileNotFoundException e) {
-            LOG.debug("No XMl routes found in {}. Skipping XML routes detection.", directory);
+            LOG.debug("No XML routes found in {}. Skipping XML routes detection.", directory);
         }
     }
 
+    private void loadXmlRests(ApplicationContext applicationContext, CamelContext camelContext, String directory) {
+    	LOG.info("Loading additional Camel XML rests from: {}", directory);
+    	try {
+    		final Resource[] xmlRests = applicationContext.getResources(directory);
+    		for (final Resource xmlRest : xmlRests) {
+    			final RestsDefinition xmlDefinitions = camelContext.loadRestsDefinition(xmlRest.getInputStream());
+    			camelContext.addRestDefinitions(xmlDefinitions.getRests());
+    			for (final RestDefinition xmlDefinition : xmlDefinitions.getRests()) {
+    				final List<RouteDefinition> routeDefinitions = xmlDefinition.asRouteDefinition(camelContext);
+    				camelContext.addRouteDefinitions(routeDefinitions);
+    			}
+    		}
+    	} catch (FileNotFoundException e) {
+            LOG.debug("No XML rests found in {}. Skipping XML rests detection.", directory);
+    	} catch (Exception e) {
+    		throw new RuntimeException(e);
+    	}
+    }
+    
 }