This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.x by this push:
     new e811401  CAMEL-13015: camel-spring-boot - xml routes/rests can now 
load from multiple paths separated by comma.
e811401 is described below

commit e8114012ec6ef7439927f830c98af7eb2b9b6487
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Thu Dec 20 12:56:41 2018 +0100

    CAMEL-13015: camel-spring-boot - xml routes/rests can now load from 
multiple paths separated by comma.
---
 .../src/main/docs/spring-boot.adoc                 |  4 +-
 .../spring/boot/CamelConfigurationProperties.java  | 12 +++++
 .../apache/camel/spring/boot/RoutesCollector.java  | 50 +++++++++--------
 .../camel/spring/boot/CamelXmlRoutesTest.java      | 62 ++++++++++++++++++++++
 .../src/test/resources/routes/bar.xml              | 25 +++++++++
 .../src/test/resources/routes/foo.xml              | 25 +++++++++
 6 files changed, 153 insertions(+), 25 deletions(-)

diff --git a/components/camel-spring-boot/src/main/docs/spring-boot.adoc 
b/components/camel-spring-boot/src/main/docs/spring-boot.adoc
index a9336d7..69c98ac 100644
--- a/components/camel-spring-boot/src/main/docs/spring-boot.adoc
+++ b/components/camel-spring-boot/src/main/docs/spring-boot.adoc
@@ -192,8 +192,8 @@ The component supports 140 options, which are listed below.
 | *camel.springboot.use-breadcrumb* | Set whether breadcrumb is enabled. The 
default value is true. | true | Boolean
 | *camel.springboot.use-data-type* | Whether to enable using data type on 
Camel messages. Data type are automatic turned on if one ore more routes has 
been explicit configured with input and output types. Otherwise data type is 
default off. | false | Boolean
 | *camel.springboot.use-mdc-logging* | To turn on MDC logging | false | Boolean
-| *camel.springboot.xml-rests* | Directory to scan for adding additional XML 
rests. You can turn this off by setting the value to false. | 
classpath:camel-rest/*.xml | String
-| *camel.springboot.xml-routes* | Directory to scan for adding additional XML 
routes. You can turn this off by setting the value to false. | 
classpath:camel/*.xml | String
+| *camel.springboot.xml-rests* | Directory to scan for adding additional XML 
rests. You can turn this off by setting the value to false. Files can be loaded 
from either classpath or file by prefixing with classpath: or file: Wildcards 
is supported using a ANT pattern style paths, such as 
classpath:&#42;&#42;/&#42;camel&#42;.xml Multiple directories can be specified 
and separated by comma, such as: 
file:/myapp/mycamel/&#42;.xml,file:/myapp/myothercamel/&#42;.xml | 
classpath:camel-rest/*.x [...]
+| *camel.springboot.xml-routes* | Directory to scan for adding additional XML 
routes. You can turn this off by setting the value to false. Files can be 
loaded from either classpath or file by prefixing with classpath: or file: 
Wildcards is supported using a ANT pattern style paths, such as 
classpath:&#42;&#42;/&#42;camel&#42;.xml Multiple directories can be specified 
and separated by comma, such as: 
file:/myapp/mycamel/&#42;.xml,file:/myapp/myothercamel/&#42;.xml | 
classpath:camel/*.xml  [...]
 | *camel.springboot.xml-routes-reload-directory* | To watch the directory for 
file changes which triggers a live reload of the Camel routes on-the-fly. For 
example configure this to point to the source code where the Camel XML files 
are located such as: src/main/resources/camel/ |  | String
 | *camel.ssl.cert-alias* | An optional certificate alias to use. This is 
useful when the keystore has multiple certificates. |  | String
 | *camel.ssl.cipher-suites* | The optional explicitly configured cipher suites 
for this configuration. |  | CipherSuitesParameters
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 81c5d11..449836a 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
@@ -122,12 +122,24 @@ public class CamelConfigurationProperties {
     /**
      * Directory to scan for adding additional XML routes.
      * You can turn this off by setting the value to false.
+     *
+     * Files can be loaded from either classpath or file by prefixing with 
classpath: or file:
+     * Wildcards is supported using a ANT pattern style paths, such as 
classpath:&#42;&#42;/&#42;camel&#42;.xml
+     *
+     * Multiple directories can be specified and separated by comma, such as:
+     * file:/myapp/mycamel/&#42;.xml,file:/myapp/myothercamel/&#42;.xml
      */
     private String xmlRoutes = "classpath:camel/*.xml";
 
     /**
      * Directory to scan for adding additional XML rests.
      * You can turn this off by setting the value to false.
+     *
+     * Files can be loaded from either classpath or file by prefixing with 
classpath: or file:
+     * Wildcards is supported using a ANT pattern style paths, such as 
classpath:&#42;&#42;/&#42;camel&#42;.xml
+     *
+     * Multiple directories can be specified and separated by comma, such as:
+     * file:/myapp/mycamel/&#42;.xml,file:/myapp/myothercamel/&#42;.xml
      */
     private String xmlRests = "classpath:camel-rest/*.xml";
 
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 d378e31..ecb0668 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
@@ -274,35 +274,39 @@ public class RoutesCollector implements 
ApplicationListener<ContextRefreshedEven
     // Helpers
 
     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(directory);
