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 2018/08/16 15:26:15 UTC

[camel] 02/03: CAMEL-12735: Fixed XMlRouteParser to strip namespace prefix so the parser can find endpoints etc.

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

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

commit 3cfc783e542094b28485fe65f4c7bb338e077350
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 16 16:36:07 2018 +0200

    CAMEL-12735: Fixed XMlRouteParser to strip namespace prefix so the parser can find endpoints etc.
---
 .../apache/camel/parser/helper/XmlLineNumberParser.java   |  8 ++++++--
 .../java/org/apache/camel/parser/xml/XmlRouteTest.java    | 15 +++++++--------
 .../camel/parser/xml/mycamel-withNamespacePrefix.xml      |  7 ++++++-
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/XmlLineNumberParser.java b/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/XmlLineNumberParser.java
index 35eae1c..407f3df 100644
--- a/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/XmlLineNumberParser.java
+++ b/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/XmlLineNumberParser.java
@@ -125,12 +125,16 @@ public final class XmlLineNumberParser {
                     }
                 }
 
+                // strip namespace prefix
+                int pos = qName.indexOf(':');
+                String lNane = pos > 0 ? qName.substring(pos + 1) : qName;
+
                 if (found) {
                     Element el;
                     if (forceNamespace != null) {
-                        el = doc.createElementNS(forceNamespace, qName);
+                        el = doc.createElementNS(forceNamespace, lNane);
                     } else {
-                        el = doc.createElement(qName);
+                        el = doc.createElement(lNane);
                     }
 
                     for (int i = 0; i < attributes.getLength(); i++) {
diff --git a/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/xml/XmlRouteTest.java b/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/xml/XmlRouteTest.java
index 3f3b853..a388b7f 100644
--- a/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/xml/XmlRouteTest.java
+++ b/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/xml/XmlRouteTest.java
@@ -17,7 +17,6 @@
 package org.apache.camel.parser.xml;
 
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
@@ -35,19 +34,19 @@ public class XmlRouteTest {
 
     @Test
     public void testXml() throws Exception {
-    	test("mycamel");
+        test("mycamel");
     }
 
     @Test
     public void testXmlWithNamespacePrefix() throws Exception {
-    	test("mycamel-withNamespacePrefix");
+        test("mycamel-withNamespacePrefix");
     }
-    
-	private void test(String filename) throws FileNotFoundException, Exception {
-		List<CamelEndpointDetails> endpoints = new ArrayList<>();
 
-		InputStream is = new FileInputStream("src/test/resources/org/apache/camel/parser/xml/"+filename+".xml");
-        String fqn = "src/test/resources/org/apache/camel/camel/parser/xml/"+filename+".xml";
+    private void test(String filename) throws Exception {
+        List<CamelEndpointDetails> endpoints = new ArrayList<>();
+
+        InputStream is = new FileInputStream("src/test/resources/org/apache/camel/parser/xml/" + filename + ".xml");
+        String fqn = "src/test/resources/org/apache/camel/camel/parser/xml/" + filename + ".xml";
         String baseDir = "src/test/resources";
         XmlRouteParser.parseXmlRouteEndpoints(is, baseDir, fqn, endpoints);
 
diff --git a/tooling/camel-route-parser/src/test/resources/org/apache/camel/parser/xml/mycamel-withNamespacePrefix.xml b/tooling/camel-route-parser/src/test/resources/org/apache/camel/parser/xml/mycamel-withNamespacePrefix.xml
index 345969c..54479a8 100644
--- a/tooling/camel-route-parser/src/test/resources/org/apache/camel/parser/xml/mycamel-withNamespacePrefix.xml
+++ b/tooling/camel-route-parser/src/test/resources/org/apache/camel/parser/xml/mycamel-withNamespacePrefix.xml
@@ -18,8 +18,13 @@
 
 -->
 <beans xmlns="http://www.springframework.org/schema/beans"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
     <!-- START SNIPPET: e1 -->
+
     <!-- camelContext is the Camel runtime, where we can host Camel routes -->
     <camel:camelContext id="camelContext-4456db4f-45bb-4aa4-8698-10823e239dbc" xmlns:camel="http://camel.apache.org/schema/spring">
         <camel:route id="myRoute">