cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1561822 - in /cxf/branches/2.7.x-fixes: api/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/
Date Mon, 27 Jan 2014 20:02:30 GMT
Author: dkulp
Date: Mon Jan 27 20:02:29 2014
New Revision: 1561822

URL: http://svn.apache.org/r1561822
Log:
Merged revisions 1561774 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1561774 | dkulp | 2014-01-27 13:29:53 -0500 (Mon, 27 Jan 2014) | 2 lines

  [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/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
    cxf/branches/2.7.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
    cxf/branches/2.7.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
    cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java

Modified: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=1561822&r1=1561821&r2=1561822&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Mon
Jan 27 20:02:29 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) {
@@ -1739,22 +1772,24 @@ public final class StaxUtils {
         }
     }
 
-    public static String toString(Source src) throws XMLStreamException {
+    public static String toString(Source src) {
         StringWriter sw = new StringWriter(1024);
         XMLStreamWriter writer = null;
         try {
             writer = createXMLStreamWriter(sw);
             copy(src, writer);
             writer.flush();
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
         } finally {
             StaxUtils.close(writer);
         }
         return sw.toString();
     }
-    public static String toString(Node src) throws XMLStreamException {
+    public static String toString(Node src) {
         return toString(new DOMSource(src));
     }
-    public static String toString(Document doc) throws XMLStreamException {
+    public static String toString(Document doc) {
         StringWriter sw = new StringWriter(1024);
         XMLStreamWriter writer = null;
         try {
@@ -1768,7 +1803,7 @@ public final class StaxUtils {
         }
         return sw.toString();
     }
-    public static String toString(Element el) throws XMLStreamException {
+    public static String toString(Element el) {
         return toString(el, 0);
     }
     public static String toString(Element el, int indent) {

Modified: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java?rev=1561822&r1=1561821&r2=1561822&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
(original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
Mon Jan 27 20:02:29 2014
@@ -34,8 +34,8 @@ import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.MapNamespaceContext;
-import org.apache.cxf.helpers.XMLUtils;
 
 public class W3CDOMStreamWriter implements XMLStreamWriter {
     static final String XML_NS = "http://www.w3.org/2000/xmlns/";
@@ -47,7 +47,7 @@ public class W3CDOMStreamWriter implemen
     private Map<String, Object> properties = Collections.emptyMap();
 
     public W3CDOMStreamWriter() throws ParserConfigurationException {
-        document = XMLUtils.newDocument();
+        document = DOMUtils.newDocument();
     }
 
     public W3CDOMStreamWriter(DocumentBuilder builder) {
@@ -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));
         }
     }
 
@@ -335,8 +343,6 @@ public class W3CDOMStreamWriter implemen
         }
         try {
             return StaxUtils.toString(document);
-        } catch (XMLStreamException e) {
-            return super.toString();
         } catch (Throwable t) {
             t.printStackTrace();
             return super.toString();

Modified: cxf/branches/2.7.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java?rev=1561822&r1=1561821&r2=1561822&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJInInterceptor.java
Mon Jan 27 20:02:29 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/branches/2.7.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java?rev=1561822&r1=1561821&r2=1561822&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/saaj/SAAJStreamWriter.java
Mon Jan 27 20:02:29 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/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java?rev=1561822&r1=1561821&r2=1561822&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
Mon Jan 27 20:02:29 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



Mime
View raw message