Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 57E2510968 for ; Tue, 28 Jan 2014 16:27:30 +0000 (UTC) Received: (qmail 30047 invoked by uid 500); 28 Jan 2014 16:27:25 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 29900 invoked by uid 500); 28 Jan 2014 16:27:23 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 29436 invoked by uid 99); 28 Jan 2014 16:27:22 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Jan 2014 16:27:22 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 2561690A0D0; Tue, 28 Jan 2014 16:27:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Tue, 28 Jan 2014 16:27:24 -0000 Message-Id: <0eb0380dde184e078d10f8ef254021a3@git.apache.org> In-Reply-To: <98cba4dfd3ab43a0bb1129ee8f4c0785@git.apache.org> References: <98cba4dfd3ab43a0bb1129ee8f4c0785@git.apache.org> X-Mailer: ASF-Git Admin Mailer 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. 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 Authored: Tue Jan 28 16:44:23 2014 +0100 Committer: Claus Ibsen 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("12")); + 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; + } + +}