Author: ningjiang Date: Mon Feb 6 09:41:44 2012 New Revision: 1240950 URL: http://svn.apache.org/viewvc?rev=1240950&view=rev Log: CAMEL-4970 Fixed the issue that cannot use xquery predicate in filter after an xpath splitter
Added: camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryPredicateFilterTest.java (with props) Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java?rev=1240950&r1=1240949&r2=1240950&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java Mon Feb 6 09:41:44 2012 @@ -171,24 +171,37 @@ public class XmlConverter { */ @Deprecated public DOMSource toSource(Document document) { - return toDOMSource(document); + return new DOMSource(document); } /** * Converts the given Node to a Source + * @throws TransformerException + * @throws ParserConfigurationException * @deprecated use toDOMSource instead */ @Deprecated - public Source toSource(Node node) { + public Source toSource(Node node) throws ParserConfigurationException, TransformerException { return toDOMSource(node); } /** * Converts the given Node to a Source + * @throws TransformerException + * @throws ParserConfigurationException */ @Converter - public DOMSource toDOMSource(Node node) { - return new DOMSource(node); + public DOMSource toDOMSource(Node node) throws ParserConfigurationException, TransformerException { + Document document = toDOMDocument(node); + return new DOMSource(document); + } + + /** + * Converts the given Document to a DOMSource + */ + @Converter + public DOMSource toDOMSource(Document document) { + return new DOMSource(document); } /** Added: camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryPredicateFilterTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryPredicateFilterTest.java?rev=1240950&view=auto ============================================================================== --- camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryPredicateFilterTest.java (added) +++ camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryPredicateFilterTest.java Mon Feb 6 09:41:44 2012 @@ -0,0 +1,68 @@ +/** + * 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.component.xquery; + +import org.w3c.dom.Document; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.builder.xml.XPathBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class XQueryPredicateFilterTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:result") + protected MockEndpoint resultEndpoint; + + @Produce(uri = "direct:xpath") + protected ProducerTemplate template; + + @Test + public void testXQuerySplitter() throws Exception { + resultEndpoint.expectedMessageCount(1); + template.sendBody("<records><record><type>1</type></record><record><type>2</type></record></records>"); + resultEndpoint.assertIsSatisfied(); + + resultEndpoint.reset(); + template.sendBody("<records><record><type>3</type></record><record><type>4</type></record></records>"); + resultEndpoint.expectedMessageCount(0); + resultEndpoint.assertIsSatisfied(); + } + + + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + + XPathBuilder splitter = new XPathBuilder("//records/record"); + + context.setTracing(true); + + from("direct:xpath").split(splitter).filter().xquery("//record[type=2]") + .to("mock:result"); + + } + }; + } + +} Propchange: camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryPredicateFilterTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryPredicateFilterTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date