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 2014/01/28 17:27:22 UTC

[1/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.

Updated Branches:
  refs/heads/camel-2.11.x d5e7d2567 -> aa33f1be1
  refs/heads/camel-2.12.x af575cb54 -> aae06ee64
  refs/heads/master 1bfb73d27 -> 9542d07c8


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/09aab55b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/09aab55b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/09aab55b

Branch: refs/heads/master
Commit: 09aab55b0df69133ad0cb0ce707c18d73c1379a7
Parents: 1bfb73d
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jan 28 16:44:23 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 28 16:44:23 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/09aab55b/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/09aab55b/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;
+    }
+
+}


[2/4] git commit: Fixed test due recent test added in camel-core

Posted by da...@apache.org.
Fixed test due recent test added in camel-core


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

Branch: refs/heads/master
Commit: 9542d07c8ede3fbb99cc6f5fb52e8b63b8b7c90e
Parents: 09aab55
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jan 28 17:16:56 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 28 17:16:56 2014 +0100

----------------------------------------------------------------------
 .../resources/org/apache/camel/spring/processor/delayer.xml  | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9542d07c/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml
index 27907cc..0193561 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/delayer.xml
@@ -24,6 +24,7 @@
 
     <!-- START SNIPPET: example -->
     <bean id="myDelayBean" class="org.apache.camel.processor.MyDelayCalcBean"/>
+    <bean id="exchangeAwareBean" class="org.apache.camel.processor.ExchangeAwareDelayCalcBean"/>
 
     <camelContext xmlns="http://camel.apache.org/schema/spring">
         <route>
@@ -47,6 +48,13 @@
             </delay>
             <to uri="mock:result"/>
         </route>
+        <route>
+            <from uri="seda:d"/>
+            <delay>
+                <method ref="exchangeAwareBean" method="delayMe"/>
+            </delay>
+            <to uri="mock:result"/>
+        </route>
     </camelContext>
     <!-- END SNIPPET: example -->
 


[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.

Posted by da...@apache.org.
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 <da...@apache.org>
Authored: Tue Jan 28 16:44:23 2014 +0100
Committer: Claus Ibsen <da...@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;
+    }
+
+}


[4/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.

Posted by da...@apache.org.
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/aa33f1be
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/aa33f1be
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/aa33f1be

Branch: refs/heads/camel-2.11.x
Commit: aa33f1be1a4f82863acf84df7608cd1927e79eb8
Parents: d5e7d25
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jan 28 16:44:23 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 28 17:27:51 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/aa33f1be/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 c822cfa..0ff2ba7 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
@@ -720,7 +720,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/aa33f1be/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;
+    }
+
+}