camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-9325: camel-spring-boot - Allow to configure directory to scan for xml routes, and to turn it off.
Date Fri, 25 Dec 2015 10:39:15 GMT
Repository: camel
Updated Branches:
  refs/heads/master 5cfea2cac -> 69421bf3d


CAMEL-9325: camel-spring-boot - Allow to configure directory to scan for xml routes, and to
turn it off.


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

Branch: refs/heads/master
Commit: 69421bf3d45899f09510ab3873a1656cbc83ec41
Parents: 5cfea2c
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Dec 25 11:35:17 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Dec 25 11:35:17 2015 +0100

----------------------------------------------------------------------
 .../spring/boot/CamelAutoConfiguration.java     |  4 ++--
 .../boot/CamelConfigurationProperties.java      | 13 ++++++++++++
 .../camel/spring/boot/RoutesCollector.java      | 22 +++++++++++++-------
 3 files changed, 30 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/69421bf3/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index e1bd003..b3c58ab 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -67,9 +67,9 @@ public class CamelAutoConfiguration {
 
     @Bean
     @ConditionalOnMissingBean(RoutesCollector.class)
-    RoutesCollector routesCollector(ApplicationContext applicationContext) {
+    RoutesCollector routesCollector(ApplicationContext applicationContext, CamelConfigurationProperties
configurationProperties) {
         Collection<CamelContextConfiguration> configurations = applicationContext.getBeansOfType(CamelContextConfiguration.class).values();
-        return new RoutesCollector(applicationContext, new ArrayList<CamelContextConfiguration>(configurations));
+        return new RoutesCollector(applicationContext, new ArrayList<CamelContextConfiguration>(configurations),
configurationProperties);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/69421bf3/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 24dfd59..0aa0da3 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
@@ -48,6 +48,12 @@ public class CamelConfigurationProperties {
      */
     private String name;
 
+    /**
+     * Directory to scan for adding additional XML routes.
+     * You can turn this off by setting the value to <tt>false</tt>
+     */
+    private String xmlRoutes = "classpath:camel/*.xml";
+
     // Getters & setters
 
     public boolean isJmxEnabled() {
@@ -90,4 +96,11 @@ public class CamelConfigurationProperties {
         this.name = name;
     }
 
+    public String getXmlRoutes() {
+        return xmlRoutes;
+    }
+
+    public void setXmlRoutes(String xmlRoutes) {
+        this.xmlRoutes = xmlRoutes;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/69421bf3/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 bf15018..49a9015 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
@@ -47,11 +47,15 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
 
     private final List<CamelContextConfiguration> camelContextConfigurations;
 
+    private final CamelConfigurationProperties configurationProperties;
+
     // Constructors
 
-    public RoutesCollector(ApplicationContext applicationContext, List<CamelContextConfiguration>
camelContextConfigurations) {
+    public RoutesCollector(ApplicationContext applicationContext, List<CamelContextConfiguration>
camelContextConfigurations,
+                           CamelConfigurationProperties configurationProperties) {
         this.applicationContext = applicationContext;
         this.camelContextConfigurations = new ArrayList<CamelContextConfiguration>(camelContextConfigurations);
+        this.configurationProperties = configurationProperties;
     }
 
     // Overridden
@@ -59,7 +63,7 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
     @Override
     public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
         ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext();
-        // only listen to context refreshs of "my" applicationContext
+        // only listen to context refresh of "my" applicationContext
         if (this.applicationContext.equals(applicationContext)) {
             CamelContext camelContext = contextRefreshedEvent.getApplicationContext().getBean(CamelContext.class);
 
@@ -82,7 +86,10 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
                 }
 
                 try {
-                    loadXmlRoutes(applicationContext, camelContext);
+                    boolean scan = !configurationProperties.getXmlRoutes().equals("false");
+                    if (scan) {
+                        loadXmlRoutes(applicationContext, camelContext, configurationProperties.getXmlRoutes());
+                    }
 
                     for (CamelContextConfiguration camelContextConfiguration : camelContextConfigurations)
{
                         LOG.debug("CamelContextConfiguration found. Invoking: {}", camelContextConfiguration);
@@ -108,16 +115,17 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
 
     // Helpers
 
-    private void loadXmlRoutes(ApplicationContext applicationContext, CamelContext camelContext)
throws Exception {
-        LOG.debug("Started XML routes detection. Scanning classpath (/camel/*.xml)...");
+    private void loadXmlRoutes(ApplicationContext applicationContext, CamelContext camelContext,
String directory) throws Exception {
+        LOG.info("Loading additional Camel XML routes from: {}", directory);
         try {
-            Resource[] xmlRoutes = applicationContext.getResources("classpath:camel/*.xml");
+            Resource[] xmlRoutes = applicationContext.getResources(directory);
             for (Resource xmlRoute : xmlRoutes) {
+                LOG.debug("Found XML route: {}", xmlRoute);
                 RoutesDefinition xmlDefinition = camelContext.loadRoutesDefinition(xmlRoute.getInputStream());
                 camelContext.addRouteDefinitions(xmlDefinition.getRoutes());
             }
         } catch (FileNotFoundException e) {
-            LOG.debug("No XMl routes found in the classpath (/camel/*.xml). Skipping XML
routes detection.");
+            LOG.debug("No XMl routes found in {}. Skipping XML routes detection.", directory);
         }
     }
 


Mime
View raw message