Repository: camel Updated Branches: refs/heads/master 873720994 -> 22c7edc0c
CAMEL-7839 Fixed the issue that Xpath is not namespace aware in choice Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/22c7edc0 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/22c7edc0 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/22c7edc0 Branch: refs/heads/master Commit: 22c7edc0c25362be1663cb297e6304a7d7518360 Parents: 8737209 Author: Willem Jiang <willem.ji...@gmail.com> Authored: Mon Sep 22 15:05:59 2014 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Mon Sep 22 15:06:11 2014 +0800 ---------------------------------------------------------------------- .../camel/model/ProcessorDefinitionHelper.java | 3 ++ .../model/ProcessorDefinitionHelperTest.java | 6 ++- ...erWithNamespaceOnImportRouteContextTest.java | 38 +++++++++++++++++++ .../xpathChoiceWithNamespaceOnRouteContext.xml | 32 ++++++++++++++++ ...eWithNamespaceOnRouteContextRouteContext.xml | 39 ++++++++++++++++++++ 5 files changed, 116 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/22c7edc0/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java index c94599c..87689a3 100644 --- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java +++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java @@ -220,6 +220,9 @@ public final class ProcessorDefinitionHelper { if (out instanceof ChoiceDefinition) { ChoiceDefinition choice = (ChoiceDefinition) out; for (WhenDefinition when : choice.getWhenClauses()) { + if (type.isInstance(when)) { + found.add((T)when); + } List<ProcessorDefinition<?>> children = when.getOutputs(); doFindType(children, type, found); } http://git-wip-us.apache.org/repos/asf/camel/blob/22c7edc0/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java b/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java index 4aa1d7e..8aa7b0c 100644 --- a/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java +++ b/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java @@ -29,7 +29,9 @@ public class ProcessorDefinitionHelperTest extends ContextTestSupport { Iterator<ProcessorDefinition> it = ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), ProcessorDefinition.class); assertNotNull(it); + assertEquals("whenfoo", it.next().getId()); assertEquals("foo", it.next().getId()); + assertEquals("whenbar", it.next().getId()); assertEquals("bar", it.next().getId()); assertEquals("baz", it.next().getId()); assertFalse(it.hasNext()); @@ -42,8 +44,8 @@ public class ProcessorDefinitionHelperTest extends ContextTestSupport { public void configure() throws Exception { from("direct:start") .choice() - .when(header("foo")).to("mock:foo").id("foo") - .when(header("bar")).to("mock:bar").id("bar") + .when(header("foo")).id("whenfoo").to("mock:foo").id("foo") + .when(header("bar")).id("whenbar").to("mock:bar").id("bar") .otherwise() .to("mock:baz").id("baz"); } http://git-wip-us.apache.org/repos/asf/camel/blob/22c7edc0/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathFilterWithNamespaceOnImportRouteContextTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathFilterWithNamespaceOnImportRouteContextTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathFilterWithNamespaceOnImportRouteContextTest.java new file mode 100644 index 0000000..0a1a42e --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringXPathFilterWithNamespaceOnImportRouteContextTest.java @@ -0,0 +1,38 @@ +/** + * 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.spring.processor; + +import org.apache.camel.CamelContext; +import org.apache.camel.processor.XPathFilterTest; + +import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; + +/** + * + */ +public class SpringXPathFilterWithNamespaceOnImportRouteContextTest extends XPathFilterTest { + + @Override + protected void setUp() throws Exception { + matchingBody = "<person name='James' city='London' xmlns='http://example.com/person'/>"; + super.setUp(); + } + + protected CamelContext createCamelContext() throws Exception { + return createSpringCamelContext(this, "org/apache/camel/spring/processor/xpathChoiceWithNamespaceOnRouteContext.xml"); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/22c7edc0/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xpathChoiceWithNamespaceOnRouteContext.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xpathChoiceWithNamespaceOnRouteContext.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xpathChoiceWithNamespaceOnRouteContext.xml new file mode 100644 index 0000000..d39bd34 --- /dev/null +++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xpathChoiceWithNamespaceOnRouteContext.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:foo="http://example.com/person" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <import resource="xpathChoiceWithNamespaceOnRouteContextRouteContext.xml" /> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + <routeContextRef ref="myCoolRoutes"/> + </camelContext> + + +</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/22c7edc0/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xpathChoiceWithNamespaceOnRouteContextRouteContext.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xpathChoiceWithNamespaceOnRouteContextRouteContext.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xpathChoiceWithNamespaceOnRouteContextRouteContext.xml new file mode 100644 index 0000000..885a837 --- /dev/null +++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/xpathChoiceWithNamespaceOnRouteContextRouteContext.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:foo="http://example.com/person" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <routeContext id="myCoolRoutes" xmlns="http://camel.apache.org/schema/spring"> + + <route> + <from uri="direct:start" /> + <choice> + <when> + <xpath>/foo:person[@name='James']</xpath> + <to uri="mock:result" /> + </when> + </choice> + </route> + + </routeContext> + +</beans> \ No newline at end of file