camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-10558: XmlConverter cannot load fallback TransformerFactory in OSGi
Date Sun, 04 Dec 2016 14:29:07 GMT
Repository: camel
Updated Branches:
  refs/heads/master b79471c7d -> fb3a76b8b


CAMEL-10558: XmlConverter cannot load fallback TransformerFactory in OSGi


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

Branch: refs/heads/master
Commit: fb3a76b8b7d227584643c1cb0de1fb301f8177af
Parents: b79471c
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Dec 4 15:06:02 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Dec 4 15:06:02 2016 +0100

----------------------------------------------------------------------
 .../camel/converter/jaxp/XmlConverter.java      | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/fb3a76b8/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java b/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
index 539eee6..f827f21 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
@@ -46,6 +46,7 @@ import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.sax.SAXSource;
@@ -86,6 +87,7 @@ public class XmlConverter {
     public static final String DOCUMENT_BUILDER_FACTORY_FEATURE = "org.apache.camel.xmlconverter.documentBuilderFactory.feature";
     public static String defaultCharset = ObjectHelper.getSystemProperty(Exchange.DEFAULT_CHARSET_PROPERTY,
"UTF-8");
 
+    private static final String JDK_FALLBACK_TRANSFORMER_FACTORY = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
     private static final Logger LOG = LoggerFactory.getLogger(XmlConverter.class);
 
     private volatile DocumentBuilderFactory documentBuilderFactory;
@@ -1170,7 +1172,23 @@ public class XmlConverter {
     }
 
     public TransformerFactory createTransformerFactory() {
-        TransformerFactory factory = TransformerFactory.newInstance();
+        TransformerFactory factory;
+        TransformerFactoryConfigurationError cause;
+        try {
+            factory = TransformerFactory.newInstance();
+        } catch (TransformerFactoryConfigurationError e) {
+            cause = e;
+            // try fallback from the JDK
+            try {
+                LOG.debug("Cannot create/load TransformerFactory due: {}. Will attempt to
use JDK fallback TransformerFactory: {}", e.getMessage(), JDK_FALLBACK_TRANSFORMER_FACTORY);
+                factory = TransformerFactory.newInstance(JDK_FALLBACK_TRANSFORMER_FACTORY,
null);
+            } catch (Throwable t) {
+                // okay we cannot load fallback then throw original exception
+                throw cause;
+            }
+        }
+        LOG.debug("Created TransformerFactory: {}", factory);
+
         // Enable the Security feature by default
         try {
             factory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);


Mime
View raw message