You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Mike Youngstrom (JIRA)" <ji...@apache.org> on 2009/08/18 18:35:15 UTC

[jira] Created: (CXF-2397) Make use of ControlledValidationXmlBeanDefinitionReader optional depending upon existence of FastInfoSet.jar

Make use of ControlledValidationXmlBeanDefinitionReader optional depending upon existence of FastInfoSet.jar
------------------------------------------------------------------------------------------------------------

                 Key: CXF-2397
                 URL: https://issues.apache.org/jira/browse/CXF-2397
             Project: CXF
          Issue Type: Improvement
          Components: Core
    Affects Versions: 2.2.3
            Reporter: Mike Youngstrom


I work on a project where Classloader size and distribution size is rather important.  So we're trying to keep our number of required dependencies to a minimum.

One area where we found this might be able to improve is in the use of ControlledValidationXmlBeanDefinitionReader and its dependence on FastInfoSet.  It would be nice if an application who didn't wish to benefit from the improved startup time of ControlledValidationXmlBeanDefinitionReader could not use it if they wished.

I wonder if this could simply be a matter of checking in BusApplicationContext.loadBeanDefinitions() if com.sun.xml.fastinfoset.stax.StAXDocumentParser is on the classpath.  If it's not then log a warning or an info about its absence and the potential performance impact then simply use a regular XmlBeanDefinitionReader instead?

Or perhaps in TunedDocumentLoader only use a com.sun.xml.fastinfoset.stax.StAXDocumentParser if fastinfoset is on the classpath.  Otherwise use a default stax implementation?

This would allow me to make FastInfoSet an optional dependency in my project.

Mike


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CXF-2397) Make use of ControlledValidationXmlBeanDefinitionReader optional depending upon existence of FastInfoSet.jar

Posted by "Mike Youngstrom (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-2397?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12745130#action_12745130 ] 

Mike Youngstrom commented on CXF-2397:
--------------------------------------

BTW that patch is on the 2.2.x branch.

> Make use of ControlledValidationXmlBeanDefinitionReader optional depending upon existence of FastInfoSet.jar
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2397
>                 URL: https://issues.apache.org/jira/browse/CXF-2397
>             Project: CXF
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 2.2.3
>            Reporter: Mike Youngstrom
>
> I work on a project where Classloader size and distribution size is rather important.  So we're trying to keep our number of required dependencies to a minimum.
> One area where we found this might be able to improve is in the use of ControlledValidationXmlBeanDefinitionReader and its dependence on FastInfoSet.  It would be nice if an application who didn't wish to benefit from the improved startup time of ControlledValidationXmlBeanDefinitionReader could not use it if they wished.
> I wonder if this could simply be a matter of checking in BusApplicationContext.loadBeanDefinitions() if com.sun.xml.fastinfoset.stax.StAXDocumentParser is on the classpath.  If it's not then log a warning or an info about its absence and the potential performance impact then simply use a regular XmlBeanDefinitionReader instead?
> Or perhaps in TunedDocumentLoader only use a com.sun.xml.fastinfoset.stax.StAXDocumentParser if fastinfoset is on the classpath.  Otherwise use a default stax implementation?
> This would allow me to make FastInfoSet an optional dependency in my project.
> Mike

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (CXF-2397) Make use of ControlledValidationXmlBeanDefinitionReader optional depending upon existence of FastInfoSet.jar

Posted by "Daniel Kulp (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-2397?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Daniel Kulp resolved CXF-2397.
------------------------------

       Resolution: Fixed
    Fix Version/s: 2.2.4
                   2.1.7
         Assignee: Daniel Kulp

