[GitHub] nicolaferraro closed pull request #71: Add support for XML routes

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] nicolaferraro closed pull request #71: Add support for XML routes

GitBox
nicolaferraro closed pull request #71: Add support for XML routes
URL: https://github.com/apache/camel-k/pull/71
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Routes.java b/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Routes.java
index b2c87d4..5a59ea3 100644
--- a/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Routes.java
+++ b/runtime/jvm/src/main/java/org/apache/camel/k/jvm/Routes.java
@@ -34,7 +34,7 @@ private Routes() {
     }
 
     public static boolean isScripting(String resource) {
-        return resource.endsWith(".java") || resource.endsWith(".js") || resource.endsWith(".groovy");
+        return resource.endsWith(".java") || resource.endsWith(".js") || resource.endsWith(".groovy") || resource.endsWith(".xml");
     }
 
     public static RoutesLoader loaderForLanguage(String language) {
diff --git a/runtime/jvm/src/main/java/org/apache/camel/k/jvm/RoutesLoaders.java b/runtime/jvm/src/main/java/org/apache/camel/k/jvm/RoutesLoaders.java
index 8f9409e..c0489ec 100644
--- a/runtime/jvm/src/main/java/org/apache/camel/k/jvm/RoutesLoaders.java
+++ b/runtime/jvm/src/main/java/org/apache/camel/k/jvm/RoutesLoaders.java
@@ -35,6 +35,7 @@
 import org.apache.camel.Component;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.RoutesDefinition;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.codehaus.groovy.control.CompilerConfiguration;
@@ -168,6 +169,35 @@ public void configure() throws Exception {
                 }
             };
         }
+    },
+    Xml {
+        @Override
+        public List<String> getSupportedLanguages() {
+            return Arrays.asList("xml");
+        }
+
+        @Override
+        public boolean test(String resource) {
+            String ext = StringUtils.substringAfterLast(resource, ".");
+            List<String> langs = getSupportedLanguages();
+
+            return langs.contains(ext);
+        }
+
+        @Override
+        public RouteBuilder load(String resource) throws Exception {
+            return new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    try (InputStream is = Routes.loadResourceAsInputStream(resource)) {
+                        final CamelContext context = getContext();
+                        final RoutesDefinition definitions = context.loadRoutesDefinition(is);
+
+                        setRouteCollection(definitions);
+                    }
+                }
+            };
+        }
     };
 
     // ********************************
diff --git a/runtime/jvm/src/test/java/org/apache/camel/k/jvm/RoutesLoadersTest.java b/runtime/jvm/src/test/java/org/apache/camel/k/jvm/RoutesLoadersTest.java
index e083464..d281085 100644
--- a/runtime/jvm/src/test/java/org/apache/camel/k/jvm/RoutesLoadersTest.java
+++ b/runtime/jvm/src/test/java/org/apache/camel/k/jvm/RoutesLoadersTest.java
@@ -112,6 +112,23 @@ public void testLoadGroovy() throws Exception {
         assertThat(routes.get(0).getOutputs().get(0)).isInstanceOf(ToDefinition.class);
     }
 
+    @Test
+    public void testLoadXml() throws Exception {
+        String resource = "classpath:routes.xml";
+        RoutesLoader loader = Routes.loaderForResource(resource);
+        RouteBuilder builder = loader.load(resource);
+
+        assertThat(loader).isSameAs(RoutesLoaders.Xml);
+        assertThat(builder).isNotNull();
+
+        builder.configure();
+
+        List<RouteDefinition> routes = builder.getRouteCollection().getRoutes();
+        assertThat(routes).hasSize(1);
+        assertThat(routes.get(0).getInputs().get(0).getEndpointUri()).isEqualTo("timer:tick");
+        assertThat(routes.get(0).getOutputs().get(0)).isInstanceOf(ToDefinition.class);
+    }
+
     @Test(expected = IllegalArgumentException.class)
     public void testResourceWithoutScheme() {
         Routes.loaderForResource("routes.js");
diff --git a/runtime/jvm/src/test/resources/routes.xml b/runtime/jvm/src/test/resources/routes.xml
new file mode 100644
index 0000000..b6672f1
--- /dev/null
+++ b/runtime/jvm/src/test/resources/routes.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<routes xmlns="http://camel.apache.org/schema/spring">
+  <route>
+    <from uri="timer:tick"/>
+    <to uri="log:info"/>
+  </route>
+</routes>
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services