[ 
https://issues.apache.org/jira/browse/CAMEL-12440?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16437001#comment-16437001
 ] 

ASF GitHub Bot commented on CAMEL-12440:
----------------------------------------

oscerd closed pull request #2291: [CAMEL-12440] Upgraded dozer to 6.2
URL: https://github.com/apache/camel/pull/2291
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/components/camel-dozer/pom.xml b/components/camel-dozer/pom.xml
index ec8ca5b5038..6664fb3d715 100644
--- a/components/camel-dozer/pom.xml
+++ b/components/camel-dozer/pom.xml
@@ -48,17 +48,20 @@
       <groupId>com.github.dozermapper</groupId>
       <artifactId>dozer-core</artifactId>
     </dependency>
+
+    <!-- Expressions -->
     <dependency>
       <groupId>javax.el</groupId>
       <artifactId>javax.el-api</artifactId>
-      <version>${javax.el-api-version}</version>
+      <version>${javax.el3-version}</version>
     </dependency>
-    <!-- must use this glassfish EL implementation -->
     <dependency>
-      <groupId>org.glassfish.web</groupId>
+      <groupId>org.glassfish</groupId>
       <artifactId>javax.el</artifactId>
-      <version>${javax.el-version}</version>
+      <version>${javax.el3-version}</version>
     </dependency>
+
+    <!-- Testing -->
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
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 23b35ffd1aa..c12cdaa37aa 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,8 +21,6 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.el.ExpressionFactory;
-
 import org.apache.camel.Component;
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
@@ -35,9 +33,6 @@
 import org.apache.camel.util.ResourceHelper;
 import org.dozer.CustomConverter;
 import org.dozer.Mapper;
-import org.dozer.config.BeanContainer;
-import org.dozer.loader.xml.ELEngine;
-import org.dozer.loader.xml.ExpressionElementReader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
diff --git 
a/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerBeanMapperConfiguration.java
 
b/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerBeanMapperConfiguration.java
index e29ca58a071..e20fa4f12c6 100644
--- 
a/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerBeanMapperConfiguration.java
+++ 
b/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/DozerBeanMapperConfiguration.java
@@ -19,8 +19,6 @@
 import java.util.List;
 import java.util.Map;
 
-import com.sun.org.apache.xpath.internal.operations.Bool;
-
 import org.dozer.CustomConverter;
 import org.dozer.CustomFieldMapper;
 import org.dozer.DozerEventListener;
diff --git 
a/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/MapperFactory.java
 
b/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/MapperFactory.java
index bc57250f12e..4886b3ca822 100644
--- 
a/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/MapperFactory.java
+++ 
b/components/camel-dozer/src/main/java/org/apache/camel/converter/dozer/MapperFactory.java
@@ -16,23 +16,17 @@
  */
 package org.apache.camel.converter.dozer;
 
-import java.lang.reflect.Field;
-import java.util.Map;
-
-import javax.el.ExpressionFactory;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.dozer.DozerEndpoint;
-import org.apache.camel.util.ReflectionHelper;
-import org.dozer.CustomConverter;
 import org.dozer.DozerBeanMapperBuilder;
-import org.dozer.DozerEventListener;
 import org.dozer.Mapper;
