You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/12/23 18:18:00 UTC

[2/2] camel git commit: 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.

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/437ade9c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/437ade9c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/437ade9c

Branch: refs/heads/camel-2.18.x
Commit: 437ade9c09492557bf907dddbca847f8975e231f
Parents: 26c79c2
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Dec 23 19:17:08 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Dec 23 19:17:51 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/437ade9c/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/437ade9c/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