Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 37426 invoked from network); 19 Nov 2010 09:36:10 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 19 Nov 2010 09:36:10 -0000 Received: (qmail 44104 invoked by uid 500); 19 Nov 2010 09:36:41 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 43303 invoked by uid 500); 19 Nov 2010 09:36:41 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 43220 invoked by uid 99); 19 Nov 2010 09:36:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Nov 2010 09:36:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Nov 2010 09:36:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9701C23889F1; Fri, 19 Nov 2010 09:35:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 -0000 To: commits@cxf.apache.org From: ffang@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101119093524.9701C23889F1@eris.apache.org> 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 stack = new Stack(); 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 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(); } }