cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1150498 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/staxutils/transform/ common/common/src/test/java/org/apache/cxf/staxutils/transform/ rt/core/src/main/java/org/apache/cxf/interceptor/transform/
Date Sun, 24 Jul 2011 22:02:41 GMT
Author: sergeyb
Date: Sun Jul 24 22:02:38 2011
New Revision: 1150498

URL: http://svn.apache.org/viewvc?rev=1150498&view=rev
Log:
CXF-3681: Applying part of the patch on behalf of Andi Kuhtz

Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
    cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java?rev=1150498&r1=1150497&r2=1150498&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
(original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/transform/DelegatingNamespaceContext.java
Sun Jul 24 22:02:38 2011
@@ -50,7 +50,7 @@ class DelegatingNamespaceContext impleme
         
         int i = 0;
         while (true) {
-            if (!prefixes.containsKey("ps" + ++i)) {
+            if (!prefixes.containsValue("ps" + ++i)) {
                 String prefix = "ps" + i;
                 addPrefix(prefix, namespace);
                 return prefix;
@@ -87,6 +87,7 @@ class DelegatingNamespaceContext impleme
         return prefix;
     }
 
+    @SuppressWarnings("unchecked")
     public Iterator getPrefixes(String ns) {
         return nc.getPrefixes(ns);
     }

Modified: cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java?rev=1150498&r1=1150497&r2=1150498&view=diff
==============================================================================
--- cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
(original)
+++ cxf/trunk/common/common/src/test/java/org/apache/cxf/staxutils/transform/InTransformReaderTest.java
Sun Jul 24 22:02:38 2011
@@ -22,11 +22,12 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.cxf.staxutils.StaxUtils;
-
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -60,4 +61,184 @@ public class InTransformReaderTest exten
         assertEquals("<ps1:test xmlns:ps1=\"http://bar\"><subtest xmlns=\"\"/></ps1:test>",
                      value);        
     }
+    
+    @Test
+    public void testReadWithSameNamespace() throws Exception {
+        InputStream is = new ByteArrayInputStream(
+                ("<test xmlns=\"http://bar\" xmlns:ns1=\"http://foo\">" 
+                + "<ns1:subtest>Hello</ns1:subtest></test>").getBytes());
+        XMLStreamReader reader = StaxUtils.createXMLStreamReader(is);
+        
+        Map<String, String> inMap = new HashMap<String, String>();
+        inMap.put("{http://bar}test", "test2");
+        inMap.put("{http://foo}*", "{http://foo}*");
+        
+        reader = new InTransformReader(reader, 
+                                       inMap,
+                                       null, false);
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
+        StaxUtils.copy(reader, bos);
+        String value = bos.toString();
+        assertTrue(("<test2 xmlns=\"\" xmlns:ps1=\"http://foo\">" 
+                + "<ps1:subtest>Hello</ps1:subtest></test2>").equals(value));
       
+    }
+    
+    @Test
+    public void testReadWithComplexRequestSameNamespace() throws Exception {
+        InputStream is = new ByteArrayInputStream(
+                ("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"

+                + "<soap:Header>"
+                + "<ns2:SoapHeaderIn xmlns:ns4=\"http://cxf.apache.org/transform/fault\"
"
+                + "xmlns:ns3=\"http://cxf.apache.org/transform/header/element\" "
+                + "xmlns:ns2=\"http://cxf.apache.org/transform/header\" "
+                + "xmlns=\"http://cxf.apache.org/transform/test\">"
+                + "<ns2:OperationalMode>SIMULATION1</ns2:OperationalMode>"
+                + "<ns2:SomeComplexHeaderType>"
+                + "<ns3:CallerCorrelationId>SomeComplexValue</ns3:CallerCorrelationId>"
+                + "</ns2:SomeComplexHeaderType>"
+                + "</ns2:SoapHeaderIn>"
+                + "</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:ns4=\"http://cxf.apache.org/transform/fault\" />"
+                + "</soap:Body></soap:Envelope>").getBytes());
+        XMLStreamReader reader = StaxUtils.createXMLStreamReader(is);
+        
+        Map<String, String> inMap = new HashMap<String, String>();
+        inMap.put("{http://cxf.apache.org/transform/header/element}*", 
+                "{http://cxf.apache.org/transform/header/element}*");
+        
+        reader = new InTransformReader(reader, 
+                                       inMap,
+                                       null, false);
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
+        StaxUtils.copy(reader, bos);
+        String value = bos.toString();
+        
+        assertTrue(("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+                + "<soap:Header><ns2:SoapHeaderIn xmlns:ns4=\"http://cxf.apache.org/transform/fault\"
"
+                + "xmlns:ps1=\"http://cxf.apache.org/transform/header/element\" "
+                + "xmlns:ns2=\"http://cxf.apache.org/transform/header\" "
+                + "xmlns=\"http://cxf.apache.org/transform/test\">"
+                + "<ns2:OperationalMode>SIMULATION1</ns2:OperationalMode>"
+                + "<ns2:SomeComplexHeaderType>"
+                + "<ps1:CallerCorrelationId>SomeComplexValue</ps1:CallerCorrelationId>"
+                + "</ns2:SomeComplexHeaderType></ns2:SoapHeaderIn></soap:Header><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:ns4=\"http://cxf.apache.org/transform/fault\"/></soap:Body></soap:Envelope>").
+                equals(value.trim()));
+    }
+    
+    @Test
+    public void testReadWithComplexRequestMultipleNamespace() throws Exception {
+        InputStream is = new ByteArrayInputStream(
+                ("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"

+                + "<soap:Header>"
+                + "<ns2:SoapHeaderIn xmlns:ns4=\"http://cxf.apache.org/transform/fault\"
"
+                + "xmlns:ns3=\"http://cxf.apache.org/transform/header/element\" "
+                + "xmlns:ns2=\"http://cxf.apache.org/transform/header\" "
+                + "xmlns=\"http://cxf.apache.org/transform/test\">"
+                + "<ns2:OperationalMode>SIMULATION1</ns2:OperationalMode>"
+                + "<ns2:SomeComplexHeaderType>"
+                + "<ns3:CallerCorrelationId>SomeComplexValue</ns3:CallerCorrelationId>"
+                + "</ns2:SomeComplexHeaderType>"
+                + "</ns2:SoapHeaderIn>"
+                + "</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:ns4=\"http://cxf.apache.org/transform/fault\" />"
+                + "</soap:Body></soap:Envelope>").getBytes());
+        XMLStreamReader reader = StaxUtils.createXMLStreamReader(is);
+        
+        Map<String, String> inMap = new HashMap<String, String>();
+        inMap.put("{http://cxf.apache.org/transform/header/element}*", 
+                "{http://cxf.apache.org/transform/header/otherelement}*");
+        inMap.put("{http://cxf.apache.org/transform/test}*", 
+                "{http://cxf.apache.org/transform/othertest}*");
+        
+        reader = new InTransformReader(reader, 
+                                       inMap,
+                                       null, false);
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
+        StaxUtils.copy(reader, bos);
+        String value = bos.toString();
+        assertTrue(("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+                + "<soap:Header><ns2:SoapHeaderIn xmlns:ns4=\"http://cxf.apache.org/transform/fault\"
"
+                + "xmlns:ps1=\"http://cxf.apache.org/transform/header/otherelement\" "
+                + "xmlns:ns2=\"http://cxf.apache.org/transform/header\" "
+                + "xmlns:ps2=\"http://cxf.apache.org/transform/othertest\">"
+                + "<ns2:OperationalMode>SIMULATION1</ns2:OperationalMode>"
+                + "<ns2:SomeComplexHeaderType>"
+                + "<ps1:CallerCorrelationId>SomeComplexValue</ps1:CallerCorrelationId>"
+                + "</ns2:SomeComplexHeaderType></ns2:SoapHeaderIn></soap:Header><soap:Body>"
+                + "<ps2:TransformTestRequest xmlns:ps2=\"http://cxf.apache.org/transform/othertest\"
"
+                + "xmlns:ns2=\"http://cxf.apache.org/transform/header\" "
+                + "xmlns:ps1=\"http://cxf.apache.org/transform/header/otherelement\" " 
+                + "xmlns:ns4=\"http://cxf.apache.org/transform/fault\"/></soap:Body></soap:Envelope>").
+                equals(value.trim()));
+    }
+    @Test
+    public void testReadWithComplexTransformationNamespace() throws Exception {
+        InputStream is = new ByteArrayInputStream(
+                ("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"

+                + "<soap:Header>"
+                + "<ns2:SoapHeaderIn xmlns:ns4=\"http://cxf.apache.org/transform/fault\"
"
+                + "xmlns:ns3=\"http://cxf.apache.org/transform/header/element\" "
+                + "xmlns:ns2=\"http://cxf.apache.org/transform/header\" "
+                + "xmlns=\"http://cxf.apache.org/transform/test\">"
+                + "<ns2:OperationalMode>SIMULATION1</ns2:OperationalMode>"
+                + "<ns2:SomeComplexHeaderType>"
+                + "<ns3:CallerCorrelationId>SomeComplexValue</ns3:CallerCorrelationId>"
+                + "</ns2:SomeComplexHeaderType>"
+                + "</ns2:SoapHeaderIn>"
+                + "</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:ns4=\"http://cxf.apache.org/transform/fault\" />"
+                + "</soap:Body></soap:Envelope>").getBytes());
+        XMLStreamReader reader = StaxUtils.createXMLStreamReader(is);
+        
+        Map<String, String> inMap = new HashMap<String, String>();
+        inMap.put("{http://cxf.apache.org/transform/header/element}*", 
+                "{http://cxf.apache.org/transform/header/otherelement}*");
+        inMap.put("{http://cxf.apache.org/transform/test}*", 
+                "{http://cxf.apache.org/transform/othertest}*");
+        inMap.put("{http://schemas.xmlsoap.org/soap/envelope/}Envelope", 
+                "{http://schemas.xmlsoap.org/soap/envelope/}TheEnvelope");
+        
+        reader = new InTransformReader(reader, 
+                                       inMap,
+                                       null, false);
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
+        StaxUtils.copy(reader, bos);
+        String value = bos.toString();
+        assertTrue(("<ps1:TheEnvelope xmlns:ps1=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+                + "<soap:Header xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+                + "<ns2:SoapHeaderIn xmlns:ns4=\"http://cxf.apache.org/transform/fault\"
"
+                + "xmlns:ps2=\"http://cxf.apache.org/transform/header/otherelement\" "
+                + "xmlns:ns2=\"http://cxf.apache.org/transform/header\" "
+                + "xmlns:ps3=\"http://cxf.apache.org/transform/othertest\">"
+                + "<ns2:OperationalMode>SIMULATION1</ns2:OperationalMode>"
+                + "<ns2:SomeComplexHeaderType>"
+                + "<ps2:CallerCorrelationId>SomeComplexValue</ps2:CallerCorrelationId>"
+                + "</ns2:SomeComplexHeaderType></ns2:SoapHeaderIn></soap:Header>"
+                + "<soap:Body xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+                + "<ps3:TransformTestRequest xmlns:ps3=\"http://cxf.apache.org/transform/othertest\"
"
+                + "xmlns:ns2=\"http://cxf.apache.org/transform/header\" "
+                + "xmlns:ps2=\"http://cxf.apache.org/transform/header/otherelement\" " 
+                + "xmlns:ns4=\"http://cxf.apache.org/transform/fault\"/></soap:Body></ps1:TheEnvelope>").
+                equals(value.trim()));
+    }
 }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java?rev=1150498&r1=1150497&r2=1150498&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java
Sun Jul 24 22:02:38 2011
@@ -46,7 +46,11 @@ public class TransformInInterceptor exte
     private String contextPropertyName;
     
     public TransformInInterceptor() {
-        super(Phase.POST_STREAM);
+        this(Phase.POST_STREAM);
+    }
+    
+    public TransformInInterceptor(String phase) {
+        super(phase);
         addBefore(StaxInInterceptor.class.getName());
     }
     

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java?rev=1150498&r1=1150497&r2=1150498&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
Sun Jul 24 22:02:38 2011
@@ -52,7 +52,11 @@ public class TransformOutInterceptor ext
     private String contextPropertyName;
     
     public TransformOutInterceptor() {
-        super(Phase.PRE_STREAM);
+        this(Phase.PRE_STREAM);
+    }
+    
+    public TransformOutInterceptor(String phase) {
+        super(phase);
         addBefore(StaxOutInterceptor.class.getName());
     }
     



Mime
View raw message