This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 06046c193cae0baebad63c8b0a164978fbcd9ade Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Fri Jan 12 14:07:34 2018 +0100 CAMEL-11599: XPath with Saxon should load Saxon using their preferred way. --- .../org/apache/camel/builder/xml/XPathBuilder.java | 9 ++-- .../org/apache/camel/itest/CamelSaxonTest.java | 59 ++++++++++++++++++++++ .../org/apache/camel/itest/CamelSaxonTest.xml | 46 +++++++++++++++++ 3 files changed, 110 insertions(+), 4 deletions(-) diff --git a/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java index 165842f..0f7f0d7 100644 --- a/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java +++ b/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java @@ -1274,25 +1274,26 @@ public class XPathBuilder extends ServiceSupport implements CamelContextAware, E if (camelContext != null) { Class<XPathFactory> clazz = camelContext.getClassResolver().resolveClass(SAXON_FACTORY_CLASS_NAME, XPathFactory.class); if (clazz != null) { + LOG.debug("Creating Saxon XPathFactory using class: {})", clazz); xpathFactory = camelContext.getInjector().newInstance(clazz); - LOG.debug("Created Saxon XPathFactory: {}", xpathFactory); + LOG.info("Created Saxon XPathFactory: {}", xpathFactory); } } } catch (Throwable e) { LOG.warn("Attempted to create Saxon XPathFactory by creating a new instance of " + SAXON_FACTORY_CLASS_NAME - + " failed. Will fallback and create XPathFactory via JDK API. This exception is ignored (stacktrace in DEBUG logging level)."); + + " failed. Will fallback and create XPathFactory using JDK API. This exception is ignored (stacktrace in DEBUG logging level)."); LOG.debug("Error creating Saxon XPathFactory. This exception is ignored.", e); } } if (xpathFactory == null) { - LOG.debug("Creating XPathFactory via JDK API using objectModelUri", objectModelUri); + LOG.debug("Creating XPathFactory from objectModelUri: {}", objectModelUri); xpathFactory = ObjectHelper.isEmpty(xpathFactoryClassName) ? XPathFactory.newInstance(objectModelUri) : XPathFactory.newInstance(objectModelUri, xpathFactoryClassName, null); + LOG.info("Created XPathFactory: {} from objectModelUri: {}", xpathFactory, objectModelUri); } - LOG.info("Using objectModelUri " + objectModelUri + " when created XPathFactory {}", xpathFactory); return xpathFactory; } diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelSaxonTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelSaxonTest.java new file mode 100644 index 0000000..7b0d9ec --- /dev/null +++ b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelSaxonTest.java @@ -0,0 +1,59 @@ +/** + * 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.itest; + +import java.net.URL; + +import org.apache.camel.CamelContext; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.karaf.AbstractFeatureTest; +import org.apache.camel.test.karaf.CamelKarafTestSupport; +import org.apache.camel.util.ObjectHelper; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; + +@RunWith(PaxExam.class) +public class CamelSaxonTest extends AbstractFeatureTest { + + @Test + public void testCamelSaxon() throws Exception { + // install the camel blueprint xml file we use in this test + URL url = ObjectHelper.loadResourceAsURL("org/apache/camel/itest/CamelSaxonTest.xml", CamelSaxonTest.class.getClassLoader()); + installBlueprintAsBundle("CamelSaxonTest", url, true); + + // lookup Camel from OSGi + CamelContext camel = getOsgiService(bundleContext, CamelContext.class); + + // test camel + MockEndpoint mock = camel.getEndpoint("mock:camel", MockEndpoint.class); + mock.expectedBodiesReceived("<name>King</name>"); + mock.expectedHeaderReceived("type", "Camel"); + + camel.createProducerTemplate().sendBodyAndHeader("direct:in", "<name>King</name>", "type", "Camel"); + + mock.assertIsSatisfied(); + } + + @Configuration + public Option[] configure() { + return CamelKarafTestSupport.configure("camel-test-karaf", "camel-saxon"); + } + +} diff --git a/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelSaxonTest.xml b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelSaxonTest.xml new file mode 100644 index 0000000..dff03e5 --- /dev/null +++ b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelSaxonTest.xml @@ -0,0 +1,46 @@ +<?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. + +--> +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + + <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/blueprint"> + + <route> + <from uri="direct:in"/> + <choice> + <when> + <xpath saxon="true">$type = 'Camel'</xpath> + <to uri="mock:camel"/> + </when> + <when> + <xpath saxon="true">//name = 'Kong'</xpath> + <to uri="mock:donkey"/> + </when> + <otherwise> + <to uri="mock:other"/> + </otherwise> + </choice> + </route> + + </camelContext> + +</blueprint> -- To stop receiving notification emails like this one, please contact "commits@camel.apache.org" <commits@camel.apache.org>.