Author: ay
Date: Wed Mar 27 09:00:28 2013
New Revision: 1461456
URL: http://svn.apache.org/r1461456
Log:
[CXF-4920] TransformationInInterceptor fails when XML contains same namespace
with different prefixes
Added:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2.xml
(with props)
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2In1.xml
(with props)
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn3.xml
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java?rev=1461456&r1=1461455&r2=1461456&view=diff
==============================================================================
---
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
(original)
+++
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
Wed Mar 27 09:00:28 2013
@@ -135,10 +135,11 @@ class DelegatingNamespaceContext impleme
public Iterator<String> getPrefixes(String ns) {
List<String> pl = new LinkedList<String>();
- for (Map<String, String> pfs : prefixes) {
- String pf = pfs.get(ns);
- if (pf != null && ns.equals(getNamespaceURI(pf))) {
- pl.add(pf);
+ for (Map<String, String> nsp : namespaces) {
+ for (Map.Entry<String, String> nse : nsp.entrySet()) {
+ if (ns.equals(nse.getValue()) &&
ns.equals(getNamespaceURI(nse.getKey()))) {
+ pl.add(nse.getKey());
+ }
}
}
return pl.iterator();
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java?rev=1461456&r1=1461455&r2=1461456&view=diff
==============================================================================
---
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
(original)
+++
cxf/trunk/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
Wed Mar 27 09:00:28 2013
@@ -329,6 +329,17 @@ public class InTransformReader extends D
}
}
+ public String getNamespaceURI(String prefix) {
+ String ns = super.getNamespaceURI(prefix);
+
+ String actualNs = nsMap.get(ns);
+ if (actualNs != null) {
+ return actualNs;
+ } else {
+ return ns != null ? ns : namespaceContext.getNamespaceURI(prefix);
+ }
+ }
+
public String getNamespaceURI() {
if (currentEvent != null) {
return currentEvent.getName().getNamespaceURI();
Modified:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml?rev=1461456&r1=1461455&r2=1461456&view=diff
==============================================================================
---
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml
(original)
+++
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml
Wed Mar 27 09:00:28 2013
@@ -32,7 +32,7 @@
<soap:Body>
<TransformTestRequest xmlns="http://cxf.apache.org/transform/test"
xmlns:ns2="http://cxf.apache.org/transform/header"
- xmlns:ps1="http://cxf.apache.org/transform/header/element"
+ xmlns:ns3="http://cxf.apache.org/transform/header/element"
xmlns:ns4="http://cxf.apache.org/transform/fault"/>
</soap:Body>
</soap:Envelope>
Modified:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn3.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn3.xml?rev=1461456&r1=1461455&r2=1461456&view=diff
==============================================================================
---
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn3.xml
(original)
+++
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn3.xml
Wed Mar 27 09:00:28 2013
@@ -31,8 +31,8 @@
</soap:Header>
<soap:Body>
<TransformTestRequest xmlns="http://cxf.apache.org/transform/test"
- xmlns:ns2="http://cxf.apache.org/transform/header"
- xmlns:ns3="http://cxf.apache.org/transform/header/element"
+ xmlns:ns2="http://cxf.apache.org/transform/header/element"
+ xmlns:ns3="http://cxf.apache.org/transform/header"
xmlns:ns4="http://cxf.apache.org/transform/fault"/>
</soap:Body>
</soap:Envelope>
Added:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2.xml?rev=1461456&view=auto
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2.xml
(added)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2.xml
Wed Mar 27 09:00:28 2013
@@ -0,0 +1,23 @@
+<?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.
+-->
+<a:foo xmlns:a="urn:abc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <wireTransfer xmlns:q1="http://bar.com/foobar"
xsi:type="q1:SwiftWireTransfer">10</wireTransfer>
+ <wireTransfer xmlns:q2="http://bar.com/foobar"
xsi:type="q2:SwiftWireTransfer">20</wireTransfer>
+</a:foo>
Propchange:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2In1.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2In1.xml?rev=1461456&view=auto
==============================================================================
---
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2In1.xml
(added)
+++
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2In1.xml
Wed Mar 27 09:00:28 2013
@@ -0,0 +1,24 @@
+<?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.
+-->
+<a:foo xmlns:a="urn:abc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <wireTransfer xmlns:q1="http://bar.com/foo"
xsi:type="q1:SwiftWireTransfer">10</wireTransfer>
+ <wireTransfer xmlns:q2="http://bar.com/foo"
xsi:type="q2:SwiftWireTransfer">20</wireTransfer>
+</a:foo>
+
Propchange:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2In1.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java?rev=1461456&r1=1461455&r2=1461456&view=diff
==============================================================================
---
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
(original)
+++
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
Wed Mar 27 09:00:28 2013
@@ -92,6 +92,27 @@ public class DelegatingNamespaceContextT
}
}
+ @Test
+ public void testSomeAddsWithDuplicatedPrefixName() throws Exception {
+ DelegatingNamespaceContext dnc = getTestDelegatingNamespaceContext();
+
+ dnc.down(); // 1
+ dnc.addPrefix("p00", "urn:foo0");
+ dnc.addPrefix("p1", "urn:foo1");
+ dnc.addPrefix("p2", "urn:foo2");
+ assertEquals("urn:foo0", dnc.getNamespaceURI("p0"));
+ assertEquals("urn:foo0", dnc.getNamespaceURI("p00"));
+ assertEquals("urn:foo1", dnc.getNamespaceURI("p1"));
+ assertEquals("urn:foo2", dnc.getNamespaceURI("p2"));
+ assertTrue("p0".equals(dnc.getPrefix("urn:foo0")) ||
"p00".equals(dnc.getPrefix("urn:foo0")));
+ assertEquals("p1", dnc.getPrefix("urn:foo1"));
+ assertEquals("p2", dnc.getPrefix("urn:foo2"));
+ verifyPrefixes(dnc.getPrefixes("urn:foo1"), new String[] {"p1"});
+ verifyPrefixes(dnc.getPrefixes("urn:foo2"), new String[] {"p2"});
+ verifyPrefixes(dnc.getPrefixes("urn:foo0"), new String[] {"p0",
"p00"});
+ }
+
+
private DelegatingNamespaceContext getTestDelegatingNamespaceContext() {
return new DelegatingNamespaceContext(
new NamespaceContext() {
Modified:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java?rev=1461456&r1=1461455&r2=1461456&view=diff
==============================================================================
---
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
(original)
+++
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
Wed Mar 27 09:00:28 2013
@@ -449,4 +449,15 @@ public class InTransformReaderTest exten
transformElements, null, null, null, null);
}
+ @Test
+ public void testReadNamespaceWithDuplicatePrefixes() throws Exception {
+ Map<String, String> transformElements = new HashMap<String, String>();
+ transformElements.put("{http://bar.com/foo}*",
+ "{http://bar.com/foobar}*");
+
TransformTestUtils.transformInStreamAndCompare("../resources/multiNS2In1.xml",
+
"../resources/multiNS2.xml",
+ transformElements, null, null, null, null);
+
+ }
+
}
Modified:
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java?rev=1461456&r1=1461455&r2=1461456&view=diff
==============================================================================
---
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java
(original)
+++
cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java
Wed Mar 27 09:00:28 2013
@@ -62,7 +62,6 @@ public final class TransformTestUtils {
appendElements,
dropElements,
transformAttributes);
-
XMLStreamReader teacher =
StaxUtils.createXMLStreamReader(
TransformTestUtils.class.getResourceAsStream(outname));
@@ -139,15 +138,16 @@ public final class TransformTestUtils {
break;
}
LOG.fine("Event: " + tevent + " ? " + revent);
- Assert.assertEquals(tevent, revent);
+ Assert.assertEquals("parsing event", tevent, revent);
switch (revent) {
case XMLStreamConstants.START_ELEMENT:
LOG.fine("Start Element " + teacher.getName() + " ? " +
reader.getName());
- Assert.assertEquals(teacher.getName(), reader.getName());
+ Assert.assertEquals("wrong start element.", teacher.getName(),
reader.getName());
if (pfx) {
// verify if the namespace prefix are preserved
- Assert.assertEquals(teacher.getPrefix(),
reader.getPrefix());
+ Assert.assertEquals("wrong start element prefix.",
teacher.getPrefix(), reader.getPrefix());
+ verifyNamespaceDeclarations(teacher, reader);
}
verifyAttributes(teacher, reader);
break;
@@ -155,12 +155,12 @@ public final class TransformTestUtils {
LOG.fine("End Element " + teacher.getName() + " ? " +
reader.getName());
if (eec) {
// perform end-element-check
- Assert.assertEquals(teacher.getName(), reader.getName());
+ Assert.assertEquals("wrong end element qname.",
teacher.getName(), reader.getName());
}
break;
case XMLStreamConstants.CHARACTERS:
LOG.fine("Characters " + teacher.getText() + " ? " +
reader.getText());
- Assert.assertEquals(teacher.getText(), reader.getText());
+ Assert.assertEquals("wrong characteres.", teacher.getText(),
reader.getText());
break;
default:
}
@@ -178,10 +178,20 @@ public final class TransformTestUtils {
// compares each attribute
for (int i = 0; i < acount; i++) {
String avalue = attributesMap.remove(teacher.getAttributeName(i));
- Assert.assertEquals(avalue, teacher.getAttributeValue(i));
+ Assert.assertEquals("attribute " + teacher.getAttributeName(i) + "
has wrong value.",
+ teacher.getAttributeValue(i), avalue);
}
// attributes must be exhausted
- Assert.assertTrue(attributesMap.isEmpty());
+ Assert.assertTrue("attributes must be exhausted.",
attributesMap.isEmpty());
+ }
+
+ private static void verifyNamespaceDeclarations(XMLStreamReader teacher,
XMLStreamReader reader) {
+ int dcount = teacher.getNamespaceCount();
+ for (int i = 0; i < dcount; i++) {
+ String p = teacher.getNamespacePrefix(i);
+ Assert.assertEquals("nsdecl prefix " + p + " is incorrectly
bound.",
+ teacher.getNamespaceURI(i),
reader.getNamespaceURI(p));
+ }
}
/**