Repository: camel Updated Branches: refs/heads/camel-2.16.x 025567f11 -> a6b710e8d
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/a0195057 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a0195057 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a0195057 Branch: refs/heads/camel-2.16.x Commit: a01950575c99445f27eef1d4accc6306d7918169 Parents: 025567f 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:49:47 2016 +0200 ---------------------------------------------------------------------- .../converter/DelegatingXMLStreamReader.java | 9 ++++- ...nsumerDuplicateNamespaceStreamCacheTest.java | 38 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/a0195057/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 743a671..005aaed 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 @@ -40,7 +40,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/a0195057/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")); + } +}