Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 14778 invoked from network); 20 Aug 2009 02:08:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 20 Aug 2009 02:08:07 -0000 Received: (qmail 20818 invoked by uid 500); 20 Aug 2009 02:08:26 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 20753 invoked by uid 500); 20 Aug 2009 02:08:26 -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 20744 invoked by uid 99); 20 Aug 2009 02:08:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Aug 2009 02:08:26 +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; Thu, 20 Aug 2009 02:08:24 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 785C523888A2; Thu, 20 Aug 2009 02:08:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r806020 - in /cxf/trunk: rt/core/pom.xml rt/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java systests/pom.xml Date: Thu, 20 Aug 2009 02:08:04 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090820020804.785C523888A2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Thu Aug 20 02:08:03 2009 New Revision: 806020 URL: http://svn.apache.org/viewvc?rev=806020&view=rev Log: [CXF-2397] Make loading of xmlfi optional if fastinfoset isn't there. Modified: cxf/trunk/rt/core/pom.xml cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java cxf/trunk/systests/pom.xml Modified: cxf/trunk/rt/core/pom.xml URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/pom.xml?rev=806020&r1=806019&r2=806020&view=diff ============================================================================== --- cxf/trunk/rt/core/pom.xml (original) +++ cxf/trunk/rt/core/pom.xml Thu Aug 20 02:08:03 2009 @@ -59,11 +59,11 @@ org.apache.geronimo.specs geronimo-javamail_1.4_spec - - xml-resolver + + xml-resolver xml-resolver true - + junit junit @@ -76,11 +76,11 @@ test - - com.sun.xml.fastinfoset - FastInfoset + + com.sun.xml.fastinfoset + FastInfoset + true - Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java?rev=806020&r1=806019&r2=806020&view=diff ============================================================================== --- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java (original) +++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java Thu Aug 20 02:08:03 2009 @@ -82,7 +82,8 @@ super(beanFactory); tunedDocumentLoader = new TunedDocumentLoader(); this.setDocumentLoader(tunedDocumentLoader); - noFastinfoset = System.getProperty("org.apache.cxf.nofastinfoset") != null; + noFastinfoset = System.getProperty("org.apache.cxf.nofastinfoset") != null + || !TunedDocumentLoader.hasFastInfoSet(); } @Override @@ -118,15 +119,16 @@ @Override public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException { - if (noFastinfoset) { - return super.loadBeanDefinitions(encodedResource); - } - - try { - return fastInfosetLoadBeanDefinitions(encodedResource); - } catch (Exception e) { - return super.loadBeanDefinitions(encodedResource); + if (!noFastinfoset) { + try { + return fastInfosetLoadBeanDefinitions(encodedResource); + } catch (BeanDefinitionStoreException bdse) { + throw bdse; + } catch (Throwable e) { + //ignore - just call the super to load them + } } + return super.loadBeanDefinitions(encodedResource); } private int fastInfosetLoadBeanDefinitions(EncodedResource encodedResource) @@ -161,7 +163,11 @@ } Resource newResource = new UrlResource(fixmlUrl); - Document doc = tunedDocumentLoader.loadFastinfosetDocument(fixmlUrl); + Document doc = TunedDocumentLoader.loadFastinfosetDocument(fixmlUrl); + if (doc == null) { + //something caused FastinfoSet to not be able to read the doc + throw new StaleFastinfosetException(); + } return registerBeanDefinitions(doc, newResource); } Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java?rev=806020&r1=806019&r2=806020&view=diff ============================================================================== --- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java (original) +++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java Thu Aug 20 02:08:03 2009 @@ -23,16 +23,14 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.logging.Logger; -import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMResult; import javax.xml.transform.sax.SAXSource; import org.w3c.dom.Document; @@ -45,6 +43,7 @@ import com.sun.xml.fastinfoset.stax.StAXDocumentParser; import org.apache.cxf.common.classloader.ClassLoaderUtils; +import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.staxutils.StaxUtils; import org.apache.cxf.staxutils.W3CDOMStreamWriter; import org.springframework.beans.factory.xml.DefaultDocumentLoader; @@ -54,27 +53,25 @@ * A Spring DocumentLoader that uses WoodStox when we are not validating to speed up the process. */ class TunedDocumentLoader extends DefaultDocumentLoader { + private static final Logger LOG = LogUtils.getL7dLogger(TunedDocumentLoader.class); + + private static boolean hasFastInfoSet; - // DocumentBuilderFactories are somewhat expensive but not thread-safe. - // We only use this builder with WoodStox, and Fast Infoset - // and we respect Spring's desire to make new factories - // when we aren't doing the optimization. - private static DocumentBuilder documentBuilder; static { - try { - documentBuilder = - DocumentBuilderFactory.newInstance().newDocumentBuilder(); - } catch (ParserConfigurationException e) { - throw new RuntimeException(e); - } + try { + ClassLoaderUtils + .loadClass("com.sun.xml.fastinfoset.stax.StAXDocumentParser", + TunedDocumentLoader.class); + hasFastInfoSet = true; + } catch (Throwable e) { + LOG.fine("FastInfoset not found on classpath. Disabling context load optimizations."); + hasFastInfoSet = false; + } } - private TransformerFactory transformerFactory; private SAXParserFactory saxParserFactory; private SAXParserFactory nsasaxParserFactory; TunedDocumentLoader() { - transformerFactory = TransformerFactory.newInstance(); - try { Class cls = ClassLoaderUtils.loadClass("com.ctc.wstx.sax.WstxSAXParserFactory", TunedDocumentLoader.class); @@ -93,6 +90,11 @@ } catch (Throwable e) { //ignore } + + } + + public static boolean hasFastInfoSet() { + return hasFastInfoSet; } @Override @@ -100,7 +102,6 @@ ErrorHandler errorHandler, int validationMode, boolean namespaceAware) throws Exception { if (validationMode == XmlBeanDefinitionReader.VALIDATION_NONE) { - SAXParserFactory parserFactory = namespaceAware ? nsasaxParserFactory : saxParserFactory; SAXParser parser = parserFactory.newSAXParser(); @@ -108,14 +109,9 @@ reader.setEntityResolver(entityResolver); reader.setErrorHandler(errorHandler); SAXSource saxSource = new SAXSource(reader, inputSource); - Document document; - // collisions are quite unlikely here, but making documentBuilderFactory objects is expensive. - synchronized (documentBuilder) { - document = documentBuilder.newDocument(); - } - DOMResult domResult = new DOMResult(document, inputSource.getSystemId()); - transformerFactory.newTransformer().transform(saxSource, domResult); - return document; + W3CDOMStreamWriter writer = new W3CDOMStreamWriter(); + StaxUtils.copy(saxSource, writer); + return writer.getDocument(); } else { return super.loadDocument(inputSource, entityResolver, errorHandler, validationMode, namespaceAware); @@ -136,9 +132,8 @@ return factory; } - Document loadFastinfosetDocument(URL url) + static Document loadFastinfosetDocument(URL url) throws IOException, ParserConfigurationException, XMLStreamException { - InputStream is = url.openStream(); InputStream in = new BufferedInputStream(is); XMLStreamReader staxReader = new StAXDocumentParser(in); Modified: cxf/trunk/systests/pom.xml URL: http://svn.apache.org/viewvc/cxf/trunk/systests/pom.xml?rev=806020&r1=806019&r2=806020&view=diff ============================================================================== --- cxf/trunk/systests/pom.xml (original) +++ cxf/trunk/systests/pom.xml Thu Aug 20 02:08:03 2009 @@ -571,6 +571,10 @@ + + com.sun.xml.fastinfoset + FastInfoset + rhino