You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2020/09/25 18:27:55 UTC

[camel] branch master updated: CAMEL-15581: Fix loading of XML rest definitions with camel-main

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

jamesnetherton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new a95d17c  CAMEL-15581: Fix loading of XML rest definitions with camel-main
a95d17c is described below

commit a95d17c772149a0f3c70243a68532272477c5423
Author: James Netherton <ja...@gmail.com>
AuthorDate: Fri Sep 25 16:19:49 2020 +0100

    CAMEL-15581: Fix loading of XML rest definitions with camel-main
---
 core/camel-main/pom.xml                            |  5 ++
 .../apache/camel/main/DefaultRoutesCollector.java  |  2 +-
 .../apache/camel/main/xml/MainXmlRestsTest.java    | 99 ++++++++++++++++++++++
 .../org/apache/camel/main/xml/camel-rests.xml      | 26 ++++++
 4 files changed, 131 insertions(+), 1 deletion(-)

diff --git a/core/camel-main/pom.xml b/core/camel-main/pom.xml
index 8f2cfc9..f4f6c70 100644
--- a/core/camel-main/pom.xml
+++ b/core/camel-main/pom.xml
@@ -115,6 +115,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-undertow</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.logging.log4j</groupId>
             <artifactId>log4j-slf4j-impl</artifactId>
             <scope>test</scope>
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/DefaultRoutesCollector.java b/core/camel-main/src/main/java/org/apache/camel/main/DefaultRoutesCollector.java
index 16e515c..bda912e 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/DefaultRoutesCollector.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/DefaultRoutesCollector.java
@@ -206,7 +206,7 @@ public class DefaultRoutesCollector implements RoutesCollector {
                 Set<InputStream> set = resolver.findResources(part);
                 for (InputStream is : set) {
                     log.debug("Found XML rest from location: {}", part);
-                    RestsDefinition rests = (RestsDefinition) ecc.getXMLRoutesDefinitionLoader().loadRoutesDefinition(ecc, is);
+                    RestsDefinition rests = (RestsDefinition) ecc.getXMLRoutesDefinitionLoader().loadRestsDefinition(ecc, is);
                     if (rests != null) {
                         answer.add(rests);
                         IOHelper.close(is);
diff --git a/core/camel-main/src/test/java/org/apache/camel/main/xml/MainXmlRestsTest.java b/core/camel-main/src/test/java/org/apache/camel/main/xml/MainXmlRestsTest.java
new file mode 100644
index 0000000..76f41ca
--- /dev/null
+++ b/core/camel-main/src/test/java/org/apache/camel/main/xml/MainXmlRestsTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.main.xml;
+
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.main.Main;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.rest.GetVerbDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.model.rest.VerbDefinition;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class MainXmlRestsTest {
+
+    @Test
+    public void testMainRestsCollector() throws Exception {
+        // will load XML from target/classes when testing
+        doTestMain("org/apache/camel/main/xml/camel-rests.xml");
+    }
+
+    @Test
+    public void testMainRestsCollectorScan() throws Exception {
+        // will load XML from target/classes when testing
+        doTestMain("org/apache/camel/main/xml/camel-res*.xml");
+    }
+
+    @Test
+    public void testMainRestsCollectorScanWildcardDirClasspathPath() throws Exception {
+        // will load XML from target/classes when testing
+        doTestMain("org/apache/camel/main/**/camel-res*.xml");
+    }
+
+    @Test
+    public void testMainRestsCollectorScanClasspathPrefix() throws Exception {
+        // will load XML from target/classes when testing
+        doTestMain("classpath:org/apache/camel/main/xml/camel-res*.xml");
+    }
+
+    @Test
+    public void testMainRestsCollectorScanInDir() throws Exception {
+        doTestMain("file:src/test/resources/org/apache/camel/main/xml/camel-res*.xml");
+    }
+
+    @Test
+    public void testMainRestsCollectorScanWildcardDirFilePath() throws Exception {
+        doTestMain("file:src/test/resources/**/camel-res*.xml");
+    }
+
+    @Test
+    public void testMainRestsCollectorFile() throws Exception {
+        doTestMain(
+                "file:src/test/resources/org/apache/camel/main/xml/camel-rests.xml,");
+    }
+
+    protected void doTestMain(String xmlRests) throws Exception {
+        Main main = new Main();
+        main.configure().withXmlRests(xmlRests);
+        main.start();
+
+        CamelContext camelContext = main.getCamelContext();
+        assertNotNull(camelContext);
+
+        List<RestDefinition> restDefinitions = camelContext.adapt(ModelCamelContext.class).getRestDefinitions();
+        assertEquals(1, restDefinitions.size());
+
+        RestDefinition restDefinition = restDefinitions.get(0);
+        assertEquals("bar", restDefinition.getId());
+        assertEquals("/say/hello", restDefinition.getPath());
+
+        List<VerbDefinition> verbs = restDefinition.getVerbs();
+        assertNotNull(verbs);
+        assertEquals(1, verbs.size());
+
+        VerbDefinition verbDefinition = verbs.get(0);
+        assertTrue(verbDefinition instanceof GetVerbDefinition);
+
+        main.stop();
+    }
+}
diff --git a/core/camel-main/src/test/resources/org/apache/camel/main/xml/camel-rests.xml b/core/camel-main/src/test/resources/org/apache/camel/main/xml/camel-rests.xml
new file mode 100644
index 0000000..30a111a
--- /dev/null
+++ b/core/camel-main/src/test/resources/org/apache/camel/main/xml/camel-rests.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+<rests xmlns="http://camel.apache.org/schema/spring">
+    <rest id="bar" path="/say/hello">
+        <get uri="/bar">
+            <to uri="mock:bar"/>
+        </get>
+    </rest>
+</rests>