> Make use of ControlledValidationXmlBeanDefinitionReader optional depending upon existence of FastInfoSet.jar
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2397
>                 URL: https://issues.apache.org/jira/browse/CXF-2397
>             Project: CXF
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 2.2.3
>            Reporter: Mike Youngstrom
>            Assignee: Daniel Kulp
>             Fix For: 2.1.7, 2.2.4
>
>
> I work on a project where Classloader size and distribution size is rather important.  So we're trying to keep our number of required dependencies to a minimum.
> One area where we found this might be able to improve is in the use of ControlledValidationXmlBeanDefinitionReader and its dependence on FastInfoSet.  It would be nice if an application who didn't wish to benefit from the improved startup time of ControlledValidationXmlBeanDefinitionReader could not use it if they wished.
> I wonder if this could simply be a matter of checking in BusApplicationContext.loadBeanDefinitions() if com.sun.xml.fastinfoset.stax.StAXDocumentParser is on the classpath.  If it's not then log a warning or an info about its absence and the potential performance impact then simply use a regular XmlBeanDefinitionReader instead?
> Or perhaps in TunedDocumentLoader only use a com.sun.xml.fastinfoset.stax.StAXDocumentParser if fastinfoset is on the classpath.  Otherwise use a default stax implementation?
> This would allow me to make FastInfoSet an optional dependency in my project.
> Mike

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CXF-2397) Make use of ControlledValidationXmlBeanDefinitionReader optional depending upon existence of FastInfoSet.jar

Posted by "Daniel Kulp (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-2397?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12745068#action_12745068 ] 

Daniel Kulp commented on CXF-2397:
----------------------------------


Patches are always welcome.  :-)

> Make use of ControlledValidationXmlBeanDefinitionReader optional depending upon existence of FastInfoSet.jar
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2397
>                 URL: https://issues.apache.org/jira/browse/CXF-2397
>             Project: CXF
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 2.2.3
>            Reporter: Mike Youngstrom
>
> I work on a project where Classloader size and distribution size is rather important.  So we're trying to keep our number of required dependencies to a minimum.
> One area where we found this might be able to improve is in the use of ControlledValidationXmlBeanDefinitionReader and its dependence on FastInfoSet.  It would be nice if an application who didn't wish to benefit from the improved startup time of ControlledValidationXmlBeanDefinitionReader could not use it if they wished.
> I wonder if this could simply be a matter of checking in BusApplicationContext.loadBeanDefinitions() if com.sun.xml.fastinfoset.stax.StAXDocumentParser is on the classpath.  If it's not then log a warning or an info about its absence and the potential performance impact then simply use a regular XmlBeanDefinitionReader instead?
> Or perhaps in TunedDocumentLoader only use a com.sun.xml.fastinfoset.stax.StAXDocumentParser if fastinfoset is on the classpath.  Otherwise use a default stax implementation?
> This would allow me to make FastInfoSet an optional dependency in my project.
> Mike

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CXF-2397) Make use of ControlledValidationXmlBeanDefinitionReader optional depending upon existence of FastInfoSet.jar

Posted by "Mike Youngstrom (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-2397?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12745129#action_12745129 ] 

Mike Youngstrom commented on CXF-2397:
--------------------------------------

Just wanted to make sure you were amiable to the idea first. :)  Here is a patch that works great for me.  I tested both with fastinfoset on the classpath and without.

Index: rt/core/pom.xml
===================================================================
--- rt/core/pom.xml	(revision 805827)
+++ rt/core/pom.xml	(working copy)
@@ -79,6 +79,7 @@
        <dependency>
          <groupId>com.sun.xml.fastinfoset</groupId>
          <artifactId>FastInfoset</artifactId>
+         <optional>true</optional>
         </dependency>
         
     </dependencies>
Index: rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java
===================================================================
--- rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java	(revision 805827)
+++ rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java	(working copy)
@@ -22,7 +22,9 @@
 import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
+import java.util.logging.Logger;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -31,6 +33,7 @@
 import javax.xml.parsers.SAXParserFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.sax.SAXSource;
@@ -42,9 +45,9 @@
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
 
-import com.sun.xml.fastinfoset.stax.StAXDocumentParser;
-
+import org.apache.cxf.bus.spring.BusApplicationContext;
 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,12 +57,15 @@
  * 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);
     
     // 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;
+    private static Class<XMLStreamReader> fastInfosetParserClass;
     static {
         try {
             documentBuilder = 
@@ -67,10 +73,17 @@
         } catch (ParserConfigurationException e) {
             throw new RuntimeException(e);
         }
+        try {
+        	fastInfosetParserClass = (Class<XMLStreamReader>)ClassLoaderUtils.loadClass("com.sun.xml.fastinfoset.stax.StAXDocumentParser",
+                                                      TunedDocumentLoader.class);
+        } catch (Throwable e) {
+        	LOG.info("FastInfoset not found on classpath.  Disabling context load optimizations.");
+        }
     }
     private TransformerFactory transformerFactory;
     private SAXParserFactory saxParserFactory;
     private SAXParserFactory nsasaxParserFactory;
