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 2019/12/06 06:24:56 UTC
[camel] branch master updated: CAMEL-14263: camel-dozer should use
source code generated configurer to avoid reflection configuration.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 9d22378 CAMEL-14263: camel-dozer should use source code generated configurer to avoid reflection configuration.
9d22378 is described below
commit 9d22378aa9257220c9d0ab62cc542b0362602584
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Dec 6 07:23:24 2019 +0100
CAMEL-14263: camel-dozer should use source code generated configurer to avoid reflection configuration.
---
.../org/apache/camel/component/dozer/DozerComponent.java | 12 ++++--------
.../org/apache/camel/component/dozer/DozerEndpoint.java | 5 +++++
.../apache/camel/component/dozer/DozerComponentTest.java | 16 ++++++----------
3 files changed, 15 insertions(+), 18 deletions(-)
diff --git a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerComponent.java b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerComponent.java
index 409a75c..ed3a1e5 100644
--- a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerComponent.java
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerComponent.java
@@ -41,13 +41,9 @@ public class DozerComponent extends DefaultComponent {
config.setMappingConfiguration(getAndRemoveOrResolveReferenceParameter(
parameters, "mappingConfiguration", DozerBeanMapperConfiguration.class));
- setProperties(config, parameters);
-
- // Validate endpoint parameters
- if (config.getTargetModel() == null) {
- throw new IllegalArgumentException("The targetModel parameter is required for dozer endpoints");
- }
-
- return new DozerEndpoint(uri, this, config);
+ DozerEndpoint answer = new DozerEndpoint(uri, this, config);
+ answer.setConfiguration(config);
+ setProperties(answer, parameters);
+ return answer;
}
}
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 4c0c53a..14d60cb 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
@@ -111,6 +111,11 @@ public class DozerEndpoint extends DefaultEndpoint {
protected void initDozerBeanContainerAndMapper() throws Exception {
log.info("Configuring {}...", Mapper.class.getName());
+ // Validate endpoint parameters
+ if (configuration.getTargetModel() == null) {
+ throw new IllegalArgumentException("The targetModel parameter is required for dozer endpoints");
+ }
+
if (mapper == null) {
if (configuration.getMappingConfiguration() == null) {
URL url = ResourceHelper.resolveMandatoryResourceAsUrl(getCamelContext().getClassResolver(), configuration.getMappingFile());
diff --git a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/DozerComponentTest.java b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/DozerComponentTest.java
index 826c1e9..1740c07 100644
--- a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/DozerComponentTest.java
+++ b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/DozerComponentTest.java
@@ -16,18 +16,18 @@
*/
package org.apache.camel.component.dozer;
-import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Assert;
import org.junit.Test;
-public class DozerComponentTest {
+public class DozerComponentTest extends CamelTestSupport {
private static final String NAME = "examplename";
private static final String MARSHAL_ID = "marshal123";
private static final String UNMARSHAL_ID = "unmarshal456";
private static final String SOURCE_MODEL = "org.example.A";
private static final String TARGET_MODEL = "org.example.B";
- private static final String DOZER_CONFIG_PATH = "test/dozerBeanMapping.xml";
+ private static final String DOZER_CONFIG_PATH = "mapping.xml";
private static final String TRANSFORM_EP_1 =
"dozer:" + NAME
+ "?marshalId=" + MARSHAL_ID
@@ -38,9 +38,7 @@ public class DozerComponentTest {
@Test
public void testCreateEndpoint() throws Exception {
- DozerComponent comp = new DozerComponent();
- comp.setCamelContext(new DefaultCamelContext());
- DozerEndpoint ep = (DozerEndpoint)comp.createEndpoint(TRANSFORM_EP_1);
+ DozerEndpoint ep = context.getEndpoint(TRANSFORM_EP_1, DozerEndpoint.class);
DozerConfiguration config = ep.getConfiguration();
Assert.assertEquals(NAME, config.getName());
Assert.assertEquals(MARSHAL_ID, config.getMarshalId());
@@ -52,12 +50,10 @@ public class DozerComponentTest {
@Test
public void requiredTargetModelMissing() throws Exception {
- DozerComponent comp = new DozerComponent();
- comp.setCamelContext(new DefaultCamelContext());
try {
- comp.createEndpoint("dozer:noTargetModel?mappingFile=mapping.xml");
+ DozerEndpoint ep = context.getEndpoint("dozer:noTargetModel?mappingFile=mapping.xml", DozerEndpoint.class);
Assert.fail("targetModel is a required parameter");
- } catch (IllegalArgumentException ex) {
+ } catch (Exception ex) {
// expected
}
}