-            for (Resource xmlRoute : xmlRoutes) {
-                LOG.debug("Found XML route: {}", xmlRoute);
-                RoutesDefinition xmlDefinition = 
camelContext.loadRoutesDefinition(xmlRoute.getInputStream());
-                camelContext.addRouteDefinitions(xmlDefinition.getRoutes());
+        String[] parts = directory.split(",");
+        for (String part : parts) {
+            LOG.info("Loading additional Camel XML routes from: {}", part);
+            try {
+                Resource[] xmlRoutes = applicationContext.getResources(part);
+                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 {}. Skipping XML routes 
detection.", part);
             }
-        } catch (FileNotFoundException e) {
-            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);
+    private void loadXmlRests(ApplicationContext applicationContext, 
CamelContext camelContext, String directory) throws Exception {
+        String[] parts = directory.split(",");
+        for (String part : parts) {
+            LOG.info("Loading additional Camel XML rests from: {}", part);
+            try {
+                final Resource[] xmlRests = 
applicationContext.getResources(part);
+                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.", part);
             }
-        } catch (FileNotFoundException e) {
-            LOG.debug("No XML rests found in {}. Skipping XML rests 
detection.", directory);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
         }
     }
 
diff --git 
a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelXmlRoutesTest.java
 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelXmlRoutesTest.java
new file mode 100644
index 0000000..3ebff4e
--- /dev/null
+++ 
b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelXmlRoutesTest.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spring.boot;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@DirtiesContext
+@RunWith(SpringRunner.class)
+@EnableAutoConfiguration
+@SpringBootTest(
+    classes = {
+        CamelXmlRoutesTest.class,
+        RouteConfigWithCamelContextInjected.class },
+    properties = {
+        
"camel.springboot.xml-routes=file:src/test/resources/routes/foo.xml,file:src/test/resources/routes/bar.xml"}
+)
+public class CamelXmlRoutesTest extends Assert {
+
+    // Collaborators fixtures
+
+    @Autowired
+    CamelContext camelContext;
+
+    @Test
+    public void shouldDetectRoutes() {
+        // When
+        Route route = camelContext.getRoute("foo");
+
+        // Then
+        assertNotNull(route);
+
+        // When
+        route = camelContext.getRoute("bar");
+
+        // Then
+        assertNotNull(route);
+    }
+
+}
\ No newline at end of file
diff --git a/components/camel-spring-boot/src/test/resources/routes/bar.xml 
b/components/camel-spring-boot/src/test/resources/routes/bar.xml
new file mode 100644
index 0000000..63ee6df
--- /dev/null
+++ b/components/camel-spring-boot/src/test/resources/routes/bar.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<routes xmlns="http://camel.apache.org/schema/spring";>
+  <route id="bar">
+    <from uri="direct:bar"/>
+    <to uri="mock:bar"/>
+  </route>
+</routes>
diff --git a/components/camel-spring-boot/src/test/resources/routes/foo.xml 
b/components/camel-spring-boot/src/test/resources/routes/foo.xml
new file mode 100644
index 0000000..99f798b
--- /dev/null
+++ b/components/camel-spring-boot/src/test/resources/routes/foo.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+
+-->
+<routes xmlns="http://camel.apache.org/schema/spring";>
+  <route id="foo">
+    <from uri="direct:foo"/>
+    <to uri="mock:foo"/>
+  </route>
+</routes>

Reply via email to