+    private XMLInputFactory xmlInputFactory;
     
     TunedDocumentLoader() {
         transformerFactory = TransformerFactory.newInstance();
@@ -93,6 +106,10 @@
         } catch (Throwable e) {
             //ignore
         }
+        if(fastInfosetParserClass == null) {
+            //fastinfoset not found, using any other Stax parser
+        	xmlInputFactory = XMLInputFactory.newInstance();
+        }
     }
 
     @Override
@@ -141,7 +158,18 @@
         
         InputStream is = url.openStream();
         InputStream in = new BufferedInputStream(is);
-        XMLStreamReader staxReader = new StAXDocumentParser(in);
+        XMLStreamReader staxReader = null;
+        if(fastInfosetParserClass != null) {
+    		try {
+				staxReader = fastInfosetParserClass.getConstructor(InputStream.class).newInstance(in);
+			} catch (Exception e) {
+				ParserConfigurationException exception = new ParserConfigurationException("Unable to create FastInfoset StAXDocumentParser");
+				exception.initCause(e);
+				throw exception;
+			}
+        } else {
+        	staxReader = XMLInputFactory.newInstance().createXMLStreamReader(in);
+        }
         W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
         StaxUtils.copy(staxReader, writer);
         in.close();


> Make use of ControlledValidationXmlBeanDefinitionReader optional depending upon existence of FastInfoSet.jar
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2397
>                 URL: https://issues.apache.org/jira/browse/CXF-2397
>             Project: CXF
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 2.2.3
>            Reporter: Mike Youngstrom
>
> I work on a project where Classloader size and distribution size is rather important.  So we're trying to keep our number of required dependencies to a minimum.
> One area where we found this might be able to improve is in the use of ControlledValidationXmlBeanDefinitionReader and its dependence on FastInfoSet.  It would be nice if an application who didn't wish to benefit from the improved startup time of ControlledValidationXmlBeanDefinitionReader could not use it if they wished.
> I wonder if this could simply be a matter of checking in BusApplicationContext.loadBeanDefinitions() if com.sun.xml.fastinfoset.stax.StAXDocumentParser is on the classpath.  If it's not then log a warning or an info about its absence and the potential performance impact then simply use a regular XmlBeanDefinitionReader instead?
> Or perhaps in TunedDocumentLoader only use a com.sun.xml.fastinfoset.stax.StAXDocumentParser if fastinfoset is on the classpath.  Otherwise use a default stax implementation?
> This would allow me to make FastInfoSet an optional dependency in my project.
> Mike

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CXF-2397) Make use of ControlledValidationXmlBeanDefinitionReader optional depending upon existence of FastInfoSet.jar

Posted by "Mike Youngstrom (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-2397?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12744594#action_12744594 ] 

Mike Youngstrom commented on CXF-2397:
--------------------------------------

I can provide a patch if necessary

> Make use of ControlledValidationXmlBeanDefinitionReader optional depending upon existence of FastInfoSet.jar
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2397
>                 URL: https://issues.apache.org/jira/browse/CXF-2397
>             Project: CXF
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 2.2.3
>            Reporter: Mike Youngstrom
>
> I work on a project where Classloader size and distribution size is rather important.  So we're trying to keep our number of required dependencies to a minimum.
> One area where we found this might be able to improve is in the use of ControlledValidationXmlBeanDefinitionReader and its dependence on FastInfoSet.  It would be nice if an application who didn't wish to benefit from the improved startup time of ControlledValidationXmlBeanDefinitionReader could not use it if they wished.
> I wonder if this could simply be a matter of checking in BusApplicationContext.loadBeanDefinitions() if com.sun.xml.fastinfoset.stax.StAXDocumentParser is on the classpath.  If it's not then log a warning or an info about its absence and the potential performance impact then simply use a regular XmlBeanDefinitionReader instead?
> Or perhaps in TunedDocumentLoader only use a com.sun.xml.fastinfoset.stax.StAXDocumentParser if fastinfoset is on the classpath.  Otherwise use a default stax implementation?
> This would allow me to make FastInfoSet an optional dependency in my project.
> Mike

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.