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 2015/02/11 09:41:35 UTC
[1/4] camel git commit: CAMEL-8332: Add component implementation to
camel-dozer module
Repository: camel
Updated Branches:
refs/heads/master fee91e7b0 -> 0e50f2c70
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/dozerBeanMapping.xml
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/dozerBeanMapping.xml b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/dozerBeanMapping.xml
new file mode 100644
index 0000000..4af9249
--- /dev/null
+++ b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/dozerBeanMapping.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<mappings xmlns="http://dozer.sourceforge.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://dozer.sourceforge.net http://dozer.sourceforge.net/schema/beanmapping.xsd">
+ <mapping>
+ <class-a>org.apache.camel.component.dozer.example.abc.ABCOrder</class-a>
+ <class-b>org.apache.camel.component.dozer.example.xyz.XYZOrder</class-b>
+ <field>
+ <a>header.customerNum</a>
+ <b>custId</b>
+ </field>
+ <field>
+ <a>header.status</a>
+ <b>priority</b>
+ </field>
+ <field>
+ <a>header.orderNum</a>
+ <b>orderId</b>
+ </field>
+ <field>
+ <a>orderItems.item</a>
+ <b>lineItems</b>
+ </field>
+ </mapping>
+ <mapping>
+ <class-a>org.apache.camel.component.dozer.example.abc.ABCOrder$OrderItems$Item</class-a>
+ <class-b>org.apache.camel.component.dozer.example.xyz.LineItem</class-b>
+ <field>
+ <a>id</a>
+ <b>itemId</b>
+ </field>
+ <field>
+ <a>price</a>
+ <b>cost</b>
+ </field>
+ <field>
+ <a>quantity</a>
+ <b>amount</b>
+ </field>
+ </mapping>
+</mappings>
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/literalMapping.xml
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/literalMapping.xml b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/literalMapping.xml
new file mode 100644
index 0000000..481f0a4
--- /dev/null
+++ b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/literalMapping.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<mappings xmlns="http://dozer.sourceforge.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://dozer.sourceforge.net http://dozer.sourceforge.net/schema/beanmapping.xsd">
+ <mapping>
+ <class-a>org.apache.camel.component.dozer.example.abc.ABCOrder</class-a>
+ <class-b>org.apache.camel.component.dozer.example.xyz.XYZOrder</class-b>
+ <field>
+ <a>header.status</a>
+ <b>priority</b>
+ </field>
+ <field>
+ <a>header.orderNum</a>
+ <b>orderId</b>
+ </field>
+ </mapping>
+ <mapping>
+ <class-a>org.apache.camel.component.dozer.LiteralMapper</class-a>
+ <class-b>org.apache.camel.component.dozer.example.xyz.XYZOrder</class-b>
+ <field custom-converter-id="_literalMapping" custom-converter-param="LITERAL_CUST_ID">
+ <a>literal</a>
+ <b>custId</b>
+ </field>
+ <field custom-converter-id="_literalMapping" custom-converter-param="LITERAL_ORDER_ID">
+ <a>literal</a>
+ <b>orderId</b>
+ </field>
+ </mapping>
+ <mapping>
+ <class-a>org.apache.camel.component.dozer.example.abc.ABCOrder$OrderItems$Item</class-a>
+ <class-b>org.apache.camel.component.dozer.example.xyz.LineItem</class-b>
+ <field>
+ <a>id</a>
+ <b>itemId</b>
+ </field>
+ <field>
+ <a>price</a>
+ <b>cost</b>
+ </field>
+ <field>
+ <a>quantity</a>
+ <b>amount</b>
+ </field>
+ </mapping>
+</mappings>
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/xyz-order.json
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/xyz-order.json b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/xyz-order.json
new file mode 100644
index 0000000..cc90787
--- /dev/null
+++ b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/xyz-order.json
@@ -0,0 +1 @@
+{"custId":"ACME-123","priority":"GOLD","orderId":"ORDER1","lineItems":[{"itemId":"PICKLE","amount":1000,"cost":2.25}]}
\ No newline at end of file
[2/4] camel git commit: CAMEL-8332: Add component implementation to
camel-dozer module
Posted by da...@apache.org.
CAMEL-8332: Add component implementation to camel-dozer module
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e085e28d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e085e28d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e085e28d
Branch: refs/heads/master
Commit: e085e28d7c4100634d543ab418bc9bf1a63638ce
Parents: fee91e7
Author: Keith Babo <kb...@redhat.com>
Authored: Wed Feb 4 10:31:14 2015 -0500
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Feb 11 08:54:02 2015 +0100
----------------------------------------------------------------------
components/camel-dozer/pom.xml | 21 +-
.../camel/component/dozer/BaseConverter.java | 50 +++
.../camel/component/dozer/CustomMapper.java | 95 +++++
.../camel/component/dozer/DozerComponent.java | 44 ++
.../component/dozer/DozerConfiguration.java | 96 +++++
.../camel/component/dozer/DozerEndpoint.java | 129 ++++++
.../camel/component/dozer/DozerProducer.java | 153 +++++++
.../camel/component/dozer/LiteralMapper.java | 44 ++
.../services/org/apache/camel/component/dozer | 17 +
.../camel/component/dozer/CustomMapperTest.java | 101 +++++
.../component/dozer/CustomMappingTest.java | 67 +++
.../component/dozer/DozerComponentTest.java | 52 +++
.../component/dozer/LiteralMappingTest.java | 67 +++
.../camel/component/dozer/XmlToJsonTest.java | 82 ++++
.../component/dozer/example/CustomMapper.java | 27 ++
.../dozer/example/CustomMapperOperations.java | 31 ++
.../component/dozer/example/abc/ABCOrder.java | 418 +++++++++++++++++++
.../dozer/example/abc/ObjectFactory.java | 79 ++++
.../component/dozer/example/xyz/LineItem.java | 107 +++++
.../component/dozer/example/xyz/XYZOrder.java | 132 ++++++
.../dozer/CustomMappingTest-context.xml | 29 ++
.../dozer/LiteralMappingTest-context.xml | 29 ++
.../component/dozer/XmlToJsonTest-context.xml | 33 ++
.../apache/camel/component/dozer/abc-order.xml | 30 ++
.../camel/component/dozer/customMapping.xml | 57 +++
.../camel/component/dozer/dozerBeanMapping.xml | 55 +++
.../camel/component/dozer/literalMapping.xml | 59 +++
.../apache/camel/component/dozer/xyz-order.json | 1 +
28 files changed, 2103 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-dozer/pom.xml b/components/camel-dozer/pom.xml
index c4c276a..75b177a 100644
--- a/components/camel-dozer/pom.xml
+++ b/components/camel-dozer/pom.xml
@@ -30,7 +30,10 @@
<description>Camel Support for the Dozer type conversion framework</description>
<properties>
- <camel.osgi.export.pkg>org.apache.camel.converter.dozer.*</camel.osgi.export.pkg>
+ <camel.osgi.export.pkg>
+ org.apache.camel.converter.dozer.*,
+ org.apache.camel.component.dozer.*
+ </camel.osgi.export.pkg>
</properties>
<dependencies>
@@ -57,7 +60,21 @@
<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/e085e28d/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/BaseConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/BaseConverter.java b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/BaseConverter.java
new file mode 100644
index 0000000..d57167d
--- /dev/null
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/BaseConverter.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer;
+
+import org.dozer.ConfigurableCustomConverter;
+
+/**
+ * Configurable converters in Dozer are not thread-safe if a single converter
+ * instance is used. One thread could step on the parameter being used by
+ * another thread since setParameter() is called first and convert() is called
+ * separately. This implementation holds a copy of the parameter in
+ * thread-local storage which eliminates the possibility of collision between
+ * threads on a single converter instance.
+ *
+ * Any converter which is referenced by ID with the Dozer component should
+ * extend this class. It is recommended to call done() in a finally block
+ * in the implementation of convert() to clean up the value stored in the
+ * thread local.
+ */
+public abstract class BaseConverter implements ConfigurableCustomConverter {
+
+ private ThreadLocal<String> localParameter = new ThreadLocal<String>();
+
+ @Override
+ public void setParameter(String parameter) {
+ localParameter.set(parameter);
+ }
+
+ public void done() {
+ localParameter.set(null);
+ }
+
+ public String getParameter() {
+ return localParameter.get();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/CustomMapper.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/CustomMapper.java b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/CustomMapper.java
new file mode 100644
index 0000000..7d46d4b
--- /dev/null
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/CustomMapper.java
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer;
+
+import java.lang.reflect.Method;
+
+import org.apache.camel.spi.ClassResolver;
+
+/**
+ * Allows a user to customize a field mapping using a POJO that is not
+ * required to extend/implement Dozer-specific classes.
+ */
+public class CustomMapper extends BaseConverter {
+
+ private ClassResolver resolver;
+
+ public CustomMapper(ClassResolver resolver) {
+ this.resolver = resolver;
+ }
+
+ @Override
+ public Object convert(Object existingDestinationFieldValue,
+ Object sourceFieldValue,
+ Class<?> destinationClass,
+ Class<?> sourceClass) {
+ try {
+ return mapCustom(sourceFieldValue);
+ } finally {
+ done();
+ }
+ }
+
+ Method selectMethod(Class<?> customClass, Object fromType) {
+ Method method = null;
+ for (Method m : customClass.getDeclaredMethods()) {
+ if (m.getReturnType() != null
+ && m.getParameterTypes().length == 1
+ && m.getParameterTypes()[0].isAssignableFrom(fromType.getClass())) {
+ method = m;
+ break;
+ }
+ }
+ return method;
+ }
+
+ Object mapCustom(Object source) {
+ Object customMapObj;
+ Method mapMethod = null;
+
+ // The converter parameter is stored in a thread local variable, so
+ // we need to parse the parameter on each invocation
+ String[] params = getParameter().split(",");
+ String className = params[0];
+ String operation = params.length > 1 ? params[1] : null;
+
+ try {
+ Class<?> customClass = resolver.resolveClass(className);
+ customMapObj = customClass.newInstance();
+ // If a specific mapping operation has been supplied use that
+ if (operation != null) {
+ mapMethod = customClass.getMethod(operation, source.getClass());
+ } else {
+ mapMethod = selectMethod(customClass, source);
+ }
+ } catch (Exception cnfEx) {
+ throw new RuntimeException("Failed to load custom mapping", cnfEx);
+ }
+
+ // Verify that we found a matching method
+ if (mapMethod == null) {
+ throw new RuntimeException("No eligible custom mapping methods in " + className);
+ }
+
+ // Invoke the custom mapping method
+ try {
+ return mapMethod.invoke(customMapObj, source);
+ } catch (Exception ex) {
+ throw new RuntimeException("Error while invoking custom mapping", ex);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerComponent.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..09a44ce
--- /dev/null
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerComponent.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.UriEndpointComponent;
+
+/**
+ * Represents the component that manages {@link DozerEndpoint}.
+ */
+public class DozerComponent extends UriEndpointComponent {
+
+ public DozerComponent() {
+ super(DozerEndpoint.class);
+ }
+
+ public DozerComponent(CamelContext context) {
+ super(context, DozerEndpoint.class);
+ }
+
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ DozerConfiguration config = new DozerConfiguration();
+ config.setName(remaining);
+ setProperties(config, parameters);
+ return new DozerEndpoint(uri, this, config);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerConfiguration.java b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerConfiguration.java
new file mode 100644
index 0000000..c390c05
--- /dev/null
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerConfiguration.java
@@ -0,0 +1,96 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer;
+
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+import org.apache.camel.spi.UriPath;
+
+import static org.dozer.util.DozerConstants.DEFAULT_MAPPING_FILE;
+
+
+/**
+ * Configuration used for a Dozer endpoint.
+ */
+@UriParams
+public class DozerConfiguration {
+
+ @UriPath
+ private String name;
+ @UriParam
+ private String marshalId;
+ @UriParam
+ private String unmarshalId;
+ @UriParam
+ private String sourceModel;
+ @UriParam
+ private String targetModel;
+ @UriParam(defaultValue = DEFAULT_MAPPING_FILE)
+ private String mappingFile;
+
+ public DozerConfiguration() {
+ setMappingFile(DEFAULT_MAPPING_FILE);
+ }
+
+ public String getMarshalId() {
+ return marshalId;
+ }
+
+ public void setMarshalId(String marshalId) {
+ this.marshalId = marshalId;
+ }
+
+ public String getUnmarshalId() {
+ return unmarshalId;
+ }
+
+ public void setUnmarshalId(String unmarshalId) {
+ this.unmarshalId = unmarshalId;
+ }
+
+ public String getSourceModel() {
+ return sourceModel;
+ }
+
+ public void setSourceModel(String sourceModel) {
+ this.sourceModel = sourceModel;
+ }
+
+ public String getTargetModel() {
+ return targetModel;
+ }
+
+ public void setTargetModel(String targetModel) {
+ this.targetModel = targetModel;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getMappingFile() {
+ return mappingFile;
+ }
+
+ public void setMappingFile(String mappingFile) {
+ this.mappingFile = mappingFile;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/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
new file mode 100644
index 0000000..0bcbda0
--- /dev/null
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerEndpoint.java
@@ -0,0 +1,129 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.util.ResourceHelper;
+import org.dozer.CustomConverter;
+import org.dozer.DozerBeanMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Represents a Dozer endpoint.
+ */
+@UriEndpoint(scheme = "dozer", label = "transformation")
+public class DozerEndpoint extends DefaultEndpoint {
+ private static final Logger LOG = LoggerFactory.getLogger(DozerEndpoint.class);
+
+ // IDs for built-in custom converters used with the Dozer component
+ private static final String CUSTOM_MAPPING_ID = "_customMapping";
+ private static final String LITERAL_MAPPING_ID = "_literalMapping";
+
+ private DozerConfiguration configuration;
+ private DozerBeanMapper mapper;
+ private LiteralMapper literalMapper;
+ private CustomMapper customMapper;
+
+ /**
+ * Create a new TransformEndpoint.
+ * @param endpointUri The uri of the Camel endpoint.
+ * @param component The {@link DozerComponent}.
+ * @param configuration endpoint configuration
+ */
+ public DozerEndpoint(String endpointUri, Component component, DozerConfiguration configuration) throws Exception {
+ super(endpointUri, component);
+ this.configuration = configuration;
+ literalMapper = new LiteralMapper();
+ customMapper = new CustomMapper(getCamelContext().getClassResolver());
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new DozerProducer(this);
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new UnsupportedOperationException(
+ "Consumer not supported for Transform endpoints");
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return true;
+ }
+
+ public synchronized DozerBeanMapper getMapper() throws Exception {
+ if (mapper == null) {
+ initDozer();
+ }
+ return mapper;
+ }
+
+ public DozerConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(DozerConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ CustomMapper getCustomMapper() {
+ return customMapper;
+ }
+
+ LiteralMapper getLiteralMapper() {
+ return literalMapper;
+ }
+
+ private void initDozer() throws Exception {
+ mapper = new DozerBeanMapper();
+ InputStream mapStream = null;
+ try {
+ LOG.info("Loading Dozer mapping file {}.", configuration.getMappingFile());
+ // create the mapper instance and add the mapping file
+ mapStream = ResourceHelper.resolveResourceAsInputStream(
+ getCamelContext().getClassResolver(), configuration.getMappingFile());
+ if (mapStream == null) {
+ throw new Exception("Unable to resolve Dozer config: " + configuration.getMappingFile());
+ }
+ mapper.addMapping(mapStream);
+
+ // add our built-in converters
+ Map<String, CustomConverter> converters = new HashMap<String, CustomConverter>();
+ converters.put(CUSTOM_MAPPING_ID, customMapper);
+ converters.put(LITERAL_MAPPING_ID, literalMapper);
+ converters.putAll(mapper.getCustomConvertersWithId());
+ mapper.setCustomConvertersWithId(converters);
+
+ } finally {
+ if (mapStream != null) {
+ mapStream.close();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java
new file mode 100644
index 0000000..fd7f6c4
--- /dev/null
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java
@@ -0,0 +1,153 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer;
+
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.model.DataFormatDefinition;
+import org.apache.camel.processor.MarshalProcessor;
+import org.apache.camel.processor.UnmarshalProcessor;
+import org.apache.camel.spi.DataFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Producer class for Dozer endpoints.
+ */
+public class DozerProducer extends DefaultProducer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DozerProducer.class);
+
+ private DozerEndpoint endpoint;
+ private UnmarshalProcessor unmarshaller;
+ private MarshalProcessor marshaller;
+
+ /**
+ * Create a new producer for dozer endpoints.
+ * @param endpoint endpoint requiring a producer
+ */
+ public DozerProducer(DozerEndpoint endpoint) {
+ super(endpoint);
+ this.endpoint = endpoint;
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ // Unmarshal the source content only if an unmarshaller is configured.
+ String unmarshalId = endpoint.getConfiguration().getUnmarshalId();
+ if (unmarshalId != null) {
+ LOG.debug("Unmarshalling input data using data format '{}'.", unmarshalId);
+ resolveUnmarshaller(exchange, unmarshalId).process(exchange);
+ }
+
+ // Load the target model class
+ Class<?> targetModel = endpoint.getCamelContext().getClassResolver().resolveClass(
+ endpoint.getConfiguration().getTargetModel());
+ // If an unmarshaller was used, the unmarshalled message is the OUT
+ // message.
+ Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
+ LOG.debug("Mapping to target model {}.", targetModel.getName());
+ // Trigger the Dozer mapping and set that as the content of the IN message
+ Object targetObject = endpoint.getMapper().map(msg.getBody(), targetModel);
+ // Second pass to process literal mappings
+ endpoint.getMapper().map(endpoint.getLiteralMapper(), targetObject);
+ msg.setBody(targetObject);
+ exchange.setIn(msg);
+
+ // Marshal the source content only if a marshaller is configured.
+ String marshalId = endpoint.getConfiguration().getMarshalId();
+ if (marshalId != null) {
+ LOG.debug("Marshalling output data using data format '{}'.", marshalId);
+ resolveMarshaller(exchange, marshalId).process(exchange);
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ super.doStop();
+ if (unmarshaller != null) {
+ unmarshaller.stop();
+ }
+ if (marshaller != null) {
+ marshaller.stop();
+ }
+ }
+
+ @Override
+ protected void doShutdown() throws Exception {
+ super.doShutdown();
+ if (unmarshaller != null) {
+ unmarshaller.shutdown();
+ }
+ if (marshaller != null) {
+ marshaller.shutdown();
+ }
+ }
+
+ /**
+ * Find and configure an unmarshaller for the specified data format.
+ */
+ private synchronized UnmarshalProcessor resolveUnmarshaller(
+ Exchange exchange, String dataFormatId) throws Exception {
+
+ if (unmarshaller == null) {
+ DataFormat dataFormat = DataFormatDefinition.getDataFormat(
+ exchange.getUnitOfWork().getRouteContext(), null, dataFormatId);
+ if (dataFormat == null) {
+ throw new Exception("Unable to resolve data format for unmarshalling: " + dataFormatId);
+ }
+
+ // Wrap the data format in a processor and start/configure it.
+ // Stop/shutdown is handled when the corresponding methods are
+ // called on this producer.
+ unmarshaller = new UnmarshalProcessor(dataFormat);
+ if (unmarshaller instanceof CamelContextAware) {
+ ((CamelContextAware)unmarshaller).setCamelContext(exchange.getContext());
+ }
+ unmarshaller.start();
+ }
+ return unmarshaller;
+ }
+
+ /**
+ * Find and configure an unmarshaller for the specified data format.
+ */
+ private synchronized MarshalProcessor resolveMarshaller(
+ Exchange exchange, String dataFormatId) throws Exception {
+
+ if (marshaller == null) {
+ DataFormat dataFormat = DataFormatDefinition.getDataFormat(
+ exchange.getUnitOfWork().getRouteContext(), null, dataFormatId);
+ if (dataFormat == null) {
+ throw new Exception("Unable to resolve data format for marshalling: " + dataFormatId);
+ }
+
+ // Wrap the data format in a processor and start/configure it.
+ // Stop/shutdown is handled when the corresponding methods are
+ // called on this producer.
+ marshaller = new MarshalProcessor(dataFormat);
+ if (marshaller instanceof CamelContextAware) {
+ ((CamelContextAware)marshaller).setCamelContext(exchange.getContext());
+ }
+ marshaller.start();
+ }
+ return marshaller;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/LiteralMapper.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/LiteralMapper.java b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/LiteralMapper.java
new file mode 100644
index 0000000..4d09963
--- /dev/null
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/LiteralMapper.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer;
+
+/**
+ * Used to map literal values (e.g. "ACME" or "ABC-123") to a field in the
+ * target object.
+ */
+public class LiteralMapper extends BaseConverter {
+
+ @Override
+ public Object convert(Object existingDestinationFieldValue,
+ Object sourceFieldValue,
+ Class<?> destinationClass,
+ Class<?> sourceClass) {
+ try {
+ return getParameter();
+ } finally {
+ done();
+ }
+ }
+
+ /**
+ * We need at least one field in this class so that we can use it as a
+ * source for Dozer transformations.
+ */
+ public String getLiteral() {
+ return getParameter();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/main/resources/META-INF/services/org/apache/camel/component/dozer
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/main/resources/META-INF/services/org/apache/camel/component/dozer b/components/camel-dozer/src/main/resources/META-INF/services/org/apache/camel/component/dozer
new file mode 100644
index 0000000..22afe69
--- /dev/null
+++ b/components/camel-dozer/src/main/resources/META-INF/services/org/apache/camel/component/dozer
@@ -0,0 +1,17 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+class=org.apache.camel.component.dozer.DozerComponent
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/CustomMapperTest.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/CustomMapperTest.java b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/CustomMapperTest.java
new file mode 100644
index 0000000..259a426
--- /dev/null
+++ b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/CustomMapperTest.java
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer;
+
+import java.lang.reflect.Method;
+
+import org.apache.camel.impl.DefaultClassResolver;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CustomMapperTest {
+
+ private CustomMapper customMapper;
+
+ @Before
+ public void setup() {
+ customMapper = new CustomMapper(new DefaultClassResolver());
+ }
+
+ @Test
+ public void selectMapperOneMethod() {
+ customMapper.setParameter(MapperWithOneMethod.class.getName());
+ Assert.assertNotNull(customMapper.selectMethod(MapperWithOneMethod.class, "test"));
+ }
+
+ @Test
+ public void selectMapperMultipleMethods() throws Exception {
+ Method selectedMethod = customMapper.selectMethod(MapperWithTwoMethods.class, new B());
+ Assert.assertNotNull(selectedMethod);
+ Assert.assertEquals(
+ MapperWithTwoMethods.class.getMethod("convertToA", B.class),
+ selectedMethod);
+ }
+
+ @Test
+ public void mapCustomFindOperation() throws Exception {
+ customMapper.setParameter(MapperWithTwoMethods.class.getName());
+ Assert.assertNotNull(customMapper.mapCustom(new B()));
+ }
+
+ @Test
+ public void mapCustomDeclaredOperation() throws Exception {
+ customMapper.setParameter(MapperWithTwoMethods.class.getName() + ",convertToA");
+ Assert.assertNotNull(customMapper.mapCustom(new B()));
+ }
+
+ @Test
+ public void mapCustomInvalidOperation() {
+ customMapper.setParameter(MapperWithTwoMethods.class.getName() + ",convertToB");
+ try {
+ customMapper.mapCustom(new B());
+ Assert.fail("Invalid operation should result in exception");
+ } catch (RuntimeException ex) {
+ Assert.assertTrue(ex.getCause() instanceof NoSuchMethodException);
+ }
+ }
+}
+
+class A {
+
+}
+
+class B extends A {
+
+}
+
+class MapperWithOneMethod {
+
+ public A convertToA(String val) {
+ return new A();
+ }
+}
+
+class MapperWithTwoMethods {
+
+ public A convertToA(String val) {
+ return new A();
+ }
+
+ public A convertToA(B val) {
+ return new A();
+ }
+
+}
+
+
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/CustomMappingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/CustomMappingTest.java b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/CustomMappingTest.java
new file mode 100644
index 0000000..6b44a2c
--- /dev/null
+++ b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/CustomMappingTest.java
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.dozer.example.abc.ABCOrder;
+import org.apache.camel.component.dozer.example.abc.ABCOrder.Header;
+import org.apache.camel.component.dozer.example.xyz.XYZOrder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+public class CustomMappingTest {
+
+ @EndpointInject(uri = "mock:result")
+ private MockEndpoint resultEndpoint;
+
+ @Produce(uri = "direct:start")
+ private ProducerTemplate startEndpoint;
+
+ @Autowired
+ private CamelContext camelContext;
+
+ @After
+ public void tearDown() {
+ resultEndpoint.reset();
+ }
+
+ @Test
+ public void testCustomMapping() throws Exception {
+ resultEndpoint.expectedMessageCount(1);
+ ABCOrder abcOrder = new ABCOrder();
+ abcOrder.setHeader(new Header());
+ abcOrder.getHeader().setStatus("GOLD");
+ abcOrder.getHeader().setCustomerNum("ACME");
+ startEndpoint.sendBody(abcOrder);
+ // check results
+ resultEndpoint.assertIsSatisfied();
+ XYZOrder result = resultEndpoint.getExchanges().get(0).getIn().getBody(XYZOrder.class);
+ Assert.assertEquals(result.getPriority(), "custom2:GOLD");
+ Assert.assertEquals(result.getCustId(), "mapCustomer:ACME");
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/DozerComponentTest.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..4dad0f0
--- /dev/null
+++ b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/DozerComponentTest.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer;
+
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DozerComponentTest {
+
+ 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 TRANSFORM_EP_1 =
+ "dozer:" + NAME
+ + "?marshalId=" + MARSHAL_ID
+ + "&unmarshalId=" + UNMARSHAL_ID
+ + "&sourceModel=" + SOURCE_MODEL
+ + "&targetModel=" + TARGET_MODEL
+ + "&mappingFile=" + DOZER_CONFIG_PATH;
+
+ @Test
+ public void testCreateEndpoint() throws Exception {
+ DozerComponent comp = new DozerComponent();
+ comp.setCamelContext(new DefaultCamelContext());
+ DozerEndpoint ep = (DozerEndpoint)comp.createEndpoint(TRANSFORM_EP_1);
+ DozerConfiguration config = ep.getConfiguration();
+ Assert.assertEquals(NAME, config.getName());
+ Assert.assertEquals(MARSHAL_ID, config.getMarshalId());
+ Assert.assertEquals(UNMARSHAL_ID, config.getUnmarshalId());
+ Assert.assertEquals(SOURCE_MODEL, config.getSourceModel());
+ Assert.assertEquals(TARGET_MODEL, config.getTargetModel());
+ Assert.assertEquals(DOZER_CONFIG_PATH, config.getMappingFile());
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/LiteralMappingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/LiteralMappingTest.java b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/LiteralMappingTest.java
new file mode 100644
index 0000000..f519991
--- /dev/null
+++ b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/LiteralMappingTest.java
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.dozer.example.abc.ABCOrder;
+import org.apache.camel.component.dozer.example.abc.ABCOrder.Header;
+import org.apache.camel.component.dozer.example.xyz.XYZOrder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+public class LiteralMappingTest {
+
+ @EndpointInject(uri = "mock:result")
+ private MockEndpoint resultEndpoint;
+
+ @Produce(uri = "direct:start")
+ private ProducerTemplate startEndpoint;
+
+ @Autowired
+ private CamelContext camelContext;
+
+ @After
+ public void tearDown() {
+ resultEndpoint.reset();
+ }
+
+ @Test
+ public void testLiteralMapping() throws Exception {
+ resultEndpoint.expectedMessageCount(1);
+ ABCOrder abcOrder = new ABCOrder();
+ abcOrder.setHeader(new Header());
+ abcOrder.getHeader().setStatus("GOLD");
+ startEndpoint.sendBody(abcOrder);
+ // check results
+ resultEndpoint.assertIsSatisfied();
+ XYZOrder result = resultEndpoint.getExchanges().get(0).getIn().getBody(XYZOrder.class);
+ Assert.assertEquals(result.getPriority(), "GOLD");
+ Assert.assertEquals(result.getCustId(), "LITERAL_CUST_ID");
+ Assert.assertEquals(result.getOrderId(), "LITERAL_ORDER_ID");
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/XmlToJsonTest.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/XmlToJsonTest.java b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/XmlToJsonTest.java
new file mode 100644
index 0000000..03ba54f
--- /dev/null
+++ b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/XmlToJsonTest.java
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer;
+
+import java.io.InputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+public class XmlToJsonTest {
+
+ private static final String ABC_ORDER_PATH = "org/apache/camel/component/dozer/abc-order.xml";
+ private static final String XYZ_ORDER_PATH = "org/apache/camel/component/dozer/xyz-order.json";
+
+ @EndpointInject(uri = "mock:result")
+ private MockEndpoint resultEndpoint;
+
+ @Produce(uri = "direct:start")
+ private ProducerTemplate startEndpoint;
+
+ @Autowired
+ private CamelContext camelContext;
+
+ @After
+ public void tearDown() {
+ resultEndpoint.reset();
+ }
+
+ @Test
+ public void testXmlToJson() throws Exception {
+ resultEndpoint.expectedMessageCount(1);
+ startEndpoint.sendBody(getResourceAsString(ABC_ORDER_PATH));
+ // check results
+ resultEndpoint.assertIsSatisfied();
+ String result = resultEndpoint.getExchanges().get(0).getIn().getBody(String.class);
+ Assert.assertEquals(getResourceAsString(XYZ_ORDER_PATH), result);
+ }
+
+ @Test
+ public void testMultipleSends() throws Exception {
+ resultEndpoint.expectedMessageCount(2);
+ startEndpoint.sendBody(getResourceAsString(ABC_ORDER_PATH));
+ startEndpoint.sendBody(getResourceAsString(ABC_ORDER_PATH));
+ // check results
+ resultEndpoint.assertIsSatisfied();
+ String result1 = resultEndpoint.getExchanges().get(0).getIn().getBody(String.class);
+ String result2 = resultEndpoint.getExchanges().get(1).getIn().getBody(String.class);
+ Assert.assertEquals(getResourceAsString(XYZ_ORDER_PATH), result1);
+ Assert.assertEquals(getResourceAsString(XYZ_ORDER_PATH), result2);
+ }
+
+ private String getResourceAsString(String resourcePath) {
+ InputStream is = getClass().getClassLoader().getResourceAsStream(resourcePath);
+ return camelContext.getTypeConverter().convertTo(String.class, is);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/CustomMapper.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/CustomMapper.java b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/CustomMapper.java
new file mode 100644
index 0000000..fd3ed7d
--- /dev/null
+++ b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/CustomMapper.java
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer.example;
+
+/**
+ * Custom mapping class with one operation.
+ */
+public class CustomMapper {
+
+ public Object mapCustomer(String source) {
+ return "mapCustomer:" + source;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/CustomMapperOperations.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/CustomMapperOperations.java b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/CustomMapperOperations.java
new file mode 100644
index 0000000..746ff3f
--- /dev/null
+++ b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/CustomMapperOperations.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer.example;
+
+/**
+ * Custom mapping class with multiple operations.
+ */
+public class CustomMapperOperations {
+
+ public Object custom1(String source) {
+ return "custom1:" + source.toString();
+ }
+
+ public Object custom2(String source) {
+ return "custom2:" + source.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/abc/ABCOrder.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/abc/ABCOrder.java b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/abc/ABCOrder.java
new file mode 100644
index 0000000..90e3a85
--- /dev/null
+++ b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/abc/ABCOrder.java
@@ -0,0 +1,418 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer.example.abc;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for anonymous complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="header">
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="status" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="customer-num" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="order-num" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </element>
+ * <element name="order-items">
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="item" maxOccurs="unbounded" minOccurs="0">
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="price" type="{http://www.w3.org/2001/XMLSchema}float"/>
+ * <element name="quantity" type="{http://www.w3.org/2001/XMLSchema}short"/>
+ * </sequence>
+ * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </element>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </element>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {
+ "header",
+ "orderItems"
+ })
+@XmlRootElement(name = "ABCOrder")
+public class ABCOrder {
+
+ @XmlElement(required = true)
+ protected ABCOrder.Header header;
+ @XmlElement(name = "order-items", required = true)
+ protected ABCOrder.OrderItems orderItems;
+
+ /**
+ * Gets the value of the header property.
+ *
+ * @return
+ * possible object is
+ * {@link ABCOrder.Header }
+ *
+ */
+ public ABCOrder.Header getHeader() {
+ return header;
+ }
+
+ /**
+ * Sets the value of the header property.
+ *
+ * @param value
+ * allowed object is
+ * {@link ABCOrder.Header }
+ *
+ */
+ public void setHeader(ABCOrder.Header value) {
+ this.header = value;
+ }
+
+ /**
+ * Gets the value of the orderItems property.
+ *
+ * @return
+ * possible object is
+ * {@link ABCOrder.OrderItems }
+ *
+ */
+ public ABCOrder.OrderItems getOrderItems() {
+ return orderItems;
+ }
+
+ /**
+ * Sets the value of the orderItems property.
+ *
+ * @param value
+ * allowed object is
+ * {@link ABCOrder.OrderItems }
+ *
+ */
+ public void setOrderItems(ABCOrder.OrderItems value) {
+ this.orderItems = value;
+ }
+
+
+ /**
+ * <p>Java class for anonymous complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="status" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="customer-num" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * <element name="order-num" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+ @XmlAccessorType(XmlAccessType.FIELD)
+ @XmlType(name = "", propOrder = {
+ "status",
+ "customerNum",
+ "orderNum"
+ })
+ public static class Header {
+
+ @XmlElement(required = true)
+ protected String status;
+ @XmlElement(name = "customer-num", required = true)
+ protected String customerNum;
+ @XmlElement(name = "order-num", required = true)
+ protected String orderNum;
+
+ /**
+ * Gets the value of the status property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the value of the status property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setStatus(String value) {
+ this.status = value;
+ }
+
+ /**
+ * Gets the value of the customerNum property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getCustomerNum() {
+ return customerNum;
+ }
+
+ /**
+ * Sets the value of the customerNum property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setCustomerNum(String value) {
+ this.customerNum = value;
+ }
+
+ /**
+ * Gets the value of the orderNum property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getOrderNum() {
+ return orderNum;
+ }
+
+ /**
+ * Sets the value of the orderNum property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setOrderNum(String value) {
+ this.orderNum = value;
+ }
+
+ }
+
+
+ /**
+ * <p>Java class for anonymous complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="item" maxOccurs="unbounded" minOccurs="0">
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="price" type="{http://www.w3.org/2001/XMLSchema}float"/>
+ * <element name="quantity" type="{http://www.w3.org/2001/XMLSchema}short"/>
+ * </sequence>
+ * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </element>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+ @XmlAccessorType(XmlAccessType.FIELD)
+ @XmlType(name = "", propOrder = {
+ "item"
+ })
+ public static class OrderItems {
+
+ protected List<ABCOrder.OrderItems.Item> item;
+
+ /**
+ * Gets the value of the item property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the item property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getItem().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link ABCOrder.OrderItems.Item }
+ *
+ *
+ */
+ public List<ABCOrder.OrderItems.Item> getItem() {
+ if (item == null) {
+ item = new ArrayList<ABCOrder.OrderItems.Item>();
+ }
+ return this.item;
+ }
+
+
+ /**
+ * <p>Java class for anonymous complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="price" type="{http://www.w3.org/2001/XMLSchema}float"/>
+ * <element name="quantity" type="{http://www.w3.org/2001/XMLSchema}short"/>
+ * </sequence>
+ * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+ @XmlAccessorType(XmlAccessType.FIELD)
+ @XmlType(name = "", propOrder = {
+ "price",
+ "quantity"
+ })
+ public static class Item {
+
+ protected float price;
+ protected short quantity;
+ @XmlAttribute(name = "id")
+ protected String id;
+
+ /**
+ * Gets the value of the price property.
+ *
+ */
+ public float getPrice() {
+ return price;
+ }
+
+ /**
+ * Sets the value of the price property.
+ *
+ */
+ public void setPrice(float value) {
+ this.price = value;
+ }
+
+ /**
+ * Gets the value of the quantity property.
+ *
+ */
+ public short getQuantity() {
+ return quantity;
+ }
+
+ /**
+ * Sets the value of the quantity property.
+ *
+ */
+ public void setQuantity(short value) {
+ this.quantity = value;
+ }
+
+ /**
+ * Gets the value of the id property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * Sets the value of the id property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setId(String value) {
+ this.id = value;
+ }
+
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/abc/ObjectFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/abc/ObjectFactory.java b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/abc/ObjectFactory.java
new file mode 100644
index 0000000..2032ee5
--- /dev/null
+++ b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/abc/ObjectFactory.java
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer.example.abc;
+
+import javax.xml.bind.annotation.XmlRegistry;
+
+
+/**
+ * This object contains factory methods for each
+ * Java content interface and Java element interface
+ * generated in the example.abc package.
+ * <p>An ObjectFactory allows you to programatically
+ * construct new instances of the Java representation
+ * for XML content. The Java representation of XML
+ * content can consist of schema derived interfaces
+ * and classes representing the binding of schema
+ * type definitions, element declarations and model
+ * groups. Factory methods for each of these are
+ * provided in this class.
+ *
+ */
+@XmlRegistry
+public class ObjectFactory {
+
+
+ /**
+ * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: example.abc
+ *
+ */
+ public ObjectFactory() {
+ }
+
+ /**
+ * Create an instance of {@link ABCOrder }
+ *
+ */
+ public ABCOrder createABCOrder() {
+ return new ABCOrder();
+ }
+
+ /**
+ * Create an instance of {@link ABCOrder.OrderItems }
+ *
+ */
+ public ABCOrder.OrderItems createABCOrderOrderItems() {
+ return new ABCOrder.OrderItems();
+ }
+
+ /**
+ * Create an instance of {@link ABCOrder.Header }
+ *
+ */
+ public ABCOrder.Header createABCOrderHeader() {
+ return new ABCOrder.Header();
+ }
+
+ /**
+ * Create an instance of {@link ABCOrder.OrderItems.Item }
+ *
+ */
+ public ABCOrder.OrderItems.Item createABCOrderOrderItemsItem() {
+ return new ABCOrder.OrderItems.Item();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/xyz/LineItem.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/xyz/LineItem.java b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/xyz/LineItem.java
new file mode 100644
index 0000000..2998c59
--- /dev/null
+++ b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/xyz/LineItem.java
@@ -0,0 +1,107 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer.example.xyz;
+
+import javax.annotation.Generated;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+
+/**
+ * LineItem
+ * <p>
+ *
+ *
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@Generated("org.jsonschema2pojo")
+@JsonPropertyOrder({
+ "itemId",
+ "amount",
+ "cost"
+})
+public class LineItem {
+
+ @JsonProperty("itemId")
+ private String itemId;
+ @JsonProperty("amount")
+ private int amount;
+ @JsonProperty("cost")
+ private double cost;
+
+ /**
+ *
+ * @return
+ * The itemId
+ */
+ @JsonProperty("itemId")
+ public String getItemId() {
+ return itemId;
+ }
+
+ /**
+ *
+ * @param itemId
+ * The itemId
+ */
+ @JsonProperty("itemId")
+ public void setItemId(String itemId) {
+ this.itemId = itemId;
+ }
+
+ /**
+ *
+ * @return
+ * The amount
+ */
+ @JsonProperty("amount")
+ public int getAmount() {
+ return amount;
+ }
+
+ /**
+ *
+ * @param amount
+ * The amount
+ */
+ @JsonProperty("amount")
+ public void setAmount(int amount) {
+ this.amount = amount;
+ }
+
+ /**
+ *
+ * @return
+ * The cost
+ */
+ @JsonProperty("cost")
+ public double getCost() {
+ return cost;
+ }
+
+ /**
+ *
+ * @param cost
+ * The cost
+ */
+ @JsonProperty("cost")
+ public void setCost(double cost) {
+ this.cost = cost;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/xyz/XYZOrder.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/xyz/XYZOrder.java b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/xyz/XYZOrder.java
new file mode 100644
index 0000000..10351ae
--- /dev/null
+++ b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/example/xyz/XYZOrder.java
@@ -0,0 +1,132 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dozer.example.xyz;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Generated;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+
+/**
+ * XYZOrder
+ * <p>
+ *
+ *
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@Generated("org.jsonschema2pojo")
+@JsonPropertyOrder({
+ "custId",
+ "priority",
+ "orderId",
+ "lineItems"
+})
+public class XYZOrder {
+
+ @JsonProperty("custId")
+ private String custId;
+ @JsonProperty("priority")
+ private String priority;
+ @JsonProperty("orderId")
+ private String orderId;
+ @JsonProperty("lineItems")
+ private List<LineItem> lineItems = new ArrayList<LineItem>();
+
+ /**
+ *
+ * @return
+ * The custId
+ */
+ @JsonProperty("custId")
+ public String getCustId() {
+ return custId;
+ }
+
+ /**
+ *
+ * @param custId
+ * The custId
+ */
+ @JsonProperty("custId")
+ public void setCustId(String custId) {
+ this.custId = custId;
+ }
+
+ /**
+ *
+ * @return
+ * The priority
+ */
+ @JsonProperty("priority")
+ public String getPriority() {
+ return priority;
+ }
+
+ /**
+ *
+ * @param priority
+ * The priority
+ */
+ @JsonProperty("priority")
+ public void setPriority(String priority) {
+ this.priority = priority;
+ }
+
+ /**
+ *
+ * @return
+ * The orderId
+ */
+ @JsonProperty("orderId")
+ public String getOrderId() {
+ return orderId;
+ }
+
+ /**
+ *
+ * @param orderId
+ * The orderId
+ */
+ @JsonProperty("orderId")
+ public void setOrderId(String orderId) {
+ this.orderId = orderId;
+ }
+
+ /**
+ *
+ * @return
+ * The lineItems
+ */
+ @JsonProperty("lineItems")
+ public List<LineItem> getLineItems() {
+ return lineItems;
+ }
+
+ /**
+ *
+ * @param lineItems
+ * The lineItems
+ */
+ @JsonProperty("lineItems")
+ public void setLineItems(List<LineItem> lineItems) {
+ this.lineItems = lineItems;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/CustomMappingTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/CustomMappingTest-context.xml b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/CustomMappingTest-context.xml
new file mode 100644
index 0000000..fde0332
--- /dev/null
+++ b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/CustomMappingTest-context.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <!-- Camel route -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <endpoint uri="dozer:java2java?mappingFile=org/apache/camel/component/dozer/customMapping.xml&targetModel=org.apache.camel.component.dozer.example.xyz.XYZOrder" id="java2java"/>
+ <route>
+ <from uri="direct:start"/>
+ <to ref="java2java"/>
+ <to uri="mock:result"/>
+ </route>
+</camelContext>
+</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/LiteralMappingTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/LiteralMappingTest-context.xml b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/LiteralMappingTest-context.xml
new file mode 100644
index 0000000..f13d5a9
--- /dev/null
+++ b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/LiteralMappingTest-context.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <!-- Camel route -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <endpoint uri="dozer:java2java?mappingFile=org/apache/camel/component/dozer/literalMapping.xml&targetModel=org.apache.camel.component.dozer.example.xyz.XYZOrder" id="java2java"/>
+ <route>
+ <from uri="direct:start"/>
+ <to ref="java2java"/>
+ <to uri="mock:result"/>
+ </route>
+</camelContext>
+</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/XmlToJsonTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/XmlToJsonTest-context.xml b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/XmlToJsonTest-context.xml
new file mode 100644
index 0000000..e9678d0
--- /dev/null
+++ b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/XmlToJsonTest-context.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <!-- Camel route -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <endpoint uri="dozer:xml2json?mappingFile=org/apache/camel/component/dozer/dozerBeanMapping.xml&marshalId=myjson&unmarshalId=myjaxb&targetModel=org.apache.camel.component.dozer.example.xyz.XYZOrder" id="xml2json"/>
+ <dataFormats>
+ <json library="Jackson" id="myjson"/>
+ <jaxb contextPath="org.apache.camel.component.dozer.example.abc" id="myjaxb"/>
+ </dataFormats>
+ <route>
+ <from uri="direct:start"/>
+ <to ref="xml2json"/>
+ <to uri="mock:result"/>
+ </route>
+</camelContext>
+</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/abc-order.xml
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/abc-order.xml b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/abc-order.xml
new file mode 100644
index 0000000..4abcef8
--- /dev/null
+++ b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/abc-order.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<ABCOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://java.sun.com">
+ <header>
+ <status>GOLD</status>
+ <customer-num>ACME-123</customer-num>
+ <order-num>ORDER1</order-num>
+ </header>
+ <order-items>
+ <item id="PICKLE">
+ <price>2.25</price>
+ <quantity>1000</quantity>
+ </item>
+ </order-items>
+</ABCOrder>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/e085e28d/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/customMapping.xml
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/customMapping.xml b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/customMapping.xml
new file mode 100644
index 0000000..5ef7f3a
--- /dev/null
+++ b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/customMapping.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<mappings xmlns="http://dozer.sourceforge.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://dozer.sourceforge.net http://dozer.sourceforge.net/schema/beanmapping.xsd">
+ <mapping>
+ <class-a>org.apache.camel.component.dozer.example.abc.ABCOrder</class-a>
+ <class-b>org.apache.camel.component.dozer.example.xyz.XYZOrder</class-b>
+ <field custom-converter-id="_customMapping"
+ custom-converter-param="org.apache.camel.component.dozer.example.CustomMapper">
+ <a>header.customerNum</a>
+ <b>custId</b>
+ </field>
+ <field custom-converter-id="_customMapping"
+ custom-converter-param="org.apache.camel.component.dozer.example.CustomMapperOperations,custom2">
+ <a>header.status</a>
+ <b>priority</b>
+ </field>
+ <field>
+ <a>header.orderNum</a>
+ <b>orderId</b>
+ </field>
+ <field>
+ <a>orderItems.item</a>
+ <b>lineItems</b>
+ </field>
+ </mapping>
+ <mapping>
+ <class-a>org.apache.camel.component.dozer.example.abc.ABCOrder$OrderItems$Item</class-a>
+ <class-b>org.apache.camel.component.dozer.example.xyz.LineItem</class-b>
+ <field>
+ <a>id</a>
+ <b>itemId</b>
+ </field>
+ <field>
+ <a>price</a>
+ <b>cost</b>
+ </field>
+ <field>
+ <a>quantity</a>
+ <b>amount</b>
+ </field>
+ </mapping>
+</mappings>
[3/4] camel git commit: CAMEL-8332: Removed duplicate in pom
Posted by da...@apache.org.
CAMEL-8332: Removed duplicate in pom
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/63faa18d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/63faa18d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/63faa18d
Branch: refs/heads/master
Commit: 63faa18dda3e27b45dd32e8593a6d746d9bac6e7
Parents: e085e28
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Feb 11 09:28:59 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Feb 11 09:28:59 2015 +0100
----------------------------------------------------------------------
components/camel-dozer/pom.xml | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/63faa18d/components/camel-dozer/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-dozer/pom.xml b/components/camel-dozer/pom.xml
index 75b177a..e0f78bc 100644
--- a/components/camel-dozer/pom.xml
+++ b/components/camel-dozer/pom.xml
@@ -45,11 +45,7 @@
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test-spring</artifactId>
- <scope>test</scope>
- </dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
[4/4] camel git commit: CAMEL-8332: Init using doStart/doStop instead
of synchronized code.
Posted by da...@apache.org.
CAMEL-8332: Init using doStart/doStop instead of synchronized code.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0e50f2c7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0e50f2c7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0e50f2c7
Branch: refs/heads/master
Commit: 0e50f2c70233ee2d4a3a083d5cb63360bd325770
Parents: 63faa18
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Feb 11 09:41:56 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Feb 11 09:41:56 2015 +0100
----------------------------------------------------------------------
.../camel/component/dozer/CustomMapper.java | 2 +-
.../camel/component/dozer/DozerComponent.java | 3 -
.../component/dozer/DozerConfiguration.java | 4 +-
.../camel/component/dozer/DozerEndpoint.java | 62 ++++++++++----------
.../camel/component/dozer/DozerProducer.java | 9 +--
5 files changed, 37 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0e50f2c7/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/CustomMapper.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/CustomMapper.java b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/CustomMapper.java
index 7d46d4b..331de0c 100644
--- a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/CustomMapper.java
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/CustomMapper.java
@@ -59,7 +59,7 @@ public class CustomMapper extends BaseConverter {
Object mapCustom(Object source) {
Object customMapObj;
- Method mapMethod = null;
+ Method mapMethod;
// The converter parameter is stored in a thread local variable, so
// we need to parse the parameter on each invocation
http://git-wip-us.apache.org/repos/asf/camel/blob/0e50f2c7/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerComponent.java
----------------------------------------------------------------------
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 09a44ce..dcae3ac 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
@@ -22,9 +22,6 @@ import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.UriEndpointComponent;
-/**
- * Represents the component that manages {@link DozerEndpoint}.
- */
public class DozerComponent extends UriEndpointComponent {
public DozerComponent() {
http://git-wip-us.apache.org/repos/asf/camel/blob/0e50f2c7/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerConfiguration.java b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerConfiguration.java
index c390c05..94f9e3d 100644
--- a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerConfiguration.java
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerConfiguration.java
@@ -16,20 +16,20 @@
*/
package org.apache.camel.component.dozer;
+import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
import org.apache.camel.spi.UriPath;
import static org.dozer.util.DozerConstants.DEFAULT_MAPPING_FILE;
-
/**
* Configuration used for a Dozer endpoint.
*/
@UriParams
public class DozerConfiguration {
- @UriPath
+ @UriPath @Metadata(required = "true")
private String name;
@UriParam
private String marshalId;
http://git-wip-us.apache.org/repos/asf/camel/blob/0e50f2c7/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 0bcbda0..5753645 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
@@ -26,15 +26,14 @@ import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultEndpoint;
import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ResourceHelper;
import org.dozer.CustomConverter;
import org.dozer.DozerBeanMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * Represents a Dozer endpoint.
- */
@UriEndpoint(scheme = "dozer", label = "transformation")
public class DozerEndpoint extends DefaultEndpoint {
private static final Logger LOG = LoggerFactory.getLogger(DozerEndpoint.class);
@@ -42,18 +41,14 @@ public class DozerEndpoint extends DefaultEndpoint {
// IDs for built-in custom converters used with the Dozer component
private static final String CUSTOM_MAPPING_ID = "_customMapping";
private static final String LITERAL_MAPPING_ID = "_literalMapping";
-
- private DozerConfiguration configuration;
+
private DozerBeanMapper mapper;
private LiteralMapper literalMapper;
private CustomMapper customMapper;
- /**
- * Create a new TransformEndpoint.
- * @param endpointUri The uri of the Camel endpoint.
- * @param component The {@link DozerComponent}.
- * @param configuration endpoint configuration
- */
+ @UriParam
+ private DozerConfiguration configuration;
+
public DozerEndpoint(String endpointUri, Component component, DozerConfiguration configuration) throws Exception {
super(endpointUri, component);
this.configuration = configuration;
@@ -68,8 +63,7 @@ public class DozerEndpoint extends DefaultEndpoint {
@Override
public Consumer createConsumer(Processor processor) throws Exception {
- throw new UnsupportedOperationException(
- "Consumer not supported for Transform endpoints");
+ throw new UnsupportedOperationException("Consumer not supported for Dozer endpoints");
}
@Override
@@ -77,10 +71,7 @@ public class DozerEndpoint extends DefaultEndpoint {
return true;
}
- public synchronized DozerBeanMapper getMapper() throws Exception {
- if (mapper == null) {
- initDozer();
- }
+ public DozerBeanMapper getMapper() throws Exception {
return mapper;
}
@@ -100,30 +91,41 @@ public class DozerEndpoint extends DefaultEndpoint {
return literalMapper;
}
- private void initDozer() throws Exception {
- mapper = new DozerBeanMapper();
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+
+ if (mapper == null) {
+ mapper = createDozerBeanMapper();
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ super.doStop();
+ // noop
+ }
+
+ private DozerBeanMapper createDozerBeanMapper() throws Exception {
+ DozerBeanMapper answer = new DozerBeanMapper();
InputStream mapStream = null;
try {
LOG.info("Loading Dozer mapping file {}.", configuration.getMappingFile());
// create the mapper instance and add the mapping file
- mapStream = ResourceHelper.resolveResourceAsInputStream(
- getCamelContext().getClassResolver(), configuration.getMappingFile());
- if (mapStream == null) {
- throw new Exception("Unable to resolve Dozer config: " + configuration.getMappingFile());
- }
- mapper.addMapping(mapStream);
+ mapStream = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext().getClassResolver(), configuration.getMappingFile());
+ answer.addMapping(mapStream);
// add our built-in converters
Map<String, CustomConverter> converters = new HashMap<String, CustomConverter>();
converters.put(CUSTOM_MAPPING_ID, customMapper);
converters.put(LITERAL_MAPPING_ID, literalMapper);
- converters.putAll(mapper.getCustomConvertersWithId());
- mapper.setCustomConvertersWithId(converters);
+ converters.putAll(answer.getCustomConvertersWithId());
+ answer.setCustomConvertersWithId(converters);
} finally {
- if (mapStream != null) {
- mapStream.close();
- }
+ IOHelper.close(mapStream);
}
+
+ return answer;
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0e50f2c7/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java
index fd7f6c4..1de9cf3 100644
--- a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.component.dozer;
-import org.apache.camel.CamelContextAware;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.impl.DefaultProducer;
@@ -117,9 +116,7 @@ public class DozerProducer extends DefaultProducer {
// Stop/shutdown is handled when the corresponding methods are
// called on this producer.
unmarshaller = new UnmarshalProcessor(dataFormat);
- if (unmarshaller instanceof CamelContextAware) {
- ((CamelContextAware)unmarshaller).setCamelContext(exchange.getContext());
- }
+ unmarshaller.setCamelContext(exchange.getContext());
unmarshaller.start();
}
return unmarshaller;
@@ -142,9 +139,7 @@ public class DozerProducer extends DefaultProducer {
// Stop/shutdown is handled when the corresponding methods are
// called on this producer.
marshaller = new MarshalProcessor(dataFormat);
- if (marshaller instanceof CamelContextAware) {
- ((CamelContextAware)marshaller).setCamelContext(exchange.getContext());
- }
+ marshaller.setCamelContext(exchange.getContext());
marshaller.start();
}
return marshaller;