Repository: camel Updated Branches: refs/heads/camel-2.18.x 26c79c2d7 -> 437ade9c0 refs/heads/master 281528256 -> e5b2d7658
CAMEL-10653: Fix NPE issue with null header values for camel-saxon after upgrade to 9.7 api. Thanks to Nikolay Voskresenskiy for reporting and unit test. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e5b2d765 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e5b2d765 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e5b2d765 Branch: refs/heads/master Commit: e5b2d7658236f910c36eddce72bc555326b31cdb Parents: 2815282 Author: Claus Ibsen <davscl...@apache.org> Authored: Fri Dec 23 19:17:08 2016 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Dec 23 19:17:25 2016 +0100 ---------------------------------------------------------------------- .../camel/component/xquery/XQueryBuilder.java | 12 +++-- .../component/xquery/XQueryNullHeaderTest.java | 56 ++++++++++++++++++++ 2 files changed, 63 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/e5b2d765/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java ---------------------------------------------------------------------- diff --git a/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java b/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java index 29ed896..a4c61d9 100644 --- a/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java +++ b/components/camel-saxon/src/main/java/org/apache/camel/component/xquery/XQueryBuilder.java @@ -639,10 +639,13 @@ public abstract class XQueryBuilder implements Expression, Predicate, NamespaceA protected void addParameters(DynamicQueryContext dynamicQueryContext, Map<String, Object> map, String parameterPrefix) { Set<Map.Entry<String, Object>> propertyEntries = map.entrySet(); for (Map.Entry<String, Object> entry : propertyEntries) { - dynamicQueryContext.setParameter( - StructuredQName.fromClarkName(parameterPrefix + entry.getKey()), - new ObjectValue(entry.getValue()) - ); + // skip headers with null values + if (entry.getValue() != null) { + dynamicQueryContext.setParameter( + StructuredQName.fromClarkName(parameterPrefix + entry.getKey()), + new ObjectValue(entry.getValue()) + ); + } } } @@ -659,7 +662,6 @@ public abstract class XQueryBuilder implements Expression, Predicate, NamespaceA LOG.debug("Initializing XQueryBuilder {}", this); if (configuration == null) { configuration = new Configuration(); - //configuration.setHostLanguage(Configuration.XQUERY); configuration.setStripsWhiteSpace(isStripsAllWhiteSpace() ? Whitespace.ALL : Whitespace.IGNORABLE); LOG.debug("Created new Configuration {}", configuration); } else { http://git-wip-us.apache.org/repos/asf/camel/blob/e5b2d765/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryNullHeaderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryNullHeaderTest.java b/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryNullHeaderTest.java new file mode 100644 index 0000000..969fd62 --- /dev/null +++ b/components/camel-saxon/src/test/java/org/apache/camel/component/xquery/XQueryNullHeaderTest.java @@ -0,0 +1,56 @@ +/** + * 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.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.spring.CamelSpringTestSupport; +import org.junit.Test; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @version + */ +public class XQueryNullHeaderTest extends CamelSpringTestSupport { + + @Test + public void testHeader() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("<employee id=\"James\"><name><firstName>James</firstName>" + + "<lastName>Strachan</lastName></name><location><city>London</city></location></employee>"); + + template.sendBodyAndHeader("direct:start", "<person user='James'><firstName>James</firstName>" + + "<lastName>Strachan</lastName><city>London</city></person>", "foo", "123"); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testHeaderWithNull() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("<employee id=\"James\"><name><firstName>James</firstName>" + + "<lastName>Strachan</lastName></name><location><city>London</city></location></employee>"); + + template.sendBodyAndHeader("direct:start", "<person user='James'><firstName>James</firstName>" + + "<lastName>Strachan</lastName><city>London</city></person>", "foo", null); + + assertMockEndpointsSatisfied(); + } + + protected ClassPathXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/xquery/xqueryExampleTest.xml"); + } +} \ No newline at end of file