Repository: camel
Updated Branches:
  refs/heads/master 25eb29eae -> 0ee67aa36


CAMEL-9854: CXF Stream Cache contains duplicate namespace definition


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a37ecccd
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a37ecccd
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a37ecccd

Branch: refs/heads/master
Commit: a37ecccdacf7e5b57422bfebab90e9da5f4352a3
Parents: 25eb29e
Author: Stephan Siano <stephan.si...@sap.com>
Authored: Mon Apr 11 13:54:21 2016 +0200
Committer: Akitoshi Yoshida <a...@apache.org>
Committed: Fri Apr 15 21:32:38 2016 +0200

----------------------------------------------------------------------
 .../converter/DelegatingXMLStreamReader.java    | 10 +++++-
 ...nsumerDuplicateNamespaceStreamCacheTest.java | 38 ++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a37ecccd/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/DelegatingXMLStreamReader.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/DelegatingXMLStreamReader.java
 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/DelegatingXMLStreamReader.java
index 9964ba4..408f8f2 100644
--- 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/DelegatingXMLStreamReader.java
+++ 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/DelegatingXMLStreamReader.java
@@ -18,6 +18,7 @@
 package org.apache.camel.component.cxf.converter;
 
 import java.util.Map;
+import java.util.Set;
 
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
@@ -36,7 +37,14 @@ class DelegatingXMLStreamReader implements XMLStreamReader {
 
     public DelegatingXMLStreamReader(XMLStreamReader reader, Map<String, 
String> nsmap) {
         this.reader = reader;
-        this.xprefixes = nsmap.keySet().toArray(new String[0]);
+        Set<String> prefixes = nsmap.keySet();
+        for (int i = 0; i < reader.getNamespaceCount(); i++) {
+            String prefix = reader.getNamespacePrefix(i);
+            if (prefixes.contains(prefix)) {
+                prefixes.remove(prefix);
+            }
+        }
+        this.xprefixes = prefixes.toArray(new String[0]);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/a37ecccd/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayloadConsumerDuplicateNamespaceStreamCacheTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayloadConsumerDuplicateNamespaceStreamCacheTest.java
 
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayloadConsumerDuplicateNamespaceStreamCacheTest.java
new file mode 100644
index 0000000..ace11a7
--- /dev/null
+++ 
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayloadConsumerDuplicateNamespaceStreamCacheTest.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.component.cxf;
+
+import org.junit.Test;
+
+public class CxfPayloadConsumerDuplicateNamespaceStreamCacheTest extends 
CxfPayloadConsumerNamespaceOnEnvelopeStreamCacheTest {
+    /*
+     * The soap namespace prefix is already defined on the root tag of the
+     * payload. If this is set another time from the envelope, the result will
+     * be an invalid XML.
+     */
+    protected static final String REQUEST_MESSAGE = "<soap:Envelope 
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"; 
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"; 
xmlns:xs=\"http://www.w3.org/2001/XMLSchema\";>"
+                                                    + 
"<soap:Body><ns2:getToken 
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"; 
xmlns:ns2=\"http://camel.apache.org/cxf/namespace\";><arg0 
xsi:type=\"xs:string\">Send</arg0></ns2:getToken></soap:Body></soap:Envelope>";
+
+    @Test
+    public void testInvokeRouter() {
+        Object returnValue = template.requestBody("direct:router", 
REQUEST_MESSAGE);
+        assertNotNull(returnValue);
+        assertTrue(returnValue instanceof String);
+        assertTrue(((String) returnValue).contains("Return Value"));
+        assertTrue(((String) 
returnValue).contains("http://www.w3.org/2001/XMLSchema-instance";));
+    }
+}

Reply via email to