camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: CAMEL-10817: Prevent duplicated xmlns namespace prefix when dumping model XML
Date Mon, 13 Feb 2017 09:05:32 GMT
CAMEL-10817: Prevent duplicated xmlns namespace prefix when dumping model XML


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

Branch: refs/heads/camel-2.18.x
Commit: 34cf6b9ebf36e1aae9e52a06881b2dfea9781c73
Parents: a01363c
Author: James Netherton <jamesnetherton@gmail.com>
Authored: Mon Feb 13 08:43:58 2017 +0000
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Feb 13 10:05:22 2017 +0100

----------------------------------------------------------------------
 .../org/apache/camel/model/ModelHelper.java     |  3 +-
 .../DuplicateNamespacePrefixIssueTest.java      | 70 ++++++++++++++++++++
 2 files changed, 72 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/34cf6b9e/camel-core/src/main/java/org/apache/camel/model/ModelHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ModelHelper.java b/camel-core/src/main/java/org/apache/camel/model/ModelHelper.java
index db40f63..1fbad55 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ModelHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ModelHelper.java
@@ -96,7 +96,8 @@ public final class ModelHelper {
         // Add additional namespaces to the document root element
         Element documentElement = dom.getDocumentElement();
         for (String nsPrefix : namespaces.keySet()) {
-            documentElement.setAttribute("xmlns:" + nsPrefix, namespaces.get(nsPrefix));
+            String prefix = nsPrefix.equals("xmlns") ? nsPrefix : "xmlns:" + nsPrefix;
+            documentElement.setAttribute(prefix, namespaces.get(nsPrefix));
         }
 
         // We invoke the type converter directly because we need to pass some custom XML
output options

http://git-wip-us.apache.org/repos/asf/camel/blob/34cf6b9e/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/issues/DuplicateNamespacePrefixIssueTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/issues/DuplicateNamespacePrefixIssueTest.java
b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/issues/DuplicateNamespacePrefixIssueTest.java
new file mode 100644
index 0000000..0e42bf5
--- /dev/null
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/issues/DuplicateNamespacePrefixIssueTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.itest.karaf.issues;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.blueprint.BlueprintCamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.itest.karaf.BaseKarafTest;
+import org.apache.camel.model.ModelHelper;
+import org.apache.camel.model.RoutesDefinition;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+/**
+ * CAMEL-10817: dumpModelAsXml can return invalid XML namespace xmlns:xmlns
+ */
+
+@RunWith(PaxExam.class)
+public class DuplicateNamespacePrefixIssueTest extends BaseKarafTest {
+
+    @Test
+    public void testRoutesNamespacePrefixesNotDuplicated() throws Exception {
+        CamelContext context = new BlueprintCamelContext(bundleContext, blueprintContainer);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:foo").id("foo")
+                    .choice()
+                        .when(xpath("foo:foo/foo:foo = 'foo'"))
+                            .log("Matched foo")
+                        .when(xpath("foo:foo/foo:bar = 'bar'"))
+                            .log("Matched bar")
+                        .when(xpath("foo:foo/foo:cheese = 'cheese'"))
+                            .log("Matched cheese");
+            }
+        });
+
+        // Dump the model XML
+        String originalModelXML = ModelHelper.dumpModelAsXml(context, context.getRouteDefinition("foo"));
+
+        // Reload routes from dumped XML
+        InputStream stream = new ByteArrayInputStream(originalModelXML.getBytes("UTF-8"));
+        RoutesDefinition routesDefinition = ModelHelper.loadRoutesDefinition(context, stream);
+
+        // Verify namespaces are as we expect
+        String modifiedModelXML = ModelHelper.dumpModelAsXml(context, routesDefinition);
+        String modifiedRoutesElementXML = modifiedModelXML.split("\n")[1];
+        String expectedRoutesElementXML = "<routes xmlns=\"http://camel.apache.org/schema/spring\">";
+        Assert.assertEquals(expectedRoutesElementXML, modifiedRoutesElementXML);
+    }
+}


Mime
View raw message