camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/4] git commit: CAMEL-6922: Fixed xml converter toDocument to support a fallback as depending on JDK/os the TC lookup may pick method with from type as Node or NodeList. Thanks to Rene Avontuur for patch.
Date Tue, 28 Jan 2014 16:27:24 GMT
CAMEL-6922: Fixed xml converter toDocument to support a fallback as depending on JDK/os the
TC lookup may pick method with from type as Node or NodeList. Thanks to Rene Avontuur for
patch.


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

Branch: refs/heads/camel-2.12.x
Commit: aae06ee647f8acdeae34dde6d96b7206c983d98a
Parents: af575cb
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Jan 28 16:44:23 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Jan 28 17:27:36 2014 +0100

----------------------------------------------------------------------
 .../camel/converter/jaxp/XmlConverter.java      | 10 +++-
 .../builder/xml/NodeListToDocumentTest.java     | 57 ++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/aae06ee6/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java b/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
index ca3df7d..b382ca5 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
@@ -690,7 +690,15 @@ public class XmlConverter {
      */
     @Converter(allowNull = true)
     public Document toDOMDocumentFromSingleNodeList(NodeList nl) throws ParserConfigurationException,
TransformerException {
-        return nl.getLength() == 1 ? toDOMDocument(nl.item(0)) : null;
+        if (nl.getLength() == 1) {
+            return toDOMDocument(nl.item(0));
+        } else if (nl instanceof Node) {
+            // as XML parsers may often have nodes that implement both Node and NodeList
then the type converter lookup
+            // may lookup either a type converter from NodeList or Node. So let's fallback
and try with Node
+            return toDOMDocument((Node) nl);
+        } else {
+            return null;
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/aae06ee6/camel-core/src/test/java/org/apache/camel/builder/xml/NodeListToDocumentTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/builder/xml/NodeListToDocumentTest.java
b/camel-core/src/test/java/org/apache/camel/builder/xml/NodeListToDocumentTest.java
new file mode 100644
index 0000000..b370307
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/builder/xml/NodeListToDocumentTest.java
@@ -0,0 +1,57 @@
+/**
+ * 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.builder.xml;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+//import com.sun.org.apache.xerces.internal.dom.ElementNSImpl;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.junit.Ignore;
+
+import static org.apache.camel.builder.xml.XPathBuilder.xpath;
+
+@Ignore("For manual testing CAMEL-6922")
+public class NodeListToDocumentTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testXPathNodeResultToDocument() throws Exception {
+        // TODO: uses an internal nexus class which can only be tested on some platforms
+        /*
+        Object result = xpath("/foo").nodeResult().evaluate(createExchange("<foo><bar>1</bar><bar>2</bar></foo>"));
+        ElementNSImpl el = assertIsInstanceOf(ElementNSImpl.class, result);
+        assertNotNull(el);
+        NodeList nodeList = (NodeList) el;
+        assertEquals(0, nodeList.getLength());
+        Document doc = context.getTypeConverter().convertTo(Document.class, nodeList);
+        assertNotNull(doc);
+        assertEquals("foo", doc.getFirstChild().getLocalName());
+        */
+    }
+
+    protected Exchange createExchange(Object xml) {
+        Exchange exchange = createExchangeWithBody(context, xml);
+        exchange.getIn().setHeader("name", "James");
+        return exchange;
+    }
+
+}


Mime
View raw message