camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: [CAMEL-9921] Use Glassfish EL when available with fallback to default
Date Mon, 09 May 2016 12:20:36 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x 9cebac107 -> 250de646d


[CAMEL-9921] Use Glassfish EL when available with fallback to default


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

Branch: refs/heads/camel-2.17.x
Commit: 250de646dcbac60506a5921a24dabf36c3379503
Parents: 9cebac1
Author: Thomas Diesler <thomas.diesler@jboss.com>
Authored: Mon May 9 13:28:00 2016 +0200
Committer: Thomas Diesler <thomas.diesler@jboss.com>
Committed: Mon May 9 14:12:10 2016 +0200

----------------------------------------------------------------------
 .../camel/component/dozer/DozerEndpoint.java    | 54 ++++++++++++--------
 1 file changed, 34 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/250de646/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerEndpoint.java
b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerEndpoint.java
index 8c0f3db..190d1cc 100644
--- a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerEndpoint.java
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerEndpoint.java
@@ -21,12 +21,15 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.el.ExpressionFactory;
+
 import com.sun.el.ExpressionFactoryImpl;
 
 import org.apache.camel.Component;
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.converter.dozer.DozerThreadContextClassLoader;
 import org.apache.camel.converter.dozer.DozerTypeConverterLoader;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.spi.UriEndpoint;
@@ -123,29 +126,12 @@ public class DozerEndpoint extends DefaultEndpoint {
     }
 
     protected void initDozerBeanContainerAndMapper() throws Exception {
-        LOG.info("Configuring DozerBeanContainer and DozerBeanMapper");
-
-        // must setup dozer to be able to load the EL factory we are using which is from
glashfish
-        ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
 
-        ExpressionFactoryImpl factory = new ExpressionFactoryImpl();
-        ClassLoader cl = factory.getClass().getClassLoader();
-        Thread.currentThread().setContextClassLoader(cl);
+        LOG.info("Configuring DozerBeanContainer and DozerBeanMapper");
 
-        System.setProperty("javax.el.ExpressionFactory", "com.sun.el.ExpressionFactoryImpl");
-        try {
-            ELEngine engine = new ELEngine();
-            engine.init();
-            BeanContainer.getInstance().setElEngine(engine);
-            ElementReader reader = new ExpressionElementReader(engine);
-            BeanContainer.getInstance().setElementReader(reader);
 
-        } catch (Throwable e) {
-            throw new IllegalStateException("Error configuring DozerBeanContainer/DozerBeanMapper
due " + e.getMessage(), e);
-        } finally {
-            System.clearProperty("javax.el.ExpressionFactory");
-            Thread.currentThread().setContextClassLoader(oldCl);
-        }
+        // init the expression engine with a fallback to the impl from glasfish
+        initELEngine();
 
         // configure mapper as well
         if (mapper == null) {
@@ -160,6 +146,34 @@ public class DozerEndpoint extends DefaultEndpoint {
 
     }
 
+    public void initELEngine() {
+        String elprop = System.getProperty("javax.el.ExpressionFactory");
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        try {
+            ClassLoader appcl = getCamelContext().getApplicationContextClassLoader();
+            ClassLoader auxcl = appcl != null ? appcl : DozerEndpoint.class.getClassLoader();
+            Thread.currentThread().setContextClassLoader(auxcl);
+            try {
+                Class<?> clazz = auxcl.loadClass("com.sun.el.ExpressionFactoryImpl");
+                ExpressionFactory factory = (ExpressionFactory) clazz.newInstance();
+                System.setProperty("javax.el.ExpressionFactory", factory.getClass().getName());
+            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
ex) {
+                LOG.debug("Cannot load glasfish expression engine, using default");
+            }
+            ELEngine engine = new ELEngine();
+            engine.init();
+            BeanContainer.getInstance().setElEngine(engine);
+            ElementReader reader = new ExpressionElementReader(engine);
+            BeanContainer.getInstance().setElementReader(reader);
+        } finally {
+            Thread.currentThread().setContextClassLoader(tccl);
+            if (elprop != null)
+                System.setProperty("javax.el.ExpressionFactory", elprop);
+            else
+                System.clearProperty("javax.el.ExpressionFactory");
+        }
+    }
+
     private DozerBeanMapper createDozerBeanMapper() throws Exception {
         DozerBeanMapper answer = DozerComponent.createDozerBeanMapper(Collections.<String>emptyList());
         InputStream mapStream = null;


Mime
View raw message