camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] git commit: CAMEL-7309: Reduce excessive INFO logging if using stax converter with woodstox on classpath.
Date Tue, 18 Mar 2014 15:57:41 GMT
CAMEL-7309: Reduce excessive INFO logging if using stax converter with woodstox on classpath.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c6b37c45
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c6b37c45
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c6b37c45

Branch: refs/heads/camel-2.13.x
Commit: c6b37c45d6774502cb1421a86f71ec992ef27460
Parents: 65a5871
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Mar 18 16:59:59 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Mar 18 17:00:12 2014 +0100

----------------------------------------------------------------------
 .../camel/converter/jaxp/StaxConverter.java     | 53 +++++++++-----------
 1 file changed, 24 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c6b37c45/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java b/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
index ca16a11..6a908e6 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
@@ -32,8 +32,6 @@ import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.dom.DOMSource;
 
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
@@ -48,10 +46,8 @@ import org.slf4j.LoggerFactory;
  */
 @Converter
 public class StaxConverter {
-    private static final Logger LOG = LoggerFactory.getLogger(XmlErrorListener.class);
+    private static final Logger LOG = LoggerFactory.getLogger(StaxConverter.class);
 
-    // TODO: do not use a cxf system property
-    // TODO: make higher default pool size as 20 is not much in high end systems
     private static final BlockingQueue<XMLInputFactory> INPUT_FACTORY_POOL;
     private static final BlockingQueue<XMLOutputFactory> OUTPUT_FACTORY_POOL;
     static {
@@ -68,9 +64,23 @@ public class StaxConverter {
             //ignore 
             i = 20;
         }
+        try {
+            // if we have more cores than 20, then use that
+            int cores = Runtime.getRuntime().availableProcessors();
+            if (cores > i) {
+                i = cores;
+            }
+        } catch (Throwable t) {
+            // ignore
+            i = 20;
+        }
+
         if (i <= 0) {
             i = 20;
         }
+
+        LOG.debug("StaxConverter pool size: {}", i);
+
         INPUT_FACTORY_POOL = new LinkedBlockingQueue<XMLInputFactory>(i);
         OUTPUT_FACTORY_POOL = new LinkedBlockingQueue<XMLOutputFactory>(i);
     }
@@ -102,12 +112,6 @@ public class StaxConverter {
     public XMLEventWriter createXMLEventWriter(Result result) throws XMLStreamException {
         XMLOutputFactory factory = getOutputFactory();
         try {
-            if (result instanceof DOMResult && !isWoodstox(factory)) {
-                //FIXME - if not woodstox, this will likely not work well
-                //likely should copy CXF's W3CDOM stuff
-                LOG.info("DOMResult is known to have issues with {0}. We suggest using Woodstox",
-                         factory.getClass());
-            }
             return factory.createXMLEventWriter(result);
         } finally {
             returnXMLOutputFactory(factory);
@@ -138,12 +142,6 @@ public class StaxConverter {
     public XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException
{
         XMLOutputFactory factory = getOutputFactory();
         try {
-            if (result instanceof DOMResult && !isWoodstox(factory)) {
-                //FIXME - if not woodstox, this will likely not work well
-                //likely should copy CXF's W3CDOM stuff
-                LOG.info("DOMResult is known to have issues with {0}. We suggest using Woodstox",
-                         factory.getClass());
-            }
             return factory.createXMLStreamWriter(result);
         } finally {
             returnXMLOutputFactory(factory);
@@ -202,12 +200,6 @@ public class StaxConverter {
     public XMLStreamReader createXMLStreamReader(Source in) throws XMLStreamException {
         XMLInputFactory factory = getInputFactory();
         try {
-            if (in instanceof DOMSource && !isWoodstox(factory)) {
-                //FIXME - if not woodstox, this will likely not work well
-                //likely should copy CXF's W3CDOM stuff
-                LOG.info("DOMSource is known to have issues with {0}. We suggest using Woodstox",
-                         factory.getClass());
-            }
             return factory.createXMLStreamReader(in);
         } finally {
             returnXMLInputFactory(factory);
@@ -286,18 +278,13 @@ public class StaxConverter {
     public XMLEventReader createXMLEventReader(Source in) throws XMLStreamException {
         XMLInputFactory factory = getInputFactory();
         try {
-            if (in instanceof DOMSource && !isWoodstox(factory)) {
-                //FIXME - if not woodstox, this will likely not work well
-                LOG.info("DOMSource is known to have issues with {0}. We suggest using Woodstox",
-                         factory.getClass());
-            }
             return factory.createXMLEventReader(in);
         } finally {
             returnXMLInputFactory(factory);
         }
     }
 
-    private boolean isWoodstox(Object factory) {
+    private static boolean isWoodstox(Object factory) {
         return factory.getClass().getPackage().getName().startsWith("com.ctc.wstx");
     }
 
@@ -342,6 +329,14 @@ public class StaxConverter {
                 throw new XMLStreamException("Reading external entities is disabled");
             }
         });
+
+        if (isWoodstox(factory)) {
+            // just log a debug as we are good then
+            LOG.debug("Created Woodstox XMLInputFactory: {}", factory);
+        } else {
+            // log a hint that woodstock may be a better factory to use
+            LOG.info("Created XMLInputFactory: {}. DOMSource/DOMResult may have issues with
{}. We suggest using Woodstox.", factory, factory);
+        }
         return factory;
     }
     


Mime
View raw message