cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1461461 - in /cxf/branches/2.7.x-fixes: ./ api/src/main/java/org/apache/cxf/staxutils/transform/ api/src/test/java/org/apache/cxf/staxutils/resources/ api/src/test/java/org/apache/cxf/staxutils/transform/
Date Wed, 27 Mar 2013 09:13:15 GMT
Author: ay
Date: Wed Mar 27 09:13:14 2013
New Revision: 1461461

URL: http://svn.apache.org/r1461461
Log:
Merged revisions 1461456 via  svn merge from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1461456 | ay | 2013-03-27 10:00:28 +0100 (Wed, 27 Mar 2013) | 1 line
  
  [CXF-4920] TransformationInInterceptor fails when XML contains same namespace with different
prefixes
........

Added:
    cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2.xml
      - copied unchanged from r1461456, cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2.xml
    cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2In1.xml
      - copied unchanged from r1461456, cxf/trunk/api/src/test/java/org/apache/cxf/staxutils/resources/multiNS2In1.xml
Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
    cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
    cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml
    cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn3.xml
    cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
    cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
    cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java

Propchange: cxf/branches/2.7.x-fixes/
            ('svn:mergeinfo' removed)

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java?rev=1461461&r1=1461460&r2=1461461&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
(original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
Wed Mar 27 09:13:14 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/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java?rev=1461461&r1=1461460&r2=1461461&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
(original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/transform/InTransformReader.java
Wed Mar 27 09:13:14 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/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml?rev=1461461&r1=1461460&r2=1461461&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml
(original)
+++ cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/complexReq1.xml
Wed Mar 27 09:13:14 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/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn3.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn3.xml?rev=1461461&r1=1461460&r2=1461461&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn3.xml
(original)
+++ cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/resources/complexReqIn3.xml
Wed Mar 27 09:13:14 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>

Modified: cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java?rev=1461461&r1=1461460&r2=1461461&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
(original)
+++ cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContextTest.java
Wed Mar 27 09:13:14 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/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java?rev=1461461&r1=1461460&r2=1461461&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
(original)
+++ cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
Wed Mar 27 09:13:14 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/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java?rev=1461461&r1=1461460&r2=1461461&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java
(original)
+++ cxf/branches/2.7.x-fixes/api/src/test/java/org/apache/cxf/staxutils/transform/TransformTestUtils.java
Wed Mar 27 09:13:14 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));
+        }
     }
 
     /**



Mime
View raw message