You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/05/05 12:14:37 UTC
camel git commit: CAMEL-9921: Setup dozer to ensure it loads the EL
engine so it works as expected when it performs mapping such as using
variables.
Repository: camel
Updated Branches:
refs/heads/master 0ff884956 -> 5556d08af
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/5556d08a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5556d08a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5556d08a
Branch: refs/heads/master
Commit: 5556d08af8a32ca23249b5dd132282f1503b2dcb
Parents: 0ff8849
Author: Claus Ibsen <da...@apache.org>
Authored: Thu May 5 12:01:31 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu May 5 14:14:28 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/5556d08a/components/camel-dozer/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-dozer/pom.xml b/components/camel-dozer/pom.xml
index 9a8fdb7..1680c0e 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.18-SNAPSHOT</version>
- </parent>
+ <parent>
+ <artifactId>components</artifactId>
+ <groupId>org.apache.camel</groupId>
+ <version>2.18-SNAPSHOT</version>
+ </parent>
- <artifactId>camel-dozer</artifactId>
- <packaging>jar</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/5556d08a/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 9e056b1..8c0f3db 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;
@@ -107,6 +113,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(
@@ -116,12 +157,7 @@ public class DozerEndpoint extends DefaultEndpoint {
}
configureMapper(mapper);
}
- }
- @Override
- protected void doStop() throws Exception {
- super.doStop();
- // noop
}
private DozerBeanMapper createDozerBeanMapper() throws Exception {