cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1561774 - in /cxf/trunk: core/src/main/java/org/apache/cxf/staxutils/ rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/ systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/ systests/ws-security/src/test/java/org/apa...
Date Mon, 27 Jan 2014 18:29:53 GMT
Author: dkulp
Date: Mon Jan 27 18:29:53 2014
New Revision: 1561774

URL: http://svn.apache.org/r1561774
Log:
[CXF-5527] Update the SAAJStreamWriter to use the SAAJ methods to create children of Body
and Header so that they end up as the proper SOAPHeaderElement or SOAPBodyElement types immediately.
 Otherwise, they may be converted to those types later.

Modified:
    cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
    cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
    cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/coverage_checker/CryptoCoverageCheckerTest.java

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=1561774&r1=1561773&r2=1561774&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Mon Jan 27 18:29:53
2014
@@ -691,26 +691,55 @@ public final class StaxUtils {
      * @throws XMLStreamException
      */
     public static void copy(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException
{
-        copy(reader, writer, false);
+        copy(reader, writer, false, false);
     }
-    public static void copy(XMLStreamReader reader, XMLStreamWriter writer,
-                            boolean fragment) throws XMLStreamException {
+    public static void copy(XMLStreamReader reader, XMLStreamWriter writer, boolean fragment)

+        throws XMLStreamException {
+        copy(reader, writer, fragment, false);
+    }
+    public static void copy(XMLStreamReader reader,
+                            XMLStreamWriter writer,
+                            boolean fragment,
+                            boolean isThreshold) throws XMLStreamException {
         // number of elements read in
         int read = 0;
+        int elementCount = 0;
+        Stack<Integer> countStack = new Stack<Integer>();
         int event = reader.getEventType();
 
         while (reader.hasNext()) {
             switch (event) {
             case XMLStreamConstants.START_ELEMENT:
                 read++;
+                if (isThreshold) {
+                    elementCount++;
+                    
+                    if (innerElementLevelThreshold != -1 
+                        && read >= innerElementLevelThreshold) {
+                        throw new DepthExceededStaxException("reach the innerElementLevelThreshold:"

+                                                   + innerElementLevelThreshold);
+                    }
+                    if (innerElementCountThreshold != -1 
+                        && elementCount >= innerElementCountThreshold) {
+                        throw new DepthExceededStaxException("reach the innerElementCountThreshold:"

+                                                   + innerElementCountThreshold);
+                    }                
+                    countStack.push(elementCount);
+                    elementCount = 0;
+                }
                 writeStartElement(reader, writer);
                 break;
             case XMLStreamConstants.END_ELEMENT:
-                writer.writeEndElement();
+                if (read > 0) {
+                    writer.writeEndElement();
+                }
                 read--;
                 if (read <= 0 && !fragment) {
                     return;
                 }
+                if (isThreshold && !countStack.isEmpty()) {
+                    elementCount = countStack.pop();
+                }
                 break;
             case XMLStreamConstants.CHARACTERS:
                 String s = reader.getText();
@@ -751,6 +780,10 @@ public final class StaxUtils {
         if (uri != null) {
             writeElementNS = true;
             Iterator<String> it = CastUtils.cast(writer.getNamespaceContext().getPrefixes(uri));
+            if (!it.hasNext() && StringUtils.isEmpty(prefix) && StringUtils.isEmpty(uri)
+                && StringUtils.isEmpty(writer.getNamespaceContext().getNamespaceURI("")))
{
+                writeElementNS = false;
+            }
             while (it != null && it.hasNext()) {
                 String s = it.next();
                 if (s == null) {

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java?rev=1561774&r1=1561773&r2=1561774&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java Mon Jan
27 18:29:53 2014
@@ -144,15 +144,23 @@ public class W3CDOMStreamWriter implemen
             }
         }
     }
+    
+    protected Element createElementNS(String ns, String pfx, String local) {
+        if (pfx != null) {
+            local = pfx + ":" + local;
+        }
+        return document.createElementNS(ns, local);
+    }
+    
     protected void createAndAddElement(String prefix, String local, String namespace) {
         if (prefix == null) {
             if (namespace == null) {
-                newChild(document.createElementNS(null, local));
+                newChild(createElementNS(null, null, local));
             } else {
-                newChild(document.createElementNS(namespace, local));
+                newChild(createElementNS(namespace, null, local));
             }
         } else {
-            newChild(document.createElementNS(namespace, prefix + ":" + local));
+            newChild(createElementNS(namespace, prefix, local));
         }
     }
 

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java?rev=1561774&r1=1561773&r2=1561774&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
Mon Jan 27 18:29:53 2014
@@ -220,8 +220,10 @@ public class SAAJInInterceptor extends A
                 soapMessage.getSOAPPart().getEnvelope().addHeader();
             }
             
-            StaxUtils.readDocElements(soapMessage.getSOAPPart().getEnvelope().getBody(),
-                                      xmlReader, true, true);
+            StaxUtils.copy(xmlReader, 
+                           new SAAJStreamWriter(soapMessage.getSOAPPart(), 
+                                                soapMessage.getSOAPPart().getEnvelope().getBody()),
+                           true, true);
             DOMSource bodySource = new DOMSource(soapMessage.getSOAPPart().getEnvelope().getBody());
             xmlReader = StaxUtils.createXMLStreamReader(bodySource);
             xmlReader.nextTag();

Modified: cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java?rev=1561774&r1=1561773&r2=1561774&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
(original)
+++ cxf/trunk/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
Mon Jan 27 18:29:53 2014
@@ -18,9 +18,12 @@
  */
 package org.apache.cxf.binding.soap.saaj;
 
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPElement;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPHeader;
 import javax.xml.soap.SOAPPart;
 
 import org.w3c.dom.Element;
@@ -124,4 +127,46 @@ public final class SAAJStreamWriter exte
         }
         super.createAndAddElement(prefix, local, namespace);
     }
+    
+    @Override
+    protected Element createElementNS(String ns, String pfx, String local) {
+        Element cur = getCurrentNode();
+        if (cur instanceof SOAPBody) {
+            try {
+                if (StringUtils.isEmpty(pfx) && StringUtils.isEmpty(ns)) {
+                    Element el = ((SOAPBody)cur).addBodyElement(new QName(local));
+                    cur.removeChild(el);
+                    return el;
+                }
+                Element el = ((SOAPBody)cur).addBodyElement(new QName(ns, local,  pfx ==
null ? "" : pfx));
+                cur.removeChild(el);
+                return el;
+            } catch (SOAPException e) {
+                //ignore
+            }
+        } else if (cur instanceof SOAPHeader) {
+            try {
+                Element el = ((SOAPHeader)cur).addHeaderElement(new QName(ns, local, pfx
== null ? "" : pfx));
+                cur.removeChild(el);
+                return el;
+            } catch (SOAPException e) {
+                //ignore
+            }
+        } else if (cur instanceof SOAPElement) {
+            try {
+                Element el = null;
+                if (StringUtils.isEmpty(pfx) && StringUtils.isEmpty(ns)) {
+                    el = ((SOAPElement)cur).addChildElement(local);
+                } else {
+                    el = ((SOAPElement)cur).addChildElement(local, pfx, ns);
+                }
+                cur.removeChild(el);
+                return el;
+            } catch (SOAPException e) {
+                //ignore
+            }
+        }
+        return super.createElementNS(ns, pfx, local);
+    }
+    
 }

Modified: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java?rev=1561774&r1=1561773&r2=1561774&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
(original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
Mon Jan 27 18:29:53 2014
@@ -88,7 +88,7 @@ public class DispatchClientServerWithHug
     @BeforeClass
     public static void startServers() throws Exception {
         //must be out of process so the system properties aren't in effect
-        assertTrue("server did not launch correctly", launchServer(Server.class, false));
+        assertTrue("server did not launch correctly", launchServer(Server.class, true));
     }
     
     @org.junit.Before

Modified: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/coverage_checker/CryptoCoverageCheckerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/coverage_checker/CryptoCoverageCheckerTest.java?rev=1561774&r1=1561773&r2=1561774&view=diff
==============================================================================
--- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/coverage_checker/CryptoCoverageCheckerTest.java
(original)
+++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/coverage_checker/CryptoCoverageCheckerTest.java
Mon Jan 27 18:29:53 2014
@@ -581,7 +581,8 @@ public class CryptoCoverageCheckerTest e
         
         // This test only applies to the DOM implementation
         if (PORT.equals(test.getPort()) && !test.isStreaming()) {
-            port.doubleIt(25);
+            int result = port.doubleIt(25);
+            assertEquals(50, result);
             
             // Now try with a message that will create a Fault in the SEI
             try {



Mime
View raw message