CAMEL-9921: Setup dozer to ensure it loads the EL engine so it works as 
expected when it performs mapping such as using variables.


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

Branch: refs/heads/camel-2.16.x
Commit: 32b2cd56d160b679c09a252a9d9e0c4863b70feb
Parents: d5197cc
Author: Claus Ibsen <davscl...@apache.org>
Authored: Thu May 5 12:01:31 2016 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Thu May 5 12:13:45 2016 +0200

----------------------------------------------------------------------
 components/camel-dozer/pom.xml                  | 126 ++++++++++---------
 .../camel/component/dozer/DozerEndpoint.java    |  46 ++++++-
 2 files changed, 105 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/32b2cd56/components/camel-dozer/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-dozer/pom.xml b/components/camel-dozer/pom.xml
index 9ca2ae6..0f789aa 100644
--- a/components/camel-dozer/pom.xml
+++ b/components/camel-dozer/pom.xml
@@ -15,71 +15,73 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
-    <modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
 
-    <parent>
-        <artifactId>components</artifactId>
-        <groupId>org.apache.camel</groupId>
-        <version>2.16.4-SNAPSHOT</version>
-    </parent>
+  <parent>
+    <artifactId>components</artifactId>
+    <groupId>org.apache.camel</groupId>
+    <version>2.16.4-SNAPSHOT</version>
+  </parent>
 
-    <artifactId>camel-dozer</artifactId>
-    <packaging>bundle</packaging>
-    <name>Camel :: Dozer</name>
-    <description>Camel Support for the Dozer type conversion 
framework</description>
+  <artifactId>camel-dozer</artifactId>
+  <packaging>jar</packaging>
+  <name>Camel :: Dozer</name>
+  <description>Camel Support for the Dozer type conversion 
framework</description>
 
-    <properties>
-        <camel.osgi.export.pkg>
-            org.apache.camel.converter.dozer.*,
-            org.apache.camel.component.dozer.*
-        </camel.osgi.export.pkg>
-    </properties>
+  <properties>
+    <camel.osgi.export.pkg>
+      org.apache.camel.converter.dozer.*,
+      org.apache.camel.component.dozer.*
+    </camel.osgi.export.pkg>
+  </properties>
 
-    <dependencies>
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>net.sf.dozer</groupId>
-            <artifactId>dozer</artifactId>
-        </dependency>
-        <dependency>
-          <groupId>javax.el</groupId>
-          <artifactId>javax.el-api</artifactId>
-          <version>${javax.el-api-version}</version>
-        </dependency>
-        <dependency>
-          <groupId>org.glassfish.web</groupId>
-          <artifactId>javax.el</artifactId>
-          <version>${javax.el-version}</version>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-          <groupId>org.slf4j</groupId>
-          <artifactId>slf4j-log4j12</artifactId>
-          <scope>test</scope>
-        </dependency>
-           <dependency>
-             <groupId>org.apache.camel</groupId>
-             <artifactId>camel-test-spring</artifactId>
-             <scope>test</scope>
-           </dependency>
-           <dependency>
-             <groupId>org.apache.camel</groupId>
-             <artifactId>camel-jaxb</artifactId>
-             <scope>test</scope>
-           </dependency>
-           <dependency>
-             <groupId>org.apache.camel</groupId>
-             <artifactId>camel-jackson</artifactId>
-             <scope>test</scope>
-           </dependency>
-    </dependencies>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>net.sf.dozer</groupId>
+      <artifactId>dozer</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>javax.el</groupId>
+      <artifactId>javax.el-api</artifactId>
+      <version>${javax.el-api-version}</version>
+    </dependency>
+    <!-- must use this glassfish EL implementation -->
+    <dependency>
+      <groupId>org.glassfish.web</groupId>
+      <artifactId>javax.el</artifactId>
+      <version>${javax.el-version}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test-spring</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-jaxb</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-jackson</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
 
 </project>

http://git-wip-us.apache.org/repos/asf/camel/blob/32b2cd56/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 f315bfb..996ac7a 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,6 +21,8 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import com.sun.el.ExpressionFactoryImpl;
+
 import org.apache.camel.Component;
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
@@ -33,6 +35,10 @@ import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ResourceHelper;
 import org.dozer.CustomConverter;
 import org.dozer.DozerBeanMapper;
+import org.dozer.config.BeanContainer;
+import org.dozer.loader.xml.ELEngine;
+import org.dozer.loader.xml.ElementReader;
+import org.dozer.loader.xml.ExpressionElementReader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -104,6 +110,41 @@ public class DozerEndpoint extends DefaultEndpoint {
     protected void doStart() throws Exception {
         super.doStart();
 
+        initDozerBeanContainerAndMapper();
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+        // noop
+    }
+
+    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);
+
+        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);
+        }
+
+        // configure mapper as well
         if (mapper == null) {
             if (configuration.getMappingConfiguration() != null) {
                 mapper = DozerTypeConverterLoader.createDozerBeanMapper(
@@ -113,12 +154,7 @@ public class DozerEndpoint extends DefaultEndpoint {
             }
             configureMapper(mapper);
         }
-    }
 
-    @Override
-    protected void doStop() throws Exception {
-        super.doStop();
-        // noop
     }
 
     private DozerBeanMapper createDozerBeanMapper() throws Exception {

Reply via email to