cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r1036774 - in /cxf/branches/2.2.x-fixes: ./ common/common/src/main/java/org/apache/cxf/staxutils/ systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/ systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/
Date Fri, 19 Nov 2010 09:35:24 GMT
Author: ffang
Date: Fri Nov 19 09:35:24 2010
New Revision: 1036774

URL: http://svn.apache.org/viewvc?rev=1036774&view=rev
Log:
Merged revisions 1036766 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.3.x-fixes

................
  r1036766 | ffang | 2010-11-19 17:08:04 +0800 (五, 19 11 2010) | 9 lines
  
  Merged revisions 1036765 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1036765 | ffang | 2010-11-19 16:59:01 +0800 (五, 19 11 2010) | 1 line
    
    [CXF-3132]refactor StaxUtils not to use recursive to avoid StackOverflowError
  ........
................

Removed:
    cxf/branches/2.2.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/resources/stack_overflow_rs.xml
Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    cxf/branches/2.2.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
    cxf/branches/2.2.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/HugeResponseInterceptor.java

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

Modified: cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=1036774&r1=1036773&r2=1036774&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
Fri Nov 19 09:35:24 2010
@@ -26,6 +26,7 @@ import java.io.StringWriter;
 import java.io.Writer;
 import java.net.URL;
 import java.util.Iterator;
+import java.util.Stack;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.logging.Logger;
@@ -872,74 +873,27 @@ public final class StaxUtils {
         return (parent instanceof Document) ? (Document)parent : parent.getOwnerDocument();
     }
 