-import org.dozer.config.BeanContainer;
-import org.dozer.config.GlobalSettings;
-import org.dozer.loader.api.BeanMappingBuilder;
-import org.dozer.loader.xml.ELEngine;
-import org.dozer.loader.xml.ExpressionElementReader;
+import org.dozer.config.SettingsKeys;
+import org.dozer.el.DefaultELEngine;
+import org.dozer.el.ELEngine;
+import org.dozer.el.ELExpressionFactory;
+import org.dozer.el.NoopELEngine;
+import org.dozer.el.TcclELEngine;
+import org.dozer.util.RuntimeUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,147 +51,50 @@ public Mapper create() {
     }
 
     private Mapper parseConfiguration(DozerBeanMapperConfiguration 
configuration) {
-        DozerBeanMapperBuilder builder = DozerBeanMapperBuilder.create();
-        if (configuration != null) {
-            if (configuration.getMappingFiles() != null) {
-                String[] files = configuration.getMappingFiles().toArray(new 
String[configuration.getMappingFiles().size()]);
-                builder.withMappingFiles(files);
-            }
-
-            if (configuration.getCustomConverters() != null) {
-                for (CustomConverter current : 
configuration.getCustomConverters()) {
-                    builder.withCustomConverter(current);
-                }
-            }
-            if (configuration.getEventListeners() != null) {
-                for (DozerEventListener current : 
configuration.getEventListeners()) {
-                    builder.withEventListener(current);
-                }
-            }
-
-            if (configuration.getCustomConvertersWithId() != null) {
-                for (Map.Entry<String, CustomConverter> current : 
configuration.getCustomConvertersWithId().entrySet()) {
-                    builder.withCustomConverterWithId(current.getKey(), 
current.getValue());
-                }
-            }
-
-            if (configuration.getBeanMappingBuilders() != null) {
-                for (BeanMappingBuilder current : 
configuration.getBeanMappingBuilders()) {
-                    builder.withMappingBuilder(current);
-                }
-            }
-
-            if (configuration.getCustomFieldMapper() != null) {
-                
builder.withCustomFieldMapper(configuration.getCustomFieldMapper());
-            }
+        configureSettings();
+
+        Mapper mapper;
+        if (configuration == null) {
+            mapper = DozerBeanMapperBuilder.buildDefault();
+        } else {
+            mapper = DozerBeanMapperBuilder.create()
+                    .withMappingFiles(configuration.getMappingFiles())
+                    .withCustomConverters(configuration.getCustomConverters())
+                    .withEventListeners(configuration.getEventListeners())
+                    
.withCustomConvertersWithIds(configuration.getCustomConvertersWithId())
+                    
.withMappingBuilders(configuration.getBeanMappingBuilders())
+                    
.withCustomFieldMapper(configuration.getCustomFieldMapper())
+                    .withELEngine(createELEngine())
+                    .build();
         }
 
-        Mapper mapper = builder.build();
-
-        configureGlobalSettings(mapper);
-        configureBeanContainer(mapper, configuration);
-
         mapper.getMappingMetadata();
 
         return mapper;
     }
 
-    /**
-     * Sets hidden fields on the mapper and returns an instance
-     * NOTE: https://github.com/DozerMapper/dozer/issues/463
-     *
-     * @param mapper
-     */
-    private void configureGlobalSettings(Mapper mapper) {
-        GlobalSettings settings;
-        try {
-            LOG.info("Attempting to retrieve GlobalSettings from: " + mapper);
-            Field field = mapper.getClass().getDeclaredField("globalSettings");
-            field.setAccessible(true);
-
-            settings = (GlobalSettings)field.get(mapper);
-        } catch (Exception e) {
-            throw new IllegalStateException("Cannot retrieve Dozer 
GlobalSettings due " + e.getMessage(), e);
-        }
-
-        //Safety check
-        if (settings == null) {
-            throw new IllegalStateException("Cannot retrieve Dozer 
GlobalSettings due null reflection response");
-        }
-
-        try {
-            LOG.info("Configuring GlobalSettings to use Camel classloader: 
{}", DozerThreadContextClassLoader.class.getName());
-            Field field = 
settings.getClass().getDeclaredField("classLoaderBeanName");
-            ReflectionHelper.setField(field, settings, 
DozerThreadContextClassLoader.class.getName());
-        } catch (Exception e) {
-            throw new IllegalStateException("Cannot configure Dozer 
GlobalSettings to use DozerThreadContextClassLoader as classloader due " + 
e.getMessage(), e);
-        }
-
-        try {
-            LOG.info("Configuring GlobalSettings to enable EL");
-            Field field = settings.getClass().getDeclaredField("elEnabled");
-            ReflectionHelper.setField(field, settings, true);
-        } catch (NoSuchFieldException nsfEx) {
-            throw new IllegalStateException("Failed to enable EL in global 
Dozer settings", nsfEx);
-        }
+    private void configureSettings() {
+        System.setProperty(SettingsKeys.CLASS_LOADER_BEAN, 
DozerThreadContextClassLoader.class.getName());
     }
 
-    public void configureBeanContainer(Mapper mapper, 
DozerBeanMapperConfiguration configuration) {
-        String elprop = System.getProperty("javax.el.ExpressionFactory");
-        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
-        try {
-            ClassLoader appcl = 
camelContext.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");
-            }
-
-            BeanContainer beanContainer = resolveBeanContainer(mapper);
-            if (beanContainer.getElEngine() == null) {
-                ELEngine engine = new ELEngine();
-                engine.init();
+    private ELEngine createELEngine() {
+        ELEngine answer;
 
-                beanContainer.setElEngine(engine);
-            }
+        ClassLoader appcl = camelContext.getApplicationContextClassLoader();
+        ClassLoader auxcl = appcl == null ? 
DozerEndpoint.class.getClassLoader() : appcl;
 
-            beanContainer.setElementReader(new 
ExpressionElementReader(beanContainer.getElEngine()));
-        } finally {
-            Thread.currentThread().setContextClassLoader(tccl);
-            if (elprop == null) {
-                System.clearProperty("javax.el.ExpressionFactory");
+        if (ELExpressionFactory.isSupported(auxcl)) {
+            if (RuntimeUtils.isOSGi()) {
+                answer = new 
TcclELEngine(ELExpressionFactory.newInstance(auxcl), auxcl);
             } else {
-                System.setProperty("javax.el.ExpressionFactory", elprop);
+                answer = new 
DefaultELEngine(ELExpressionFactory.newInstance());
             }
-        }
-    }
-
-    private BeanContainer resolveBeanContainer(Mapper mapper) {
-        LOG.info("Attempting to retrieve BeanContainer from: " + mapper);
-
-        BeanContainer beanContainer = (BeanContainer)resolveProperty(mapper, 
"beanContainer");
-        if (beanContainer == null) {
-            throw new IllegalStateException("Cannot retrieve Dozer 
BeanContainer due null response");
-        }
-
-        return beanContainer;
-    }
-
-    private static Object resolveProperty(Mapper mapper, String fieldName) {
-        Object prop;
-        try {
-            Field field = mapper.getClass().getDeclaredField(fieldName);
-            field.setAccessible(true);
+        } else {
+            LOG.warn("Expressions are not supported by Dozer. Are you missing 
javax.el dependency?");
 
-            prop = field.get(mapper);
-        } catch (Exception e) {
-            throw new IllegalStateException("Cannot retrieve DozerBeanMapper." 
+ fieldName + " due " + e.getMessage(), e);
+            answer = new NoopELEngine();
         }
 
-        return prop;
+        return answer;
     }
 }
diff --git a/parent/pom.xml b/parent/pom.xml
index 1aa665e43c0..429f5b27522 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -189,7 +189,7 @@
     <docker-java-bundle-version>3.0.14_1</docker-java-bundle-version>
     <docker-maven-plugin-version>0.25.0</docker-maven-plugin-version>
     <dom4j-bundle-version>1.6.1_5</dom4j-bundle-version>
-    <dozer-version>6.1.0</dozer-version>
+    <dozer-version>6.2.0</dozer-version>
     <drools-version>7.3.0.Final</drools-version>
     <dropbox-version>3.0.6</dropbox-version>
     
<eclipse-equinox-common-version>3.3.0-v20070426</eclipse-equinox-common-version>
@@ -355,6 +355,7 @@
     <javassist-version>3.20.0-GA</javassist-version>
     <javax.el-api-version>2.2.5</javax.el-api-version>
     <javax.el-version>2.2.5</javax.el-version>
+    <javax.el3-version>3.0.0</javax.el3-version>
     
<javax.el-api-hibernate-validator-version>3.0.1-b04</javax.el-api-hibernate-validator-version>
     
<javax.el-hibernate-validator-version>3.0.1-b10</javax.el-hibernate-validator-version>
     <javax-inject-bundle-version>1_2</javax-inject-bundle-version>
@@ -525,6 +526,7 @@
     
<networknt-json-schema-validator-version>0.1.17</networknt-json-schema-validator-version>
     <noggit-bundle-version>0.5_1</noggit-bundle-version>
     <!-- should be in-sync with deltaspike -->
+    <objenesis-version>2.6</objenesis-version>
     <openwebbeans1-version>1.2.7</openwebbeans1-version>
     <openwebbeans-version>1.7.3</openwebbeans-version>
     <oauth-provider-bundle-version>20100527_1</oauth-provider-bundle-version>
diff --git a/platforms/karaf/features/src/main/resources/features.xml 
b/platforms/karaf/features/src/main/resources/features.xml
index b6080c245a9..b1cb57b8e44 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -538,12 +538,13 @@
     <feature version='${project.version}'>camel-core</feature>
     <feature>war</feature>
     <bundle 
dependency='true'>mvn:com.github.dozermapper/dozer-core/${dozer-version}</bundle>
-    <bundle 
dependency='true'>mvn:com.github.dozermapper/dozer-schema/${dozer-version}</bundle>
     <bundle 
dependency='true'>mvn:org.apache.commons/commons-lang3/${commons-lang3-version}</bundle>
     <bundle 
dependency='true'>mvn:commons-collections/commons-collections/${commons-collections-version}</bundle>
     <bundle 
dependency='true'>mvn:commons-beanutils/commons-beanutils/${commons-beanutils-version}</bundle>
-    <bundle 
dependency='true'>mvn:javax.el/javax.el-api/${javax.el-api-version}</bundle>
-    <bundle 
dependency='true'>mvn:org.glassfish.web/javax.el/${javax.el-version}</bundle>
+    <bundle 
dependency='true'>mvn:commons-io/commons-io/${commons-io-version}</bundle>
+    <bundle 
dependency='true'>mvn:javax.el/javax.el-api/${javax.el3-version}</bundle>
+    <bundle 
dependency='true'>mvn:org.glassfish/javax.el/${javax.el3-version}</bundle>
+    <bundle 
dependency='true'>mvn:org.objenesis/objenesis/${objenesis-version}</bundle>
     <bundle>mvn:org.apache.camel/camel-dozer/${project.version}</bundle>
   </feature>
   <feature name='camel-dropbox' version='${project.version}' resolver='(obr)' 
start-level='50'>
diff --git 
a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml 
b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
index c7b39f43d75..7db5e035481 100644
--- 
a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
+++ 
b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
@@ -88,7 +88,7 @@
       <dependency>
         <groupId>com.github.dozermapper</groupId>
         <artifactId>dozer-core</artifactId>
-        <version>6.1.0</version>
+        <version>6.2.0</version>
       </dependency>
       <dependency>
         <groupId>com.google.code.scriptengines</groupId>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Upgrade camel-dozer to 6.2
> --------------------------
>
>                 Key: CAMEL-12440
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12440
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-dozer
>            Reporter: Gareth Healy
>            Assignee: Andrea Cosentino
>            Priority: Major
>             Fix For: 2.22.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to