-    /**
-     * @param parent
-     * @param reader
-     * @return
-     * @throws XMLStreamException
-     */
-    private static Element startElement(Document doc, 
-                                        Node parent, 
-                                        XMLStreamReader reader,
-                                        boolean repairing,
-                                        boolean recordLocation)
-        throws XMLStreamException {
-
-        Element e = doc.createElementNS(reader.getNamespaceURI(), reader.getLocalName());
-        if (reader.getPrefix() != null) {
-            e.setPrefix(reader.getPrefix());
-        }       
-        e = (Element)parent.appendChild(e);
-        recordLocation = addLocation(doc, e, reader, recordLocation);
-
-        for (int ns = 0; ns < reader.getNamespaceCount(); ns++) {
-            String uri = reader.getNamespaceURI(ns);
-            String prefix = reader.getNamespacePrefix(ns);
-
-            declare(e, uri, prefix);
-        }
-
-        for (int att = 0; att < reader.getAttributeCount(); att++) {
-            String name = reader.getAttributeLocalName(att);
-            String prefix = reader.getAttributePrefix(att);
+    private static boolean isDeclared(Element e, String namespaceURI, String prefix) {
+        while (e != null) {
+            Attr att;
             if (prefix != null && prefix.length() > 0) {
-                name = prefix + ":" + name;
+                att = e.getAttributeNodeNS(XML_NS, prefix);
+            } else {
+                att = e.getAttributeNode("xmlns");
+            }
+    
+            if (att != null && att.getNodeValue().equals(namespaceURI)) {
+                return true;
+            }
+    
+            if (e.getParentNode() instanceof Element) {
+                e = (Element)e.getParentNode();
+            } else if (StringUtils.isEmpty(prefix) && StringUtils.isEmpty(namespaceURI))
{
+                //A document that probably doesn't have any namespace qualifies elements
+                return true;
+            } else {
+                e = null;
             }
-
-            Attr attr = doc.createAttributeNS(reader.getAttributeNamespace(att), name);
-            attr.setValue(reader.getAttributeValue(att));
-            e.setAttributeNode(attr);
-        }
-
-        if (repairing && !isDeclared(e, reader.getNamespaceURI(), reader.getPrefix()))
{
-            declare(e, reader.getNamespaceURI(), reader.getPrefix());
-        }
-
-        reader.next();
-
-        readDocElements(doc, e, reader, repairing, recordLocation);
-
-        return e;
-    }
-
-    private static boolean isDeclared(Element e, String namespaceURI, String prefix) {
-        Attr att;
-        if (prefix != null && prefix.length() > 0) {
-            att = e.getAttributeNodeNS(XML_NS, prefix);
-        } else {
-            att = e.getAttributeNode("xmlns");
-        }
-
-        if (att != null && att.getNodeValue().equals(namespaceURI)) {
-            return true;
-        }
-
-        if (e.getParentNode() instanceof Element) {
-            return isDeclared((Element)e.getParentNode(), namespaceURI, prefix);
-        }
-        if (StringUtils.isEmpty(prefix) && StringUtils.isEmpty(namespaceURI)) {
-            //A document that probably doesn't have any namespace qualifies elements
-            return true;
         }
         return false;
     }
@@ -957,19 +911,58 @@ public final class StaxUtils {
     public static void readDocElements(Document doc, Node parent,
                                        XMLStreamReader reader, boolean repairing, boolean
recordLoc)
         throws XMLStreamException {
-
+        
+        Stack<Node> stack = new Stack<Node>();
         int event = reader.getEventType();
         while (reader.hasNext()) {
             switch (event) {
-            case XMLStreamConstants.START_ELEMENT:
-                startElement(doc, parent, reader, repairing, recordLoc);
+            case XMLStreamConstants.START_ELEMENT: {
+                Element e = doc.createElementNS(reader.getNamespaceURI(), reader.getLocalName());
+                if (reader.getPrefix() != null) {
+                    e.setPrefix(reader.getPrefix());
+                }       
+                e = (Element)parent.appendChild(e);
+                recordLoc = addLocation(doc, e, reader, recordLoc);
+
+                for (int ns = 0; ns < reader.getNamespaceCount(); ns++) {
+                    String uri = reader.getNamespaceURI(ns);
+                    String prefix = reader.getNamespacePrefix(ns);
+
+                    declare(e, uri, prefix);
+                }
+
+                for (int att = 0; att < reader.getAttributeCount(); att++) {
+                    String name = reader.getAttributeLocalName(att);
+                    String prefix = reader.getAttributePrefix(att);
+                    if (prefix != null && prefix.length() > 0) {
+                        name = prefix + ":" + name;
+                    }
+
+                    Attr attr = doc.createAttributeNS(reader.getAttributeNamespace(att),
name);
+                    attr.setValue(reader.getAttributeValue(att));
+                    e.setAttributeNode(attr);
+                }
+
+                if (repairing && !isDeclared(e, reader.getNamespaceURI(), reader.getPrefix()))
{
+                    declare(e, reader.getNamespaceURI(), reader.getPrefix());
+                }
+                stack.push(parent);
+                parent = e;
+                
+                //event = reader.next();
+                //readDocElements(doc, e, reader, repairing, recordLoc);
                 
+                break;
+            }
+            case XMLStreamConstants.END_ELEMENT:
+                if (stack.isEmpty()) {
+                    return;
+                }
+                parent = stack.pop();
                 if (parent instanceof Document) {
                     return;
                 }
                 break;
-            case XMLStreamConstants.END_ELEMENT:
-                return;
             case XMLStreamConstants.NAMESPACE:
                 break;
             case XMLStreamConstants.ATTRIBUTE:

Modified: cxf/branches/2.2.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java?rev=1036774&r1=1036773&r2=1036774&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/DispatchClientServerWithHugeResponseTest.java
Fri Nov 19 09:35:24 2010
@@ -117,11 +117,12 @@ public class DispatchClientServerWithHug
         assertNotNull(soapReqMsg3);
         Response<SOAPMessage> response = disp.invokeAsync(soapReqMsg3);
         try {
-            response.get(10, TimeUnit.SECONDS);
+            response.get(300, TimeUnit.SECONDS);
         } catch (TimeoutException te) {
             fail("We should not have encountered a timeout, " 
                 + "should get some exception tell me stackoverflow");
         } catch (Throwable e) {
+            e.printStackTrace();
             assertTrue(e.getCause() instanceof StackOverflowError);
         }
         

Modified: cxf/branches/2.2.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/HugeResponseInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/HugeResponseInterceptor.java?rev=1036774&r1=1036773&r2=1036774&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/HugeResponseInterceptor.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/dispatch/HugeResponseInterceptor.java
Fri Nov 19 09:35:24 2010
@@ -18,13 +18,9 @@
  */
 package org.apache.cxf.systest.dispatch;
 
-import java.io.IOException;
-import java.io.InputStream;
 
-import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.LoggingInInterceptor;
-import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
@@ -37,26 +33,7 @@ public class HugeResponseInterceptor ext
     }
 
     public void handleMessage(Message message) throws Fault {
-        InputStream is = message.getContent(InputStream.class);
-        if (is != null) {
-            CachedOutputStream bos = new CachedOutputStream();
-            try {
-                //intend to change response as malformed message
-                is = getClass().getClassLoader().getResourceAsStream(
-                        "org/apache/cxf/systest/dispatch/resources/stack_overflow_rs.xml");
-                IOUtils.copy(is, bos);
-
-                bos.flush();
-                is.close();
-                message.setContent(InputStream.class, bos.getInputStream());
-                bos.close();
-                message.setContent(InputStream.class, bos.getInputStream());
-                
-            } catch (IOException e) {
-                throw new Fault(e);
-            }
-        }
-
+        throw new StackOverflowError();
     }
 
 }



Mime
View raw message