You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/11/24 09:45:23 UTC

[1/4] camel git commit: CAMEL-10447 javadoc and some minor fixes

Repository: camel
Updated Branches:
  refs/heads/master b65041424 -> 2dcd9b8d1


CAMEL-10447 javadoc and some minor fixes


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

Branch: refs/heads/master
Commit: 2dcd9b8d1212b03a59ea16e63affcab7988c2027
Parents: 7ba090f
Author: Tomohisa Igarashi <tm...@gmail.com>
Authored: Thu Nov 24 00:27:25 2016 +0900
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Nov 24 10:45:13 2016 +0100

----------------------------------------------------------------------
 .../impl/transformer/DataFormatTransformer.java |  5 +--
 .../impl/transformer/ProcessorTransformer.java  | 14 ++++----
 .../apache/camel/model/InputTypeDefinition.java | 14 ++++----
 .../camel/model/OutputTypeDefinition.java       | 14 ++++----
 .../org/apache/camel/model/RouteDefinition.java | 14 ++++----
 .../CustomTransformerDefinition.java            | 17 +++++----
 .../DataFormatTransformerDefinition.java        | 10 ++++--
 .../EndpointTransformerDefinition.java          | 16 ++++++---
 .../transformer/TransformerDefinition.java      | 38 +++++++++-----------
 .../camel/processor/CamelInternalProcessor.java |  7 ++--
 .../java/org/apache/camel/spi/RouteContext.java |  4 +--
 .../java/org/apache/camel/spi/Transformer.java  | 12 +++++--
 .../transformer/TransformerContractTest.java    |  2 --
 13 files changed, 93 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2dcd9b8d/camel-core/src/main/java/org/apache/camel/impl/transformer/DataFormatTransformer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/transformer/DataFormatTransformer.java b/camel-core/src/main/java/org/apache/camel/impl/transformer/DataFormatTransformer.java
index 9993807..b4e0586 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/transformer/DataFormatTransformer.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/transformer/DataFormatTransformer.java
@@ -34,8 +34,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * A <a href="http://camel.apache.org/transformer.html">Transformer</a>
- * leverages DataFormat to perform transformation.
+ * A {@link Transformer} implementation which leverages {@link DataFormat} to perform transformation.
+ * 
+ * {@see Transformer}
  */
 public class DataFormatTransformer extends Transformer {
     private static final Logger LOG = LoggerFactory.getLogger(DataFormatTransformer.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/2dcd9b8d/camel-core/src/main/java/org/apache/camel/impl/transformer/ProcessorTransformer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/transformer/ProcessorTransformer.java b/camel-core/src/main/java/org/apache/camel/impl/transformer/ProcessorTransformer.java
index f7bc2d4..ddacf3d 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/transformer/ProcessorTransformer.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/transformer/ProcessorTransformer.java
@@ -28,12 +28,14 @@ import org.apache.camel.processor.SendProcessor;
 import org.apache.camel.spi.DataType;
 import org.apache.camel.spi.Transformer;
 import org.apache.camel.support.ServiceSupport;
+import org.apache.camel.util.ServiceHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * A <a href="http://camel.apache.org/transformer.html">Transformer</a>
- * leverages Processor to perform transformation.
+ * A {@link Transformer} implementation which leverages {@link Processor} to perform transformation.
+ * 
+ * {@see Transformer}
  */
 public class ProcessorTransformer extends Transformer {
     private static final Logger LOG = LoggerFactory.getLogger(ProcessorTransformer.class);
@@ -108,15 +110,11 @@ public class ProcessorTransformer extends Transformer {
 
     @Override
     protected void doStart() throws Exception {
-        if (this.processor instanceof ServiceSupport) {
-            ((ServiceSupport)this.processor).start();
-        }
+        ServiceHelper.startService(this.processor);
     }
 
     @Override
     protected void doStop() throws Exception {
-        if (this.processor instanceof ServiceSupport) {
-            ((ServiceSupport)this.processor).stop();
-        }
+        ServiceHelper.stopService(this.processor);
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/2dcd9b8d/camel-core/src/main/java/org/apache/camel/model/InputTypeDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/InputTypeDefinition.java b/camel-core/src/main/java/org/apache/camel/model/InputTypeDefinition.java
index 782e041..ade8359 100644
--- a/camel-core/src/main/java/org/apache/camel/model/InputTypeDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/InputTypeDefinition.java
@@ -26,6 +26,13 @@ import org.apache.camel.spi.Metadata;
 
 /**
  * Set data type of the input message.
+ * Type name consists of two parts, 'scheme' and 'name' connected with ':'. For Java type 'name'
+ * is a fully qualified class name. For example {@code java:java.lang.String}, {@code json:ABCOrder}.
+ * It's also possible to specify only scheme part, so that it works like a wildcard. If only 'xml'
+ * is specified, all the XML message matches. It's handy to add only one transformer/validator
+ * for all the transformation from/to XML.
+ * 
+ * {@see OutputTypeDefinition}
  */
 @Metadata(label = "configuration")
 @XmlRootElement(name = "inputType")
@@ -33,8 +40,6 @@ import org.apache.camel.spi.Metadata;
 public class InputTypeDefinition extends OptionalIdentifiedDefinition<InputTypeDefinition> {
     @XmlAttribute(required = true)
     private String urn;
-    @XmlTransient
-    private Class<?> clazz;
 
     public InputTypeDefinition() {
     }
@@ -44,9 +49,6 @@ public class InputTypeDefinition extends OptionalIdentifiedDefinition<InputTypeD
      * @return input type URN
      */
     public String getUrn() {
-        if (clazz != null) {
-            return "java:" + clazz.getName();
-        }
         return urn;
     }
 
@@ -63,7 +65,7 @@ public class InputTypeDefinition extends OptionalIdentifiedDefinition<InputTypeD
      * @param clazz Java Class
      */
     public void setJavaClass(Class<?> clazz) {
-        this.clazz = clazz;
+        this.urn = "java:" + clazz.getName();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/2dcd9b8d/camel-core/src/main/java/org/apache/camel/model/OutputTypeDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/OutputTypeDefinition.java b/camel-core/src/main/java/org/apache/camel/model/OutputTypeDefinition.java
index 755874a..8988ae3 100644
--- a/camel-core/src/main/java/org/apache/camel/model/OutputTypeDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/OutputTypeDefinition.java
@@ -26,6 +26,13 @@ import org.apache.camel.spi.Metadata;
 
 /**
  * Sets data type of the output message.
+ * Type name consists of two parts, 'scheme' and 'name' connected with ':'. For Java type 'name'
+ * is a fully qualified class name. For example {@code java:java.lang.String}, {@code json:ABCOrder}.
+ * It's also possible to specify only scheme part, so that it works like a wildcard. If only 'xml'
+ * is specified, all the XML message matches. It's handy to add only one transformer/validator
+ * for all the XML-Java transformation.
+ * 
+ * {@see InputTypeDefinition}
  */
 @Metadata(label = "configuration")
 @XmlRootElement(name = "outputType")
@@ -33,8 +40,6 @@ import org.apache.camel.spi.Metadata;
 public class OutputTypeDefinition extends OptionalIdentifiedDefinition<OutputTypeDefinition> {
     @XmlAttribute(required = true)
     private String urn;
-    @XmlTransient
-    private Class<?> clazz;
 
     public OutputTypeDefinition() {
     }
@@ -44,9 +49,6 @@ public class OutputTypeDefinition extends OptionalIdentifiedDefinition<OutputTyp
      * @return output type URN
      */
     public String getUrn() {
-        if (clazz != null) {
-            return "java:" + clazz.getName();
-        }
         return urn;
     }
 
@@ -64,7 +66,7 @@ public class OutputTypeDefinition extends OptionalIdentifiedDefinition<OutputTyp
      * @param clazz Java Class
      */
     public void setJavaClass(Class<?> clazz) {
-        this.clazz = clazz;
+        this.urn = "java:" + clazz.getName();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/2dcd9b8d/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
index e140dc0..76b4ec3 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -634,12 +634,12 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
 
     /**
      * Declare an input type.
-     * @param name input type URN
+     * @param urn input type URN
      * @return the builder
      */
-    public RouteDefinition inputType(String name) {
+    public RouteDefinition inputType(String urn) {
         inputType = new InputTypeDefinition();
-        inputType.setUrn(name);
+        inputType.setUrn(urn);
         return this;
     }
 
@@ -656,17 +656,17 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
 
     /**
      * Declare an output type.
-     * @param name output type URN
+     * @param urn output type URN
      * @return the builder
      */
-    public RouteDefinition outputType(String name) {
+    public RouteDefinition outputType(String urn) {
         outputType = new OutputTypeDefinition();
-        outputType.setUrn(name);
+        outputType.setUrn(urn);
         return this;
     }
 
     /**
-     * Declare an output type.
+     * Declare an output type with Java class.
      * @param clazz Class object of the output type
      * @return the builder
      */

http://git-wip-us.apache.org/repos/asf/camel/blob/2dcd9b8d/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java b/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java
index 3af804b..029c6f4 100644
--- a/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java
@@ -40,7 +40,11 @@ import org.apache.camel.spi.Transformer;
 import org.apache.camel.util.ObjectHelper;
 
 /**
- * Represents a BeanTransformer.
+ * Represents a CustomTransformer. One of the bean reference (ref) or fully qualified class name (type)
+ * of the custom {@link Transformer} needs to be specified.
+ * 
+ * {@see TransformerDefinition}
+ * {@see Transformer}
  */
 @Metadata(label = "transformation")
 @XmlType(name = "customTransformer")
@@ -52,13 +56,13 @@ public class CustomTransformerDefinition extends TransformerDefinition {
     private String type;
 
     @Override
-    protected Transformer doCreateTransformer() throws Exception {
+    protected Transformer doCreateTransformer(CamelContext context) throws Exception {
         if (ref == null && type == null) {
             throw new IllegalArgumentException("'ref' or 'type' must be specified for customTransformer");
         }
         Transformer transformer;
         if (ref != null) {
-            transformer = getCamelContext().getRegistry().lookupByNameAndType(ref, Transformer.class);
+            transformer = context.getRegistry().lookupByNameAndType(ref, Transformer.class);
             if (transformer == null) {
                 throw new IllegalArgumentException("Cannot find transformer with ref:" + ref);
             }
@@ -66,13 +70,14 @@ public class CustomTransformerDefinition extends TransformerDefinition {
                 throw new IllegalArgumentException(String.format("Transformer '%s' is already in use. Please check if duplicate transformer exists.", ref));
             }
         } else {
-            Class<Transformer> transformerClass = getCamelContext().getClassResolver().resolveMandatoryClass(type, Transformer.class);
+            Class<Transformer> transformerClass = context.getClassResolver().resolveMandatoryClass(type, Transformer.class);
             if (transformerClass == null) {
                 throw new IllegalArgumentException("Cannot find transformer class: " + type);
             }
-            transformer = transformerClass.newInstance();
+            transformer = context.getInjector().newInstance(transformerClass);
+
         }
-        transformer.setCamelContext(getCamelContext());
+        transformer.setCamelContext(context);
         return transformer.setModel(getScheme())
                           .setFrom(getFrom())
                           .setTo(getTo());

http://git-wip-us.apache.org/repos/asf/camel/blob/2dcd9b8d/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java b/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java
index 6429b85..191b985 100644
--- a/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java
@@ -74,7 +74,11 @@ import org.apache.camel.spi.RouteContext;
 import org.apache.camel.spi.Transformer;
 
 /**
- * Represents a DataFormatTransformer.
+ * Represents a {@link DataFormatTransformer} which leverages {@link DataFormat} to perform
+ * transformation. One of the DataFormat 'ref' or DataFormat 'type' needs to be specified.
+ * 
+ * {@see TransformerDefinition}
+ * {@see DataFormatTransformer}
  */
 @Metadata(label = "transformation")
 @XmlType(name = "dataFormatTransformer")
@@ -125,8 +129,8 @@ public class DataFormatTransformerDefinition extends TransformerDefinition {
     private String ref;
 
     @Override
-    protected Transformer doCreateTransformer() {
-        return new DataFormatTransformer(getCamelContext())
+    protected Transformer doCreateTransformer(CamelContext context) {
+        return new DataFormatTransformer(context)
                 .setDataFormatType(dataFormatType)
                 .setDataFormatRef(ref)
                 .setModel(getScheme())

http://git-wip-us.apache.org/repos/asf/camel/blob/2dcd9b8d/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java b/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java
index 7b16fc4..eb18e0b 100644
--- a/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java
@@ -36,7 +36,13 @@ import org.apache.camel.spi.RouteContext;
 import org.apache.camel.spi.Transformer;
 
 /**
- * Represents a EndpointTransformer.
+ * Represents an endpoint {@link Transformer} which leverages camel {@link Endpoint} to
+ * perform transformation. A {@link ProcessorTransformer} will be created internally
+ * with a {@link SendProcessor} which forwards the message to the specified Endpoint.
+ * One of the Endpoint 'ref' or 'uri' needs to be specified.
+ * 
+ * {@see TransformerDefinition}
+ * {@see ProcessorTransformer}
  */
 @Metadata(label = "transformation")
 @XmlType(name = "endpointTransformer")
@@ -49,11 +55,11 @@ public class EndpointTransformerDefinition extends TransformerDefinition {
     private String uri;
 
     @Override
-    protected Transformer doCreateTransformer() throws Exception {
-        Endpoint endpoint = uri != null ? getCamelContext().getEndpoint(uri)
-            : getCamelContext().getRegistry().lookupByNameAndType(ref, Endpoint.class);
+    protected Transformer doCreateTransformer(CamelContext context) throws Exception {
+        Endpoint endpoint = uri != null ? context.getEndpoint(uri)
+            : context.getRegistry().lookupByNameAndType(ref, Endpoint.class);
         SendProcessor processor = new SendProcessor(endpoint, ExchangePattern.InOut);
-        return new ProcessorTransformer(getCamelContext())
+        return new ProcessorTransformer(context)
             .setProcessor(processor)
             .setModel(getScheme())
             .setFrom(getFrom())

http://git-wip-us.apache.org/repos/asf/camel/blob/2dcd9b8d/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java b/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java
index 7695a63..da24804 100644
--- a/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java
@@ -39,7 +39,20 @@ import org.apache.camel.util.ObjectHelper;
 import static org.apache.camel.util.EndpointHelper.isReferenceParameter;
 
 /**
- * Represents a Transformer.
+ * <p>Represents a {@link Transformer} which declaratively transforms message content
+ * according to the input type declared by {@link InputTypeDefinition} and/or output type
+ * declared by {@link OutputTypeDefinition}.</p>
+ * <p>If you specify from='java:com.example.ABC' and to='xml:XYZ', the transformer
+ * will be picked up when current message type is 'java:com.example.ABC' and expected
+ * message type is 'xml:XYZ'.
+ * If you specify from='java' to='xml', then it will be picked up for all of java
+ * to xml transformation.
+ * Also it's possible to specify scheme='xml' so that the transformer will be picked up
+ * for all of java to xml and xml to java transformation.</p>
+ * 
+ * {@see Transformer}
+ * {@see InputTypeDefinition}
+ * {@see OutputTypeDefinition}
  */
 @Metadata(label = "transformation")
 @XmlType(name = "transformer")
@@ -51,15 +64,12 @@ public abstract class TransformerDefinition {
     private String from;
     @XmlAttribute
     private String to;
-    @XmlTransient
-    private CamelContext camelContext;
 
     public Transformer createTransformer(CamelContext context) throws Exception {
-        this.camelContext = context;
-        return doCreateTransformer();
+        return doCreateTransformer(context);
     };
 
-    protected abstract Transformer doCreateTransformer() throws Exception;
+    protected abstract Transformer doCreateTransformer(CamelContext context) throws Exception;
 
     public String getScheme() {
         return scheme;
@@ -113,21 +123,5 @@ public abstract class TransformerDefinition {
         this.to = "java:" + clazz.getName();
     }
 
-    /**
-     * Get the CamelContext.
-     * @return
-     */
-    public CamelContext getCamelContext() {
-        return camelContext;
-    }
-
-    /**
-     * Set the CamelContext.
-     * @param camelContext CamelContext
-     */
-    public void setCamelContext(CamelContext camelContext) {
-        this.camelContext = camelContext;
-    }
-
 }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/2dcd9b8d/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
index ab9892a..723bab3 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
@@ -68,6 +68,7 @@ import org.slf4j.LoggerFactory;
  *     <li>Debugging</li>
  *     <li>Message History</li>
  *     <li>Stream Caching</li>
+ *     <li>{@link Transformer}</li>
  * </ul>
  * ... and more.
  * <p/>
@@ -875,7 +876,7 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor {
             DataType to = contract.getInputType();
             if (to != null && !to.equals(from)) {
                 LOG.debug("Looking for transformer for INPUT: from='{}', to='{}'", from, to);
-                convertBody(exchange.getIn(), from, to);
+                doTransform(exchange.getIn(), from, to);
                 exchange.setProperty(Exchange.INPUT_TYPE, to);
             }
             return null;
@@ -888,12 +889,12 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor {
             DataType to = contract.getOutputType();
             if (to != null && !to.equals(from)) {
                 LOG.debug("Looking for transformer for OUTPUT: from='{}', to='{}'", from, to);
-                convertBody(target, from, to);
+                doTransform(target, from, to);
                 exchange.setProperty(exchange.hasOut() ? Exchange.OUTPUT_TYPE : Exchange.INPUT_TYPE, to);
             }
         }
         
-        private static void convertBody(Message message, DataType from, DataType to) throws Exception {
+        private static void doTransform(Message message, DataType from, DataType to) throws Exception {
             CamelContext context = message.getExchange().getContext();
             // transform into 'from' type before performing declared transformation
             if (from != null && from.isJavaType() && from.getName() != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/2dcd9b8d/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java b/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
index 194f544..ce57112 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
@@ -193,8 +193,8 @@ public interface RouteContext extends RuntimeConfiguration, EndpointAware {
     int getAndIncrement(ProcessorDefinition<?> node);
 
     /**
-     * 
-     * @param contract
+     * Sets a {@link Contract} which declares input/output message type on the route.
+     * @param contract {@link Contract} for this route
      */
     void setContract(Contract contract);
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/2dcd9b8d/camel-core/src/main/java/org/apache/camel/spi/Transformer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/Transformer.java b/camel-core/src/main/java/org/apache/camel/spi/Transformer.java
index adee678..d179556 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/Transformer.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/Transformer.java
@@ -29,8 +29,16 @@ import org.slf4j.LoggerFactory;
 
 /**
  * <a href="http://camel.apache.org/transformer.html">Transformer</a>
- * represents Any to Any data transformation which leverages data format and endpoint
- * under the cover.
+ * performs message transformation according to the declared data type.
+ * There are two Exchange property indicates current message type, {@link Exchange.INPUT_TYPE}
+ * holds input message type and {@link Exchange.OUTPUT_TYPE} holds output message type. If the
+ * input type and/or output type declared by {@link InputTypeDefinition}
+ * and/or {@link OutputTypeDefinition} in the route definition is different from those property
+ * at runtime, camel internal processor look for a Transformer which transforms from
+ * the current message type to the expected message type.
+ *  
+ *  {@see InputTypeDefinition}
+ *  {@see OutputTypeDefinition}
  */
 public abstract class Transformer extends ServiceSupport implements CamelContextAware {
 

http://git-wip-us.apache.org/repos/asf/camel/blob/2dcd9b8d/camel-core/src/test/java/org/apache/camel/impl/transformer/TransformerContractTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/transformer/TransformerContractTest.java b/camel-core/src/test/java/org/apache/camel/impl/transformer/TransformerContractTest.java
index 263afd1..0a3d7e4 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/transformer/TransformerContractTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/transformer/TransformerContractTest.java
@@ -37,8 +37,6 @@ import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.RouteContext;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
-
 public class TransformerContractTest extends ContextTestSupport {
 
     @Override


[2/4] camel git commit: CAMEL-10447 Add contract based type awareness and transformer which leverages the type metadata

Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-demo/pom.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/pom.xml b/examples/camel-example-transformer-demo/pom.xml
new file mode 100644
index 0000000..b6a6392
--- /dev/null
+++ b/examples/camel-example-transformer-demo/pom.xml
@@ -0,0 +1,141 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>examples</artifactId>
+    <version>2.19.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-example-transformer-demo</artifactId>
+  <packaging>bundle</packaging>
+  <name>Camel :: Example :: Transformer :: Demo</name>
+  <description>An example demonstrating declarative transformation along data type declaration using Spring DSL
+  </description>
+  <properties>
+    <camel.osgi.export.pkg>org.apache.camel.example.transformer.*</camel.osgi.export.pkg>
+  </properties>
+
+  <dependencies>
+    <!-- START SNIPPET: e1 -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-spring</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-bindy</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-jackson</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-jaxb</artifactId>
+    </dependency>
+    
+    <!-- logging -->
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-slf4j-impl</artifactId>
+    </dependency>
+
+    <!-- for testing -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test-spring</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+        <groupId>xmlunit</groupId>
+        <artifactId>xmlunit</artifactId>
+        <scope>test</scope>
+        <version>1.6</version>
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-artifacts</id>
+            <phase>package</phase>
+            <goals>
+              <goal>attach-artifact</goal>
+            </goals>
+            <configuration>
+              <artifacts>
+                <artifact>
+                  <file>target/classes/features.xml</file>
+                  <type>xml</type>
+                  <classifier>features</classifier>
+                </artifact>
+              </artifacts>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
+            <Export-Package>${camel.osgi.export.pkg}</Export-Package>
+            <Import-Package>*</Import-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+
+
+      <!-- Allows the example to be run via 'mvn compile exec:java' -->
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>exec-maven-plugin</artifactId>
+        <configuration>
+          <mainClass>org.apache.camel.example.transformer.demo.client.CamelClient</mainClass>
+          <includePluginDependencies>false</includePluginDependencies>
+          <commandlineArgs>${target.cmd.args}</commandlineArgs>
+        </configuration>
+      </plugin>
+    </plugins>
+
+  </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/Order.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/Order.java b/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/Order.java
new file mode 100644
index 0000000..1ce5a3a
--- /dev/null
+++ b/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/Order.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.example.transformer.demo;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.util.IOHelper;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * The Order.
+ */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+@CsvRecord(separator = ",")
+public class Order {
+    @XmlAttribute
+    @DataField(pos = 1)
+    private String orderId;
+
+    @XmlAttribute
+    @DataField(pos = 2)
+    private String itemId;
+
+    @XmlAttribute
+    @DataField(pos = 3)
+    private int quantity;
+
+    public String getOrderId() {
+        return orderId;
+    }
+
+    public Order setOrderId(String orderId) {
+        this.orderId = orderId;
+        return this;
+    }
+
+    public String getItemId() {
+        return itemId;
+    }
+
+    public Order setItemId(String itemId) {
+        this.itemId = itemId;
+        return this;
+    }
+
+    public int getQuantity() {
+        return quantity;
+    }
+
+    public Order setQuantity(int quantity) {
+        this.quantity = quantity;
+        return this;
+    }
+
+    @Override
+    public String toString() {
+        return String.format("Order[orderId='%s', itemId='%s', quantity='%s']", orderId, itemId, quantity);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/OrderProcessor.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/OrderProcessor.java b/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/OrderProcessor.java
new file mode 100644
index 0000000..5cf4794
--- /dev/null
+++ b/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/OrderProcessor.java
@@ -0,0 +1,41 @@
+/**
+ * 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.example.transformer.demo;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.util.IOHelper;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * A processor which receives a order request and return a response.
+ * <p/>
+ */
+public class OrderProcessor implements Processor {
+
+    public void process(Exchange exchange) {
+        Order order = exchange.getIn().getBody(Order.class);
+        OrderResponse answer = new OrderResponse()
+            .setAccepted(true)
+            .setOrderId(order.getOrderId())
+            .setDescription(String.format("Order accepted:[item='%s' quantity='%s']", order.getItemId(), order.getQuantity()));
+        exchange.getOut().setBody(answer);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/OrderResponse.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/OrderResponse.java b/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/OrderResponse.java
new file mode 100644
index 0000000..3ca2ae5
--- /dev/null
+++ b/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/OrderResponse.java
@@ -0,0 +1,76 @@
+/**
+ * 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.example.transformer.demo;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.util.IOHelper;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * The OrderResponse.
+ */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class OrderResponse {
+    @XmlAttribute
+    private String orderId;
+
+    @XmlAttribute
+    private boolean accepted;
+
+    @XmlAttribute
+    private String description;
+
+    public String getOrderId() {
+        return orderId;
+    }
+
+    public OrderResponse setOrderId(String orderId) {
+        this.orderId = orderId;
+        return this;
+    }
+
+    public boolean isAccepted() {
+        return accepted;
+    }
+
+    public OrderResponse setAccepted(boolean accepted) {
+        this.accepted = accepted;
+        return this;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public OrderResponse setDescription(String description) {
+        this.description = description;
+        return this;
+    }
+
+    @Override
+    public String toString() {
+        return String.format("OrderResponse[orderId='%s', accepted='%s', description='%s']", orderId, accepted, description);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/client/CamelClient.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/client/CamelClient.java b/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/client/CamelClient.java
new file mode 100644
index 0000000..03ac095
--- /dev/null
+++ b/examples/camel-example-transformer-demo/src/main/java/org/apache/camel/example/transformer/demo/client/CamelClient.java
@@ -0,0 +1,106 @@
+/**
+ * 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.example.transformer.demo.client;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.example.transformer.demo.Order;
+import org.apache.camel.example.transformer.demo.OrderResponse;
+import org.apache.camel.spring.Main;
+import org.apache.camel.spring.SpringCamelContext;
+import org.apache.camel.util.IOHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * Client that sends order data in various format and verify XML output.
+ * <p/>
+ */
+public final class CamelClient {
+    private static final Logger LOG = LoggerFactory.getLogger(CamelClient.class);
+    private static final String CSV_PATH = "target/output/orders.csv";
+    private CamelClient() {
+        // Helper class
+    }
+
+    public static void main(final String[] args) throws Exception {
+        File csvLogFile = new File(CSV_PATH);
+        if (csvLogFile.exists()) {
+            LOG.info("---> Removing log file '{}'...", csvLogFile.getAbsolutePath());
+            csvLogFile.delete();
+        }
+        
+        // START SNIPPET: e1
+        LOG.info("---> Starting 'order' camel route...");
+        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/camel-context.xml");
+        context.start();
+        CamelContext camelContext = context.getBean("order", CamelContext.class);
+        ProducerTemplate producer = camelContext.createProducerTemplate();
+        // END SNIPPET: e1
+        Thread.sleep(1000);
+        
+        Order order = new Order()
+            .setOrderId("Order-Java-0001")
+            .setItemId("MILK")
+            .setQuantity(3);
+        LOG.info("---> Sending '{}' to 'direct:java'", order);
+        OrderResponse response = producer.requestBody("direct:java", order, OrderResponse.class);
+        Thread.sleep(1000);
+        LOG.info("---> Received '{}'", response);
+        LOG.info("---> CSV log now contains:{}", getCsvLog());
+        Thread.sleep(1000);
+        
+        String orderXml = "<order orderId=\"Order-XML-0001\" itemId=\"MIKAN\" quantity=\"365\"/>";
+        LOG.info("---> Sending '{}' to 'direct:xml'", orderXml);
+        String responseXml = producer.requestBody("direct:xml", orderXml, String.class);
+        Thread.sleep(1000);
+        LOG.info("---> Received '{}'", responseXml);
+        LOG.info("---> CSV log now contains:{}", getCsvLog());
+        Thread.sleep(1000);
+        
+        String orderJson = "{\"orderId\":\"Order-JSON-0001\", \"itemId\":\"MIZUYO-KAN\", \"quantity\":\"16350\"}";
+        LOG.info("---> Sending '{}' to 'direct:json'", orderJson);
+        String responseJson = producer.requestBody("direct:json", orderJson, String.class);
+        Thread.sleep(1000);
+        LOG.info("---> Received '{}'", responseJson);
+        LOG.info("---> CSV log now contains:{}", getCsvLog());
+        Thread.sleep(1000);
+        
+        context.stop();
+    }
+
+    public static String getCsvLog() throws Exception {
+        BufferedReader reader = new BufferedReader(new FileReader(new File(CSV_PATH)));
+        try {
+            StringBuilder buf = new StringBuilder();
+            String line = null;
+            while ((line = reader.readLine()) != null) {
+                buf.append(System.lineSeparator()).append(line);
+            }
+            return buf.toString();
+        } finally {
+            reader.close();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-demo/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/src/main/resources/META-INF/LICENSE.txt b/examples/camel-example-transformer-demo/src/main/resources/META-INF/LICENSE.txt
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/examples/camel-example-transformer-demo/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-demo/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/src/main/resources/META-INF/NOTICE.txt b/examples/camel-example-transformer-demo/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/examples/camel-example-transformer-demo/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Apache Camel distribution.                    ==
+   =========================================================================
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+
+   Please read the different LICENSE files present in the licenses directory of
+   this distribution.

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-demo/src/main/resources/META-INF/spring/camel-context.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/src/main/resources/META-INF/spring/camel-context.xml b/examples/camel-example-transformer-demo/src/main/resources/META-INF/spring/camel-context.xml
new file mode 100644
index 0000000..f8fa92f
--- /dev/null
+++ b/examples/camel-example-transformer-demo/src/main/resources/META-INF/spring/camel-context.xml
@@ -0,0 +1,100 @@
+<?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.
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xmlns:camel="http://camel.apache.org/schema/spring"
+       xsi:schemaLocation="
+         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+    <!-- START SNIPPET: e1 -->
+    <bean id="orderProcessor" class="org.apache.camel.example.transformer.demo.OrderProcessor"/>
+    <!-- END SNIPPET: e1 -->
+
+    <camel:camelContext id="order">
+
+        <!-- START SNIPPET: e2 -->
+        <camel:dataFormats>
+            <camel:json id="jsondf" library="Jackson" unmarshalTypeName="org.apache.camel.example.transformer.demo.Order"/>
+        </camel:dataFormats>
+        <!-- END SNIPPET: e2 -->
+
+        <!-- START SNIPPET: e3 -->
+        <camel:transformers>
+            <!-- specifying from&to data type for the Java-CSV transformation -->
+            <camel:dataFormatTransformer from="java:org.apache.camel.example.transformer.demo.Order" to="csv:CSVOrder">
+                <camel:bindy id="csvdf" type="Csv" classType="org.apache.camel.example.transformer.demo.Order"/>
+            </camel:dataFormatTransformer>
+            <!-- instead of exact from&to type, scheme name can be specified to apply for all the Java-XML transformation -->
+            <camel:dataFormatTransformer scheme="xml">
+                <camel:jaxb id="xmldf" contextPath="org.apache.camel.example.transformer.demo"/>
+            </camel:dataFormatTransformer>
+            <!--  for all the Java-JSON transformation, referring to already defined DataFormat -->
+            <camel:dataFormatTransformer ref="jsondf" scheme="json"/>
+        </camel:transformers>
+        <!-- END SNIPPET: e3 -->
+
+        <!-- START SNIPPET: e4 -->
+        <camel:route id="xml">
+            <camel:from uri="direct:xml"/>
+            <!--  This route expects XML as an input/output type -->
+            <camel:inputType urn="xml:XMLOrder"/>
+            <camel:outputType urn="xml:XMLOrderResponse"/>
+            <camel:to uri="direct:java"/>
+        </camel:route>
+        <!-- END SNIPPET: e4 -->
+
+        <!-- START SNIPPET: e5 -->
+        <camel:route id="json">
+            <camel:from uri="direct:json"/>
+            <!--  This route expects JSON as an input/output type -->
+            <!--  Only scheme 'json' is specified for the type, which means it handles arbitrary JSON content -->
+            <camel:inputType urn="json"/>
+            <camel:outputType urn="json"/>
+            <camel:to uri="direct:java"/>
+        </camel:route>
+        <!-- END SNIPPET: e5 -->
+
+        <!-- START SNIPPET: e6 -->
+        <camel:route id="java">
+            <camel:from uri="direct:java"/>
+            <!-- This route expects Java object as an input/output type. -->
+            <!--  If the request comes from xml route, the XML-Java transformer is applied. -->
+            <!--  If it comes from json route, the JSON-Java transformer is applied. -->
+            <!--  If it's sent via ProducerTemplate directly without specifying input/output type, no transformer is applied. -->
+            <camel:inputType urn="java:org.apache.camel.example.transformer.demo.Order"/>
+            <camel:outputType urn="java:org.apache.camel.example.transformer.demo.OrderResponse"/>
+            <camel:wireTap uri="direct:csv"/>
+            <camel:process ref="orderProcessor"/>
+        </camel:route>
+        <!-- END SNIPPET: e6 -->
+
+        <!-- START SNIPPET: e7 -->
+        <camel:route id="csv">
+            <camel:from uri="direct:csv"/>
+            <!-- This route expects CSV as an input type, therefore Java-CSV transformation is triggered -->
+            <camel:inputType urn="csv:CSVOrder"/>
+            <camel:to uri="file:target/output?fileExist=Append&amp;fileName=orders.csv"/>
+        </camel:route>
+        <!-- END SNIPPET: e7 -->
+    </camel:camelContext>
+
+</beans>

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-demo/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/src/main/resources/features.xml b/examples/camel-example-transformer-demo/src/main/resources/features.xml
new file mode 100644
index 0000000..c3378fa
--- /dev/null
+++ b/examples/camel-example-transformer-demo/src/main/resources/features.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.
+-->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0" name="camel-example-transformer-demo">
+    <repository>mvn:org.apache.camel.karaf/apache-camel/${project.version}/xml/features</repository>
+    
+    <feature name='camel-example-transformer-demo' version='${project.version}'>
+        <feature version="${project.version}">camel</feature>
+        <feature version="${project.version}">camel-bindy</feature>
+        <feature version="${project.version}">camel-jackson</feature>
+        <feature version="${project.version}">camel-jaxb</feature>
+        <feature version="${project.version}">camel-spring</feature>
+        <bundle>mvn:org.apache.camel/camel-example-transformer-demo/${project.version}</bundle>
+    </feature>
+
+</features>

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-demo/src/main/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/src/main/resources/log4j2.properties b/examples/camel-example-transformer-demo/src/main/resources/log4j2.properties
new file mode 100644
index 0000000..a1e0d92
--- /dev/null
+++ b/examples/camel-example-transformer-demo/src/main/resources/log4j2.properties
@@ -0,0 +1,28 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+appender.stdout.type = Console
+appender.stdout.name = stdout
+appender.stdout.layout.type = PatternLayout
+appender.stdout.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+rootLogger.level = INFO
+rootLogger.appenderRef.stdout.ref = stdout
+
+#logger.transformer.name = org.apache.camel.impl.transformer
+#logger.transformer.level = DEBUG
+#logger.processor.name = org.apache.camel.processor
+#logger.processor.level = DEBUG

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-demo/src/main/resources/org/apache/camel/example/transformer/demo/jaxb.index
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/src/main/resources/org/apache/camel/example/transformer/demo/jaxb.index b/examples/camel-example-transformer-demo/src/main/resources/org/apache/camel/example/transformer/demo/jaxb.index
new file mode 100644
index 0000000..e75bd7a
--- /dev/null
+++ b/examples/camel-example-transformer-demo/src/main/resources/org/apache/camel/example/transformer/demo/jaxb.index
@@ -0,0 +1,2 @@
+Order
+OrderResponse

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-demo/src/test/java/org/apache/camel/example/transformer/OrderRouteSpringTest.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/src/test/java/org/apache/camel/example/transformer/OrderRouteSpringTest.java b/examples/camel-example-transformer-demo/src/test/java/org/apache/camel/example/transformer/OrderRouteSpringTest.java
new file mode 100644
index 0000000..93768d5
--- /dev/null
+++ b/examples/camel-example-transformer-demo/src/test/java/org/apache/camel/example/transformer/OrderRouteSpringTest.java
@@ -0,0 +1,140 @@
+/**
+ * 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.example.transformer;
+
+import java.net.URL;
+import java.util.List;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.example.transformer.demo.Order;
+import org.apache.camel.example.transformer.demo.OrderResponse;
+import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader;
+import org.apache.camel.test.spring.CamelSpringRunner;
+import org.apache.camel.test.spring.MockEndpointsAndSkip;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.test.context.ContextConfiguration;
+
+import static org.junit.Assert.*;
+
+@RunWith(CamelSpringRunner.class)
+@ContextConfiguration(value = "/META-INF/spring/camel-context.xml", loader = CamelSpringDelegatingTestContextLoader.class)
+@MockEndpointsAndSkip("direct:csv")
+public class OrderRouteSpringTest {
+    @Produce(uri = "direct:java")
+    protected ProducerTemplate javaProducer;
+
+    @Produce(uri = "direct:xml")
+    protected ProducerTemplate xmlProducer;
+
+    @Produce(uri = "direct:json")
+    protected ProducerTemplate jsonProducer;
+
+    @EndpointInject(uri = "mock:direct:csv")
+    private MockEndpoint mockCsv;
+
+    @Before
+    public void before() {
+        mockCsv.reset();
+    }
+
+    @Test
+    public void testJava() throws Exception {
+        mockCsv.whenAnyExchangeReceived(new Processor() {
+            public void process(Exchange exchange) {
+                Object mockBody = exchange.getIn().getBody();
+                assertEquals(Order.class, mockBody.getClass());
+                Order mockOrder = (Order)mockBody;
+                assertEquals("Order-Java-0001", mockOrder.getOrderId());
+                assertEquals("MILK", mockOrder.getItemId());
+                assertEquals(3, mockOrder.getQuantity());
+            }
+        });
+        mockCsv.setExpectedMessageCount(1);
+
+        Order order = new Order()
+            .setOrderId("Order-Java-0001")
+            .setItemId("MILK")
+            .setQuantity(3);
+        Object answer = javaProducer.requestBody(order);
+        assertEquals(OrderResponse.class, answer.getClass());
+        OrderResponse or = (OrderResponse)answer;
+        assertEquals("Order-Java-0001", or.getOrderId());
+        assertEquals(true, or.isAccepted());
+        assertEquals("Order accepted:[item='MILK' quantity='3']", or.getDescription());
+        mockCsv.assertIsSatisfied();
+    }
+
+    @Test
+    public void testXML() throws Exception {
+        mockCsv.whenAnyExchangeReceived(new Processor() {
+            public void process(Exchange exchange) {
+                Object mockBody = exchange.getIn().getBody();
+                assertEquals(Order.class, mockBody.getClass());
+                Order mockOrder = (Order)mockBody;
+                assertEquals("Order-XML-0001", mockOrder.getOrderId());
+                assertEquals("MIKAN", mockOrder.getItemId());
+                assertEquals(365, mockOrder.getQuantity());
+            }
+        });
+        mockCsv.setExpectedMessageCount(1);
+
+        String order = "<order orderId=\"Order-XML-0001\" itemId=\"MIKAN\" quantity=\"365\"/>";
+        String expectedAnswer = "<orderResponse orderId=\"Order-XML-0001\" accepted=\"true\" description=\"Order accepted:[item='MIKAN' quantity='365']\"/>";
+        String answer = xmlProducer.requestBody("direct:xml", order, String.class);
+        XMLUnit.compareXML(expectedAnswer, answer);
+        mockCsv.assertIsSatisfied();
+    }
+
+    @Test
+    public void testJSON() throws Exception {
+        mockCsv.whenAnyExchangeReceived(new Processor() {
+            public void process(Exchange exchange) {
+                Object mockBody = exchange.getIn().getBody();
+                assertEquals(Order.class, mockBody.getClass());
+                Order mockOrder = (Order)mockBody;
+                assertEquals("Order-JSON-0001", mockOrder.getOrderId());
+                assertEquals("MIZUYO-KAN", mockOrder.getItemId());
+                assertEquals(16350, mockOrder.getQuantity());
+            }
+        });
+        mockCsv.setExpectedMessageCount(1);
+
+        String order = "{\"orderId\":\"Order-JSON-0001\", \"itemId\":\"MIZUYO-KAN\", \"quantity\":\"16350\"}";
+        OrderResponse expected = new OrderResponse()
+            .setAccepted(true)
+            .setOrderId("Order-JSON-0001")
+            .setDescription("Order accepted:[item='MIZUYO-KAN' quantity='16350']");
+        ObjectMapper jsonMapper = new ObjectMapper();
+        String expectedJson = jsonMapper.writeValueAsString(expected);
+        String answer = jsonProducer.requestBody("direct:json", order, String.class);
+        assertEquals(expectedJson, answer);
+        mockCsv.assertIsSatisfied();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 481f6a5..9aeaffc 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -99,6 +99,9 @@
     <module>camel-example-swagger-osgi</module>
     <module>camel-example-swagger-xml</module>
     <module>camel-example-tracer</module>
+    <module>camel-example-transformer-blueprint</module>
+    <module>camel-example-transformer-cdi</module>
+    <module>camel-example-transformer-demo</module>
     <module>camel-example-twitter-websocket</module>
     <module>camel-example-twitter-websocket-blueprint</module>
     <module>camel-example-widget-gadget-cdi</module>


[4/4] camel git commit: CAMEL-10447 Add contract based type awareness and transformer which leverages the type metadata

Posted by da...@apache.org.
CAMEL-10447 Add contract based type awareness and transformer which leverages the type metadata


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

Branch: refs/heads/master
Commit: 7ba090f5ca58f2f4a040898e56db3e11ba24fcde
Parents: b650414
Author: Tomohisa Igarashi <tm...@gmail.com>
Authored: Fri Jul 15 22:41:04 2016 +0900
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Nov 24 10:45:13 2016 +0100

----------------------------------------------------------------------
 .../java/org/apache/camel/CamelContext.java     |  34 ++
 .../main/java/org/apache/camel/Exchange.java    |   3 +
 .../apache/camel/impl/DefaultCamelContext.java  |  61 ++++
 .../apache/camel/impl/DefaultRouteContext.java  |  11 +
 .../impl/transformer/DataFormatTransformer.java | 154 ++++++++
 .../impl/transformer/ProcessorTransformer.java  | 122 +++++++
 .../camel/impl/transformer/TransformerKey.java  |  75 ++++
 .../java/org/apache/camel/model/Constants.java  |   3 +-
 .../apache/camel/model/InputTypeDefinition.java |  79 +++++
 .../camel/model/OutputTypeDefinition.java       |  80 +++++
 .../org/apache/camel/model/RouteDefinition.java |  80 ++++-
 .../CustomTransformerDefinition.java            | 106 ++++++
 .../DataFormatTransformerDefinition.java        | 161 +++++++++
 .../EndpointTransformerDefinition.java          |  88 +++++
 .../transformer/TransformerDefinition.java      | 133 +++++++
 .../transformer/TransformersDefinition.java     |  58 +++
 .../camel/model/transformer/package-info.java   |  24 ++
 .../camel/processor/CamelInternalProcessor.java | 120 +++++++
 .../java/org/apache/camel/spi/Contract.java     | 112 ++++++
 .../java/org/apache/camel/spi/DataType.java     |  89 +++++
 .../java/org/apache/camel/spi/RouteContext.java |   5 +
 .../java/org/apache/camel/spi/Transformer.java  | 128 +++++++
 .../resources/org/apache/camel/model/jaxb.index |   2 +
 .../apache/camel/model/transformer/jaxb.index   |  21 ++
 .../transformer/TransformerContractTest.java    | 173 +++++++++
 .../impl/transformer/TransformerRouteTest.java  | 349 +++++++++++++++++++
 .../blueprint/CamelContextFactoryBean.java      |  11 +
 .../camel/cdi/xml/CamelContextFactoryBean.java  |  12 +
 .../xml/AbstractCamelContextFactoryBean.java    |   6 +
 .../camel/spring/CamelContextFactoryBean.java   |  14 +
 .../spring/handler/CamelNamespaceHandler.java   |   1 +
 .../transformer/SpringTransformerRouteTest.java |  48 +++
 .../transformer/SpringTransformerRouteTest.xml  |  97 ++++++
 examples/README.md                              |   5 +
 .../README.md                                   |  51 +++
 .../camel-example-transformer-blueprint/pom.xml | 121 +++++++
 .../OSGI-INF/blueprint/camel-context.xml        |  53 +++
 .../src/main/resources/features.xml             |  29 ++
 .../src/main/resources/log4j2.properties        |  28 ++
 .../src/main/resources/transform.xsl            |  14 +
 .../camel-example-transformer-cdi/README.md     |  37 ++
 examples/camel-example-transformer-cdi/pom.xml  | 102 ++++++
 .../camel/example/transformer/cdi/MyRoutes.java |  56 +++
 .../src/main/resources/META-INF/LICENSE.txt     | 203 +++++++++++
 .../src/main/resources/META-INF/NOTICE.txt      |  11 +
 .../src/main/resources/META-INF/beans.xml       |  18 +
 .../src/main/resources/log4j2.properties        |  28 ++
 .../src/main/resources/transform.xsl            |  14 +
 .../camel-example-transformer-demo/README.md    |  33 ++
 examples/camel-example-transformer-demo/pom.xml | 141 ++++++++
 .../camel/example/transformer/demo/Order.java   |  82 +++++
 .../transformer/demo/OrderProcessor.java        |  41 +++
 .../example/transformer/demo/OrderResponse.java |  76 ++++
 .../transformer/demo/client/CamelClient.java    | 106 ++++++
 .../src/main/resources/META-INF/LICENSE.txt     | 203 +++++++++++
 .../src/main/resources/META-INF/NOTICE.txt      |  11 +
 .../resources/META-INF/spring/camel-context.xml | 100 ++++++
 .../src/main/resources/features.xml             |  30 ++
 .../src/main/resources/log4j2.properties        |  28 ++
 .../camel/example/transformer/demo/jaxb.index   |   2 +
 .../transformer/OrderRouteSpringTest.java       | 140 ++++++++
 examples/pom.xml                                |   3 +
 62 files changed, 4224 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index e3710d8..8c687b2 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -36,11 +36,13 @@ import org.apache.camel.model.RoutesDefinition;
 import org.apache.camel.model.remote.ServiceCallConfigurationDefinition;
 import org.apache.camel.model.rest.RestDefinition;
 import org.apache.camel.model.rest.RestsDefinition;
+import org.apache.camel.model.transformer.TransformerDefinition;
 import org.apache.camel.spi.AsyncProcessorAwaitManager;
 import org.apache.camel.spi.CamelContextNameStrategy;
 import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.DataFormatResolver;
+import org.apache.camel.spi.DataType;
 import org.apache.camel.spi.Debugger;
 import org.apache.camel.spi.EndpointRegistry;
 import org.apache.camel.spi.EndpointStrategy;
@@ -69,6 +71,7 @@ import org.apache.camel.spi.RuntimeEndpointRegistry;
 import org.apache.camel.spi.ServicePool;
 import org.apache.camel.spi.ShutdownStrategy;
 import org.apache.camel.spi.StreamCachingStrategy;
+import org.apache.camel.spi.Transformer;
 import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.camel.spi.UnitOfWorkFactory;
 import org.apache.camel.spi.UuidGenerator;
@@ -1217,6 +1220,37 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
     void setDataFormatResolver(DataFormatResolver dataFormatResolver);
 
     /**
+     * Sets the transformers that can be referenced in the routes.
+     *
+     * @param transformers the transformers
+     */
+    void setTransformers(List<TransformerDefinition> transformers);
+
+    /**
+     * Gets the transformers that can be referenced in the routes.
+     *
+     * @return the transformers available
+     */
+    List<TransformerDefinition> getTransformers();
+
+    /**
+     * Resolve a transformer given a scheme
+     *
+     * @param model data model name.
+     * @return the resolved transformer, or <tt>null</tt> if not found
+     */
+    Transformer resolveTransformer(String model);
+
+    /**
+     * Resolve a transformer given from/to data type.
+     *
+     * @param from from data type
+     * @param to to data type
+     * @return the resolved data format, or <tt>null</tt> if not found
+     */
+    Transformer resolveTransformer(DataType from, DataType to);
+
+    /**
      * Sets the properties that can be referenced in the camel context
      * <p/>
      * <b>Important:</b> This has nothing to do with property placeholders, and is just a plain set of key/value pairs

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/Exchange.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/Exchange.java b/camel-core/src/main/java/org/apache/camel/Exchange.java
index b23da1a..b6f6c37 100644
--- a/camel-core/src/main/java/org/apache/camel/Exchange.java
+++ b/camel-core/src/main/java/org/apache/camel/Exchange.java
@@ -231,6 +231,9 @@ public interface Exchange {
     String XSLT_FATAL_ERROR = "CamelXsltFatalError";
     String XSLT_WARNING     = "CamelXsltWarning";
 
+    String INPUT_TYPE  = "CamelInputType";
+    String OUTPUT_TYPE = "CamelOutputType";
+
     /**
      * Returns the {@link ExchangePattern} (MEP) of this exchange.
      *

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 12295bf..9cd8e83 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -90,6 +90,7 @@ import org.apache.camel.component.properties.PropertiesComponent;
 import org.apache.camel.impl.converter.BaseTypeConverterRegistry;
 import org.apache.camel.impl.converter.DefaultTypeConverter;
 import org.apache.camel.impl.converter.LazyLoadingTypeConverter;
+import org.apache.camel.impl.transformer.TransformerKey;
 import org.apache.camel.management.DefaultManagementMBeanAssembler;
 import org.apache.camel.management.DefaultManagementStrategy;
 import org.apache.camel.management.JmxSystemPropertyKeys;
@@ -105,6 +106,7 @@ import org.apache.camel.model.RoutesDefinition;
 import org.apache.camel.model.remote.ServiceCallConfigurationDefinition;
 import org.apache.camel.model.rest.RestDefinition;
 import org.apache.camel.model.rest.RestsDefinition;
+import org.apache.camel.model.transformer.TransformerDefinition;
 import org.apache.camel.processor.interceptor.BacklogDebugger;
 import org.apache.camel.processor.interceptor.BacklogTracer;
 import org.apache.camel.processor.interceptor.Debug;
@@ -119,6 +121,7 @@ import org.apache.camel.spi.ComponentResolver;
 import org.apache.camel.spi.Container;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.DataFormatResolver;
+import org.apache.camel.spi.DataType;
 import org.apache.camel.spi.Debugger;
 import org.apache.camel.spi.EndpointRegistry;
 import org.apache.camel.spi.EndpointStrategy;
@@ -150,6 +153,7 @@ import org.apache.camel.spi.RuntimeEndpointRegistry;
 import org.apache.camel.spi.ServicePool;
 import org.apache.camel.spi.ShutdownStrategy;
 import org.apache.camel.spi.StreamCachingStrategy;
+import org.apache.camel.spi.Transformer;
 import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.camel.spi.UnitOfWorkFactory;
 import org.apache.camel.spi.UuidGenerator;
@@ -276,6 +280,8 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
     private final StopWatch stopWatch = new StopWatch(false);
     private Date startDate;
     private ModelJAXBContextFactory modelJAXBContextFactory;
+    private List<TransformerDefinition> transformers = new ArrayList<TransformerDefinition>();
+    private Map<TransformerKey, Transformer> transformerRegistry = new HashMap<TransformerKey, Transformer>();
 
     /**
      * Creates the {@link CamelContext} using {@link JndiRegistry} as registry,
@@ -4323,6 +4329,61 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
                 }
             }
         }
+    }
+
+    @Override
+    public void setTransformers(List<TransformerDefinition> transformers) {
+        this.transformers = transformers;
+    }
+
+    @Override
+    public List<TransformerDefinition> getTransformers() {
+        return transformers;
+    }
+
+    @Override
+    public Transformer resolveTransformer(String scheme) {
+        if (scheme == null) {
+            return null;
+        }
+        return resolveTransformer(getTransformerKey(scheme));
+    }
+
+    @Override
+    public Transformer resolveTransformer(DataType from, DataType to) {
+        if (from == null || to == null) {
+            return null;
+        }
+        return resolveTransformer(getTransformerKey(from, to));
+    }
+
+    protected Transformer resolveTransformer(TransformerKey key) {
+        Transformer transformer = transformerRegistry.get(key);
+        if (transformer != null) {
+            return transformer;
+        }
+        for (TransformerDefinition def : getTransformers()) {
+            if (key.match(def)) {
+                try {
+                    transformer = def.createTransformer(this);
+                    transformer.setCamelContext(this);
+                    addService(transformer);
+                } catch (Exception e) {
+                    throw new RuntimeCamelException(e);
+                }
+                log.debug("Registering Transformer '{}'", transformer);
+                transformerRegistry.put(key, transformer);
+                return transformer;
+            }
+        }
+        return null;
+    }
+
+    protected TransformerKey getTransformerKey(String scheme) {
+        return new TransformerKey(scheme);
+    }
 
+    protected TransformerKey getTransformerKey(DataType from, DataType to) {
+        return new TransformerKey(from, to);
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
index d18ccb7..8a2e7c1 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
@@ -36,6 +36,7 @@ import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.processor.CamelInternalProcessor;
 import org.apache.camel.processor.Pipeline;
+import org.apache.camel.spi.Contract;
 import org.apache.camel.spi.InterceptStrategy;
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.spi.RoutePolicy;
@@ -68,6 +69,7 @@ public class DefaultRouteContext implements RouteContext {
     private List<RoutePolicy> routePolicyList = new ArrayList<RoutePolicy>();
     private ShutdownRoute shutdownRoute;
     private ShutdownRunningTask shutdownRunningTask;
+    private Contract contract;
 
     public DefaultRouteContext(CamelContext camelContext, RouteDefinition route, FromDefinition from, Collection<Route> routes) {
         this.camelContext = camelContext;
@@ -191,6 +193,11 @@ public class DefaultRouteContext implements RouteContext {
             // wrap in route lifecycle
             internal.addAdvice(new CamelInternalProcessor.RouteLifecycleAdvice());
 
+            // wrap in contract
+            if (contract != null) {
+                internal.addAdvice(new CamelInternalProcessor.ContractAdvice(contract));
+            }
+
             // and create the route that wraps the UoW
             Route edcr = new EventDrivenConsumerRoute(this, getEndpoint(), internal);
             edcr.getProperties().put(Route.ID_PROPERTY, routeId);
@@ -400,4 +407,8 @@ public class DefaultRouteContext implements RouteContext {
     public List<RoutePolicy> getRoutePolicyList() {
         return routePolicyList;
     }
+
+    public void setContract(Contract contract) {
+        this.contract = contract;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/impl/transformer/DataFormatTransformer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/transformer/DataFormatTransformer.java b/camel-core/src/main/java/org/apache/camel/impl/transformer/DataFormatTransformer.java
new file mode 100644
index 0000000..9993807
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/transformer/DataFormatTransformer.java
@@ -0,0 +1,154 @@
+/**
+ * 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.impl.transformer;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.converter.stream.OutputStreamBuilder;
+import org.apache.camel.model.DataFormatDefinition;
+import org.apache.camel.model.transformer.DataFormatTransformerDefinition;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.DataType;
+import org.apache.camel.spi.Transformer;
+import org.apache.camel.support.ServiceSupport;
+import org.apache.camel.util.ServiceHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A <a href="http://camel.apache.org/transformer.html">Transformer</a>
+ * leverages DataFormat to perform transformation.
+ */
+public class DataFormatTransformer extends Transformer {
+    private static final Logger LOG = LoggerFactory.getLogger(DataFormatTransformer.class);
+
+    private String dataFormatRef;
+    private DataFormatDefinition dataFormatType;
+    private DataFormat dataFormat;
+    private String transformerString;
+
+    public DataFormatTransformer(CamelContext context) {
+        setCamelContext(context);
+    }
+
+    /**
+     * Perform data transformation with specified from/to type using DataFormat.
+     * @param message message to apply transformation
+     * @param from 'from' data type
+     * @param to 'to' data type
+     */
+    @Override
+    public void transform(Message message, DataType from, DataType to) throws Exception {
+        Exchange exchange = message.getExchange();
+        CamelContext context = exchange.getContext();
+        
+        // Unmarshaling into Java Object
+        if ((to == null || to.isJavaType()) && (from.equals(getFrom()) || from.getModel().equals(getModel()))) {
+            DataFormat dataFormat = getDataFormat(exchange);
+            LOG.debug("Unmarshaling with '{}'", dataFormat);
+            Object answer = dataFormat.unmarshal(exchange, message.getBody(InputStream.class));
+            if (to != null && to.getName() != null) {
+                Class<?> toClass = context.getClassResolver().resolveClass(to.getName());
+                if (!toClass.isAssignableFrom(answer.getClass())) {
+                    LOG.debug("Converting to '{}'", toClass.getName());
+                    answer = context.getTypeConverter().mandatoryConvertTo(toClass, answer);
+                }
+            }
+            message.setBody(answer);
+            
+        // Marshaling from Java Object
+        } else if ((from == null || from.isJavaType()) && (to.equals(getTo()) || to.getModel().equals(getModel()))) {
+            Object input = message.getBody();
+            if (from != null && from.getName() != null) {
+                Class<?> fromClass = context.getClassResolver().resolveClass(from.getName());
+                if (!fromClass.isAssignableFrom(input.getClass())) {
+                    LOG.debug("Converting to '{}'", fromClass.getName());
+                    input = context.getTypeConverter().mandatoryConvertTo(fromClass, input);
+                }
+            }
+            OutputStreamBuilder osb = OutputStreamBuilder.withExchange(exchange);
+            DataFormat dataFormat = getDataFormat(exchange);
+            LOG.debug("Marshaling with '{}'", dataFormat);
+            dataFormat.marshal(exchange, message.getBody(), osb);
+            message.setBody(osb.build());
+            
+        } else {
+            throw new IllegalArgumentException("Unsupported transformation: from='" + from + ", to='" + to + "'");
+        }
+    }
+
+    /**
+     * A bit dirty hack to create DataFormat instance, as it requires a RouteContext anyway.
+     */
+    private DataFormat getDataFormat(Exchange exchange) throws Exception {
+        if (this.dataFormat == null) {
+            this.dataFormat = DataFormatDefinition.getDataFormat(
+                exchange.getUnitOfWork().getRouteContext(), this.dataFormatType, this.dataFormatRef);
+            if (this.dataFormat != null && !getCamelContext().hasService(this.dataFormat)) {
+                getCamelContext().addService(this.dataFormat, false);
+            }
+        }
+        return this.dataFormat;
+    }
+
+    /**
+     * Set DataFormat ref.
+     * @param ref DataFormat ref
+     * @return this DataFormatTransformer instance
+     */
+    public DataFormatTransformer setDataFormatRef(String ref) {
+        this.dataFormatRef = ref;
+        this.transformerString = null;
+        return this;
+    }
+
+    /**
+     * Set DataFormatDefinition.
+     * @param dataFormatType DataFormatDefinition
+     * @return this DataFormatTransformer instance
+     */
+    public DataFormatTransformer setDataFormatType(DataFormatDefinition dataFormatType) {
+        this.dataFormatType = dataFormatType;
+        this.transformerString = null;
+        return this;
+    }
+
+    @Override
+    public String toString() {
+        if (transformerString == null) {
+            transformerString =
+                String.format("DataFormatTransformer[scheme='%s', from='%s', to='%s', ref='%s', type='%s']",
+                    getModel(), getFrom(), getTo(), dataFormatRef, dataFormatType);
+        }
+        return transformerString;
+    }
+
+    @Override
+    public void doStart() throws Exception {
+        // no-op
+    }
+
+    @Override
+    public void doStop() throws Exception {
+        ServiceHelper.stopService(this.dataFormat);
+        getCamelContext().removeService(this.dataFormat);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/impl/transformer/ProcessorTransformer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/transformer/ProcessorTransformer.java b/camel-core/src/main/java/org/apache/camel/impl/transformer/ProcessorTransformer.java
new file mode 100644
index 0000000..f7bc2d4
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/transformer/ProcessorTransformer.java
@@ -0,0 +1,122 @@
+/**
+ * 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.impl.transformer;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.model.transformer.EndpointTransformerDefinition;
+import org.apache.camel.processor.SendProcessor;
+import org.apache.camel.spi.DataType;
+import org.apache.camel.spi.Transformer;
+import org.apache.camel.support.ServiceSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A <a href="http://camel.apache.org/transformer.html">Transformer</a>
+ * leverages Processor to perform transformation.
+ */
+public class ProcessorTransformer extends Transformer {
+    private static final Logger LOG = LoggerFactory.getLogger(ProcessorTransformer.class);
+
+    private Processor processor;
+    private String transformerString;
+
+    public ProcessorTransformer(CamelContext context) {
+        setCamelContext(context);
+    }
+
+    /**
+     * Perform data transformation with specified from/to type using Processor.
+     * @param message message to apply transformation
+     * @param from 'from' data type
+     * @param to 'to' data type
+     */
+    @Override
+    public void transform(Message message, DataType from, DataType to) throws Exception {
+        Exchange exchange = message.getExchange();
+        CamelContext context = exchange.getContext();
+        if (from.isJavaType()) {
+            Object input = message.getBody();
+            Class<?> fromClass = context.getClassResolver().resolveClass(from.getName());
+            if (!fromClass.isAssignableFrom(input.getClass())) {
+                LOG.debug("Converting to '{}'", fromClass.getName());
+                input = context.getTypeConverter().mandatoryConvertTo(fromClass, input);
+                message.setBody(input);
+            }
+        }
+        
+        LOG.debug("Sending to transform processor '{}'", processor);
+        DefaultExchange transformExchange = new DefaultExchange(exchange);
+        transformExchange.setIn(message);
+        transformExchange.setProperties(exchange.getProperties());
+        processor.process(transformExchange);
+        Message answer = transformExchange.hasOut() ? transformExchange.getOut() : transformExchange.getIn();
+        
+        if (to.isJavaType()) {
+            Object answerBody = answer.getBody();
+            Class<?> toClass = context.getClassResolver().resolveClass(to.getName());
+            if (!toClass.isAssignableFrom(answerBody.getClass())) {
+                LOG.debug("Converting to '{}'", toClass.getName());
+                answerBody = context.getTypeConverter().mandatoryConvertTo(toClass, answerBody);
+                answer.setBody(answerBody);
+            }
+        }
+        
+        message.copyFrom(answer);
+    }
+
+    /**
+     * Set Processor.
+     * @param processor Processor
+     * @return this ProcessorTransformer instance
+     */
+    public ProcessorTransformer setProcessor(Processor processor) {
+        this.processor = processor;
+        this.transformerString = null;
+        return this;
+    }
+
+    @Override
+    public String toString() {
+        if (transformerString == null) {
+            transformerString =
+                String.format("ProcessorTransformer[scheme='%s', from='%s', to='%s', processor='%s']",
+                    getModel(), getFrom(), getTo(), processor);
+        }
+        return transformerString;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        if (this.processor instanceof ServiceSupport) {
+            ((ServiceSupport)this.processor).start();
+        }
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        if (this.processor instanceof ServiceSupport) {
+            ((ServiceSupport)this.processor).stop();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/impl/transformer/TransformerKey.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/transformer/TransformerKey.java b/camel-core/src/main/java/org/apache/camel/impl/transformer/TransformerKey.java
new file mode 100644
index 0000000..c5680ea
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/transformer/TransformerKey.java
@@ -0,0 +1,75 @@
+/**
+ * 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.impl.transformer;
+
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultEndpointRegistry;
+import org.apache.camel.model.transformer.TransformerDefinition;
+import org.apache.camel.spi.DataType;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ValueHolder;
+
+/**
+ * Key used in Transformer registry in {@link DefaultCamelContext},
+ * to ensure a consistent lookup.
+ */
+public final class TransformerKey extends ValueHolder<String> {
+
+    private String scheme;
+    private DataType from;
+    private DataType to;
+
+    public TransformerKey(String scheme) {
+        super(scheme);
+        this.scheme = scheme;
+        ObjectHelper.notEmpty(scheme, "scheme");
+    }
+
+    public TransformerKey(DataType from, DataType to) {
+        super(createKeyString(from, to));
+        this.from = from;
+        this.to = to;
+    }
+
+    private static String createKeyString(DataType from, DataType to) {
+        return from + "/" + to;
+    }
+
+    /**
+     * Test if specified TransformerDefinition matches with data type represented by this key.
+     * @param def TransformerDefinition
+     * @return true if it matches, otherwise false
+     */
+    public boolean match(TransformerDefinition def) {
+        if (scheme != null) {
+            return scheme.equals(def.getScheme());
+        }
+        if (from == null) {
+            return to.toString().equals(def.getTo());
+        }
+        if (to == null) {
+            return from.toString().equals(def.getFrom());
+        }
+        return from.toString().equals(def.getFrom()) && to.toString().equals(def.getTo());
+    }
+
+    @Override
+    public String toString() {
+        return get();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/model/Constants.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/Constants.java b/camel-core/src/main/java/org/apache/camel/model/Constants.java
index 9c72ac1..eaec06e 100644
--- a/camel-core/src/main/java/org/apache/camel/model/Constants.java
+++ b/camel-core/src/main/java/org/apache/camel/model/Constants.java
@@ -31,7 +31,8 @@ public final class Constants {
         + "org.apache.camel.model.language:"
         + "org.apache.camel.model.loadbalancer:"
         + "org.apache.camel.model.remote:"
-        + "org.apache.camel.model.rest";
+        + "org.apache.camel.model.rest:"
+        + "org.apache.camel.model.transformer";
 
     public static final String PLACEHOLDER_QNAME = "http://camel.apache.org/schema/placeholder";
 

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/model/InputTypeDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/InputTypeDefinition.java b/camel-core/src/main/java/org/apache/camel/model/InputTypeDefinition.java
new file mode 100644
index 0000000..782e041
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/InputTypeDefinition.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.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.spi.Metadata;
+
+/**
+ * Set data type of the input message.
+ */
+@Metadata(label = "configuration")
+@XmlRootElement(name = "inputType")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class InputTypeDefinition extends OptionalIdentifiedDefinition<InputTypeDefinition> {
+    @XmlAttribute(required = true)
+    private String urn;
+    @XmlTransient
+    private Class<?> clazz;
+
+    public InputTypeDefinition() {
+    }
+
+    /**
+     * Get input type URN.
+     * @return input type URN
+     */
+    public String getUrn() {
+        if (clazz != null) {
+            return "java:" + clazz.getName();
+        }
+        return urn;
+    }
+
+    /**
+     * Set input type URN.
+     * @param urn input type URN
+     */
+    public void setUrn(String urn) {
+        this.urn = urn;
+    }
+
+    /**
+     * Set input type via Java Class.
+     * @param clazz Java Class
+     */
+    public void setJavaClass(Class<?> clazz) {
+        this.clazz = clazz;
+    }
+
+    @Override
+    public String toString() {
+        return "inputType[" + urn + "]";
+    }
+
+    @Override
+    public String getLabel() {
+        return "inputType[" + urn + "]";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/model/OutputTypeDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/OutputTypeDefinition.java b/camel-core/src/main/java/org/apache/camel/model/OutputTypeDefinition.java
new file mode 100644
index 0000000..755874a
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/OutputTypeDefinition.java
@@ -0,0 +1,80 @@
+/**
+ * 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.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.spi.Metadata;
+
+/**
+ * Sets data type of the output message.
+ */
+@Metadata(label = "configuration")
+@XmlRootElement(name = "outputType")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class OutputTypeDefinition extends OptionalIdentifiedDefinition<OutputTypeDefinition> {
+    @XmlAttribute(required = true)
+    private String urn;
+    @XmlTransient
+    private Class<?> clazz;
+
+    public OutputTypeDefinition() {
+    }
+
+    /**
+     * Get output type URN.
+     * @return output type URN
+     */
+    public String getUrn() {
+        if (clazz != null) {
+            return "java:" + clazz.getName();
+        }
+        return urn;
+    }
+
+    /**
+     * Set output type URN.
+     * @param urn output type URN
+     * @return this OutputTypeDefinition instance
+     */
+    public void setUrn(String urn) {
+        this.urn = urn;
+    }
+
+    /**
+     * Set output type via Java Class.
+     * @param clazz Java Class
+     */
+    public void setJavaClass(Class<?> clazz) {
+        this.clazz = clazz;
+    }
+
+    @Override
+    public String toString() {
+        return "outputType[" + urn + "]";
+    }
+
+    @Override
+    public String getLabel() {
+        return "outputType[" + urn + "]";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
index 83f51ef..e140dc0 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -46,6 +46,7 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultRouteContext;
 import org.apache.camel.model.rest.RestDefinition;
 import org.apache.camel.processor.interceptor.HandleFault;
+import org.apache.camel.spi.Contract;
 import org.apache.camel.spi.LifecycleStrategy;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.RouteContext;
@@ -61,7 +62,7 @@ import org.apache.camel.util.ObjectHelper;
  */
 @Metadata(label = "configuration")
 @XmlRootElement(name = "route")
-@XmlType(propOrder = {"inputs", "outputs"})
+@XmlType(propOrder = {"inputs", "inputType", "outputType", "outputs"})
 @XmlAccessorType(XmlAccessType.PROPERTY)
 // must use XmlAccessType.PROPERTY as there is some custom logic needed to be executed in the setter methods
 public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
@@ -87,6 +88,8 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
     private boolean contextScopedErrorHandler = true;
     private Boolean rest;
     private RestDefinition restDefinition;
+    private InputTypeDefinition inputType;
+    private OutputTypeDefinition outputType;
 
     public RouteDefinition() {
     }
@@ -629,6 +632,50 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
         return this;
     }
 
+    /**
+     * Declare an input type.
+     * @param name input type URN
+     * @return the builder
+     */
+    public RouteDefinition inputType(String name) {
+        inputType = new InputTypeDefinition();
+        inputType.setUrn(name);
+        return this;
+    }
+
+    /**
+     * Declare an input type with Java class.
+     * @param clazz Class object of the input type
+     * @return the builder
+     */
+    public RouteDefinition inputType(Class clazz) {
+        inputType = new InputTypeDefinition();
+        inputType.setJavaClass(clazz);
+        return this;
+    }
+
+    /**
+     * Declare an output type.
+     * @param name output type URN
+     * @return the builder
+     */
+    public RouteDefinition outputType(String name) {
+        outputType = new OutputTypeDefinition();
+        outputType.setUrn(name);
+        return this;
+    }
+
+    /**
+     * Declare an output type.
+     * @param clazz Class object of the output type
+     * @return the builder
+     */
+    public RouteDefinition outputType(Class clazz) {
+        outputType = new OutputTypeDefinition();
+        outputType.setJavaClass(clazz);
+        return this;
+    }
+
     // Properties
     // -----------------------------------------------------------------------
 
@@ -935,6 +982,24 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
         return true;
     }
 
+    @XmlElementRef(required = false)
+    public void setInputType(InputTypeDefinition inputType) {
+        this.inputType = inputType;
+    }
+
+    public InputTypeDefinition getInputType() {
+        return this.inputType;
+    }
+
+    @XmlElementRef(required = false)
+    public void setOutputType(OutputTypeDefinition outputType) {
+        this.outputType = outputType;
+    }
+
+    public OutputTypeDefinition getOutputType() {
+        return this.outputType;
+    }
+
     // Implementation methods
     // -------------------------------------------------------------------------
     protected RouteContext addRoutes(CamelContext camelContext, Collection<Route> routes, FromDefinition fromType) throws Exception {
@@ -1062,6 +1127,18 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
             throw new FailedToCreateRouteException(route.getId(), route.toString(), at, cause);
         }
 
+        // add data type contract
+        if (inputType != null || outputType != null) {
+            Contract contract = new Contract();
+            if (inputType != null) {
+                contract.setInputType(inputType.getUrn());
+            }
+            if (outputType != null) {
+                contract.setOutputType(outputType.getUrn());
+            }
+            routeContext.setContract(contract);
+        }
+
         List<ProcessorDefinition<?>> list = new ArrayList<ProcessorDefinition<?>>(outputs);
         for (ProcessorDefinition<?> output : list) {
             try {
@@ -1075,4 +1152,5 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
         routeContext.commit();
         return routeContext;
     }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java b/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java
new file mode 100644
index 0000000..3af804b
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/CustomTransformerDefinition.java
@@ -0,0 +1,106 @@
+/**
+ * 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.model.transformer;
+
+import java.util.Map;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAnyAttribute;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.component.bean.BeanHolder;
+import org.apache.camel.component.bean.BeanProcessor;
+import org.apache.camel.component.bean.ConstantStaticTypeBeanHolder;
+import org.apache.camel.component.bean.ConstantTypeBeanHolder;
+import org.apache.camel.impl.transformer.ProcessorTransformer;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.DataType;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.RouteContext;
+import org.apache.camel.spi.Transformer;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * Represents a BeanTransformer.
+ */
+@Metadata(label = "transformation")
+@XmlType(name = "customTransformer")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CustomTransformerDefinition extends TransformerDefinition {
+    @XmlAttribute
+    private String ref;
+    @XmlAttribute
+    private String type;
+
+    @Override
+    protected Transformer doCreateTransformer() throws Exception {
+        if (ref == null && type == null) {
+            throw new IllegalArgumentException("'ref' or 'type' must be specified for customTransformer");
+        }
+        Transformer transformer;
+        if (ref != null) {
+            transformer = getCamelContext().getRegistry().lookupByNameAndType(ref, Transformer.class);
+            if (transformer == null) {
+                throw new IllegalArgumentException("Cannot find transformer with ref:" + ref);
+            }
+            if (transformer.getModel() != null || transformer.getFrom() != null || transformer.getTo() != null) {
+                throw new IllegalArgumentException(String.format("Transformer '%s' is already in use. Please check if duplicate transformer exists.", ref));
+            }
+        } else {
+            Class<Transformer> transformerClass = getCamelContext().getClassResolver().resolveMandatoryClass(type, Transformer.class);
+            if (transformerClass == null) {
+                throw new IllegalArgumentException("Cannot find transformer class: " + type);
+            }
+            transformer = transformerClass.newInstance();
+        }
+        transformer.setCamelContext(getCamelContext());
+        return transformer.setModel(getScheme())
+                          .setFrom(getFrom())
+                          .setTo(getTo());
+    }
+
+    public String getRef() {
+        return ref;
+    }
+
+    /**
+     * Set a bean reference of the Transformer
+     * @param ref the bean reference of the Transformer
+     */
+    public void setRef(String ref) {
+        this.ref = ref;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    /**
+     * Set a class name of the Transformer
+     * @param ref the class name of the Transformer
+     */
+    public void setType(String type) {
+        this.type = type;
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java b/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java
new file mode 100644
index 0000000..6429b85
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/DataFormatTransformerDefinition.java
@@ -0,0 +1,161 @@
+/**
+ * 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.model.transformer;
+
+import java.util.Map;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAnyAttribute;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Message;
+import org.apache.camel.impl.transformer.DataFormatTransformer;
+import org.apache.camel.model.DataFormatDefinition;
+import org.apache.camel.model.dataformat.AvroDataFormat;
+import org.apache.camel.model.dataformat.Base64DataFormat;
+import org.apache.camel.model.dataformat.BeanioDataFormat;
+import org.apache.camel.model.dataformat.BindyDataFormat;
+import org.apache.camel.model.dataformat.BoonDataFormat;
+import org.apache.camel.model.dataformat.CastorDataFormat;
+import org.apache.camel.model.dataformat.CryptoDataFormat;
+import org.apache.camel.model.dataformat.CsvDataFormat;
+import org.apache.camel.model.dataformat.CustomDataFormat;
+import org.apache.camel.model.dataformat.FlatpackDataFormat;
+import org.apache.camel.model.dataformat.GzipDataFormat;
+import org.apache.camel.model.dataformat.HL7DataFormat;
+import org.apache.camel.model.dataformat.IcalDataFormat;
+import org.apache.camel.model.dataformat.JacksonXMLDataFormat;
+import org.apache.camel.model.dataformat.JaxbDataFormat;
+import org.apache.camel.model.dataformat.JibxDataFormat;
+import org.apache.camel.model.dataformat.JsonDataFormat;
+import org.apache.camel.model.dataformat.PGPDataFormat;
+import org.apache.camel.model.dataformat.ProtobufDataFormat;
+import org.apache.camel.model.dataformat.RssDataFormat;
+import org.apache.camel.model.dataformat.SerializationDataFormat;
+import org.apache.camel.model.dataformat.SoapJaxbDataFormat;
+import org.apache.camel.model.dataformat.StringDataFormat;
+import org.apache.camel.model.dataformat.SyslogDataFormat;
+import org.apache.camel.model.dataformat.TarFileDataFormat;
+import org.apache.camel.model.dataformat.TidyMarkupDataFormat;
+import org.apache.camel.model.dataformat.UniVocityCsvDataFormat;
+import org.apache.camel.model.dataformat.UniVocityFixedWidthDataFormat;
+import org.apache.camel.model.dataformat.UniVocityTsvDataFormat;
+import org.apache.camel.model.dataformat.XMLBeansDataFormat;
+import org.apache.camel.model.dataformat.XMLSecurityDataFormat;
+import org.apache.camel.model.dataformat.XStreamDataFormat;
+import org.apache.camel.model.dataformat.XmlJsonDataFormat;
+import org.apache.camel.model.dataformat.XmlRpcDataFormat;
+import org.apache.camel.model.dataformat.ZipDataFormat;
+import org.apache.camel.model.dataformat.ZipFileDataFormat;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.RouteContext;
+import org.apache.camel.spi.Transformer;
+
+/**
+ * Represents a DataFormatTransformer.
+ */
+@Metadata(label = "transformation")
+@XmlType(name = "dataFormatTransformer")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class DataFormatTransformerDefinition extends TransformerDefinition {
+
+    @XmlElements({
+        @XmlElement(required = false, name = "avro", type = AvroDataFormat.class),
+        @XmlElement(required = false, name = "base64", type = Base64DataFormat.class),
+        @XmlElement(required = false, name = "beanio", type = BeanioDataFormat.class),
+        @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class),
+        @XmlElement(required = false, name = "boon", type = BoonDataFormat.class),
+        @XmlElement(required = false, name = "castor", type = CastorDataFormat.class),
+        @XmlElement(required = false, name = "crypto", type = CryptoDataFormat.class),
+        @XmlElement(required = false, name = "csv", type = CsvDataFormat.class),
+        @XmlElement(required = false, name = "custom", type = CustomDataFormat.class),
+        @XmlElement(required = false, name = "flatpack", type = FlatpackDataFormat.class),
+        @XmlElement(required = false, name = "gzip", type = GzipDataFormat.class),
+        @XmlElement(required = false, name = "hl7", type = HL7DataFormat.class),
+        @XmlElement(required = false, name = "ical", type = IcalDataFormat.class),
+        @XmlElement(required = false, name = "jacksonxml", type = JacksonXMLDataFormat.class),
+        @XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class),
+        @XmlElement(required = false, name = "jibx", type = JibxDataFormat.class),
+        @XmlElement(required = false, name = "json", type = JsonDataFormat.class),
+        @XmlElement(required = false, name = "protobuf", type = ProtobufDataFormat.class),
+        @XmlElement(required = false, name = "rss", type = RssDataFormat.class),
+        @XmlElement(required = false, name = "secureXML", type = XMLSecurityDataFormat.class),
+        @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
+        @XmlElement(required = false, name = "soapjaxb", type = SoapJaxbDataFormat.class),
+        @XmlElement(required = false, name = "string", type = StringDataFormat.class),
+        @XmlElement(required = false, name = "syslog", type = SyslogDataFormat.class),
+        @XmlElement(required = false, name = "tarfile", type = TarFileDataFormat.class),
+        @XmlElement(required = false, name = "tidyMarkup", type = TidyMarkupDataFormat.class),
+        @XmlElement(required = false, name = "univocity-csv", type = UniVocityCsvDataFormat.class),
+        @XmlElement(required = false, name = "univocity-fixed", type = UniVocityFixedWidthDataFormat.class),
+        @XmlElement(required = false, name = "univocity-tsv", type = UniVocityTsvDataFormat.class),
+        @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
+        @XmlElement(required = false, name = "xmljson", type = XmlJsonDataFormat.class),
+        @XmlElement(required = false, name = "xmlrpc", type = XmlRpcDataFormat.class),
+        @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class),
+        @XmlElement(required = false, name = "pgp", type = PGPDataFormat.class),
+        @XmlElement(required = false, name = "zip", type = ZipDataFormat.class),
+        @XmlElement(required = false, name = "zipFile", type = ZipFileDataFormat.class)}
+        )
+    private DataFormatDefinition dataFormatType;
+
+    @XmlAttribute
+    private String ref;
+
+    @Override
+    protected Transformer doCreateTransformer() {
+        return new DataFormatTransformer(getCamelContext())
+                .setDataFormatType(dataFormatType)
+                .setDataFormatRef(ref)
+                .setModel(getScheme())
+                .setFrom(getFrom())
+                .setTo(getTo());
+    }
+
+    public String getRef() {
+        return ref;
+    }
+
+    /**
+     * Set the reference of the DataFormat.
+     * @param ref reference of the DataFormat
+     */
+    public void setRef(String ref) {
+        this.ref = ref;
+    }
+
+    public DataFormatDefinition getDataFormatType() {
+        return dataFormatType;
+    }
+
+    /**
+     * The data format to be used
+     */
+    public void setDataFormatType(DataFormatDefinition dataFormatType) {
+        this.dataFormatType = dataFormatType;
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java b/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java
new file mode 100644
index 0000000..7b16fc4
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/EndpointTransformerDefinition.java
@@ -0,0 +1,88 @@
+/**
+ * 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.model.transformer;
+
+import java.util.Map;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAnyAttribute;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.impl.transformer.ProcessorTransformer;
+import org.apache.camel.processor.SendProcessor;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.RouteContext;
+import org.apache.camel.spi.Transformer;
+
+/**
+ * Represents a EndpointTransformer.
+ */
+@Metadata(label = "transformation")
+@XmlType(name = "endpointTransformer")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class EndpointTransformerDefinition extends TransformerDefinition {
+
+    @XmlAttribute
+    private String ref;
+    @XmlAttribute
+    private String uri;
+
+    @Override
+    protected Transformer doCreateTransformer() throws Exception {
+        Endpoint endpoint = uri != null ? getCamelContext().getEndpoint(uri)
+            : getCamelContext().getRegistry().lookupByNameAndType(ref, Endpoint.class);
+        SendProcessor processor = new SendProcessor(endpoint, ExchangePattern.InOut);
+        return new ProcessorTransformer(getCamelContext())
+            .setProcessor(processor)
+            .setModel(getScheme())
+            .setFrom(getFrom())
+            .setTo(getTo());
+    }
+
+    public String getRef() {
+        return ref;
+    }
+
+    /**
+     * Set the reference of the Endpoint.
+     * @param ref reference of the Endpoint
+     */
+    public void setRef(String ref) {
+        this.ref = ref;
+    }
+
+    public String getUri() {
+        return uri;
+    }
+
+    /**
+     * Set the URI of the Endpoint.
+     * @param uri URI of the Endpoint
+     */
+    public void setUri(String uri) {
+        this.uri = uri;
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java b/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java
new file mode 100644
index 0000000..7695a63
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/TransformerDefinition.java
@@ -0,0 +1,133 @@
+/**
+ * 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.model.transformer;
+
+import java.util.Map;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAnyAttribute;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.namespace.QName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.model.IdentifiedType;
+import org.apache.camel.model.OtherAttributesAware;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.DataType;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.RouteContext;
+import org.apache.camel.spi.Transformer;
+import org.apache.camel.util.ObjectHelper;
+
+import static org.apache.camel.util.EndpointHelper.isReferenceParameter;
+
+/**
+ * Represents a Transformer.
+ */
+@Metadata(label = "transformation")
+@XmlType(name = "transformer")
+@XmlAccessorType(XmlAccessType.FIELD)
+public abstract class TransformerDefinition {
+    @XmlAttribute
+    private String scheme;
+    @XmlAttribute
+    private String from;
+    @XmlAttribute
+    private String to;
+    @XmlTransient
+    private CamelContext camelContext;
+
+    public Transformer createTransformer(CamelContext context) throws Exception {
+        this.camelContext = context;
+        return doCreateTransformer();
+    };
+
+    protected abstract Transformer doCreateTransformer() throws Exception;
+
+    public String getScheme() {
+        return scheme;
+    }
+
+    /**
+     * Set a scheme name supported by the transformer.
+     * @param scheme scheme name
+     */
+    public void setScheme(String scheme) {
+        this.scheme = scheme;
+    }
+
+    public String getFrom() {
+        return from;
+    }
+
+    /**
+     * Set the 'from' data type .
+     * @param from 'from' data type
+     */
+    public void setFrom(String from) {
+        this.from = from;
+    }
+
+    /**
+     * Set the 'from' data type using Java class.
+     * @param clazz 'from' Java class
+     */
+    public void setFrom(Class<?> clazz) {
+        this.from = "java:" + clazz.getName();
+    }
+
+    public String getTo() {
+        return to;
+    }
+
+    /**
+     * Set the 'to' data type.
+     * @param to 'to' data type 
+     */
+    public void setTo(String to) {
+        this.to = to;
+    }
+
+    /**
+     * Set the 'to' data type using Java class.
+     * @param clazz 'to' Java class
+     */
+    public void setTo(Class<?> clazz) {
+        this.to = "java:" + clazz.getName();
+    }
+
+    /**
+     * Get the CamelContext.
+     * @return
+     */
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    /**
+     * Set the CamelContext.
+     * @param camelContext CamelContext
+     */
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/model/transformer/TransformersDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/TransformersDefinition.java b/camel-core/src/main/java/org/apache/camel/model/transformer/TransformersDefinition.java
new file mode 100644
index 0000000..3820c0f
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/TransformersDefinition.java
@@ -0,0 +1,58 @@
+/**
+ * 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.model.transformer;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.DataFormatDefinition;
+import org.apache.camel.spi.Metadata;
+
+/**
+ * To configure transforms.
+ */
+@Metadata(label = "transformation", title = "Transformations")
+@XmlRootElement(name = "transformers")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class TransformersDefinition {
+
+    @XmlElements({
+        @XmlElement(required = false, name = "dataFormatTransformer", type = DataFormatTransformerDefinition.class),
+        @XmlElement(required = false, name = "endpointTransformer", type = EndpointTransformerDefinition.class),
+        @XmlElement(required = false, name = "customTransformer", type = CustomTransformerDefinition.class)}
+        )
+    private List<TransformerDefinition> transforms;
+
+    /**
+     * A list holding the configured transformations
+     */
+    public void setTransformers(List<TransformerDefinition> transforms) {
+        this.transforms = transforms;
+    }
+
+    public List<TransformerDefinition> getTransforms() {
+        return transforms;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/model/transformer/package-info.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/transformer/package-info.java b/camel-core/src/main/java/org/apache/camel/model/transformer/package-info.java
new file mode 100644
index 0000000..840ddb3
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/transformer/package-info.java
@@ -0,0 +1,24 @@
+/**
+ * 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.
+ */
+
+/**
+ * The JAXB POJOs for the
+ * <a href="http://camel.apache.org/transformer.html">Transformers</a> used to transform message contents
+ * according to declared data types inside <a href="http://camel.apache.org/components.html">components</a>
+ */
+@javax.xml.bind.annotation.XmlSchema(namespace = "http://camel.apache.org/schema/spring", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
+package org.apache.camel.model.transformer;

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
index 50f2af4..ab9892a 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
@@ -26,6 +26,7 @@ import java.util.concurrent.RejectedExecutionException;
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
+import org.apache.camel.Message;
 import org.apache.camel.MessageHistory;
 import org.apache.camel.Ordered;
 import org.apache.camel.Processor;
@@ -40,11 +41,14 @@ import org.apache.camel.model.ProcessorDefinitionHelper;
 import org.apache.camel.processor.interceptor.BacklogDebugger;
 import org.apache.camel.processor.interceptor.BacklogTracer;
 import org.apache.camel.processor.interceptor.DefaultBacklogTracerEventMessage;
+import org.apache.camel.spi.Contract;
+import org.apache.camel.spi.DataType;
 import org.apache.camel.spi.InflightRepository;
 import org.apache.camel.spi.MessageHistoryFactory;
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.spi.RoutePolicy;
 import org.apache.camel.spi.StreamCachingStrategy;
+import org.apache.camel.spi.Transformer;
 import org.apache.camel.spi.UnitOfWork;
 import org.apache.camel.util.MessageHelper;
 import org.apache.camel.util.OrderedComparator;
@@ -854,4 +858,120 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor {
         }
     }
 
+    /**
+     * Advice for data type contract
+     * TODO add declarative validation
+     */
+    public static class ContractAdvice implements CamelInternalProcessorAdvice {
+        private Contract contract;
+        
+        public ContractAdvice(Contract contract) {
+            this.contract = contract;
+        }
+        
+        @Override
+        public Object before(Exchange exchange) throws Exception {
+            DataType from = getCurrentType(exchange, Exchange.INPUT_TYPE);
+            DataType to = contract.getInputType();
+            if (to != null && !to.equals(from)) {
+                LOG.debug("Looking for transformer for INPUT: from='{}', to='{}'", from, to);
+                convertBody(exchange.getIn(), from, to);
+                exchange.setProperty(Exchange.INPUT_TYPE, to);
+            }
+            return null;
+        }
+        
+        @Override
+        public void after(Exchange exchange, Object data) throws Exception {
+            Message target = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
+            DataType from = getCurrentType(exchange, exchange.hasOut() ? Exchange.OUTPUT_TYPE : Exchange.INPUT_TYPE);
+            DataType to = contract.getOutputType();
+            if (to != null && !to.equals(from)) {
+                LOG.debug("Looking for transformer for OUTPUT: from='{}', to='{}'", from, to);
+                convertBody(target, from, to);
+                exchange.setProperty(exchange.hasOut() ? Exchange.OUTPUT_TYPE : Exchange.INPUT_TYPE, to);
+            }
+        }
+        
+        private static void convertBody(Message message, DataType from, DataType to) throws Exception {
+            CamelContext context = message.getExchange().getContext();
+            // transform into 'from' type before performing declared transformation
+            if (from != null && from.isJavaType() && from.getName() != null) {
+                Class<?> fromJava = getClazz(from.getName(), context);
+                if (!fromJava.isAssignableFrom(message.getBody().getClass())) {
+                    LOG.debug("Converting to '{}'", fromJava.getName());
+                    Object fromBody = message.getMandatoryBody(fromJava);
+                    message.setBody(fromBody);
+                }
+            }
+            
+            Transformer transformer = context.resolveTransformer(from, to);
+            if (transformer != null) {
+                // Applying exactly matched transformer. Java-Java transformer is also allowed.
+                LOG.debug("Applying transformer: from='{}', to='{}', transformer='{}'", from, to, transformer);
+                transformer.transform(message, from, to);
+                return;
+            } else if (from == null || from.isJavaType()) {
+                if (to.isJavaType() && to.getName() != null) {
+                    // Java->Java transformation just relies on TypeConverter if no declared transformer
+                    // TODO for better performance it may be better to add TypeConveterTransformer
+                    // into transformer registry to avoid unnecessary scan in transformer registry
+                    LOG.debug("Converting to '{}'", to.getName());
+                    Object answer = message.getMandatoryBody(getClazz(to.getName(), context));
+                    message.setBody(answer);
+                    return;
+                } else if (from == null) {
+                    // {undefined}->Other transformation - assuming it's already in expected shape
+                    return;
+                } else {
+                    // Java->Other transformation
+                    transformer = context.resolveTransformer(to.getModel());
+                    if (transformer != null) {
+                        LOG.debug("Applying transformer: from='{}', to='{}', transformer='{}'", from, to, transformer);
+                        transformer.transform(message, from, to);
+                        return;
+                    }
+                }
+            } else if (from != null) {
+                if (to.isJavaType()) {
+                    // Other->Java transformation
+                    transformer = context.resolveTransformer(from.getModel());
+                    if (transformer != null) {
+                        LOG.debug("Applying transformer: from='{}', to='{}', transformer='{}'", from, to, transformer);
+                        transformer.transform(message, from, to);
+                        return;
+                    }
+                } else {
+                    // Other->Other transformation - look for a transformer chain
+                    Transformer fromTransformer = context.resolveTransformer(from.getModel());
+                    Transformer toTransformer = context.resolveTransformer(to.getModel());
+                    if (fromTransformer != null && toTransformer != null) {
+                        LOG.debug("Applying transformer: from='{}', to='{}', transformer='{}'", from, to, transformer);
+                        fromTransformer.transform(message, from, new DataType(Object.class));
+                        LOG.debug("Applying transformer: from='{}', to='{}', transformer='{}'", from, to, transformer);
+                        toTransformer.transform(message, new DataType(Object.class), to);
+                        return;
+                    }
+                }
+            }
+            
+            throw new IllegalArgumentException("No Transformer found for [from='" + from + "', to='" + to + "']");
+        }
+        
+        private static Class<?> getClazz(String type, CamelContext context) throws Exception {
+            return context.getClassResolver().resolveMandatoryClass(type);
+        }
+        
+        private static DataType getCurrentType(Exchange exchange, String name) {
+            Object prop = exchange.getProperty(name);
+            if (prop instanceof DataType) {
+                return (DataType)prop;
+            } else if (prop instanceof String) {
+                DataType answer = new DataType((String)prop);
+                exchange.setProperty(name, answer);
+                return answer;
+            }
+            return null;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/spi/Contract.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/Contract.java b/camel-core/src/main/java/org/apache/camel/spi/Contract.java
new file mode 100644
index 0000000..0706023
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/spi/Contract.java
@@ -0,0 +1,112 @@
+/**
+ * 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.spi;
+
+import java.util.Map;
+import javax.xml.namespace.QName;
+
+/**
+ * A Contract which represents the input type and/or output type of the {@link Endpoint} or {@link Processor}.
+ */
+public class Contract {
+
+    private DataType inputType;
+    private DataType outputType;
+    private String contractString;
+    
+    public DataType getInputType() {
+        return inputType;
+    }
+    
+    /**
+     * Set the input data type.
+     * @param inputType input data type
+     */
+    public void setInputType(String inputType) {
+        this.inputType = new DataType(inputType);
+        this.contractString = null;
+    }
+    
+    /**
+     * Set the input data type with Java class.
+     * @param clazz Java class which represents input data type
+     */
+    public void setInputType(Class<?> clazz) {
+        this.inputType = new DataType(clazz);
+        this.contractString = null;
+    }
+    
+    public DataType getOutputType() {
+        return outputType;
+    }
+    
+   /**
+    * Set the output data type.
+    * @param outputType output data type
+    */
+    public void setOutputType(String outputType) {
+        this.outputType = new DataType(outputType);
+        this.contractString = null;
+    }
+    
+    /**
+     * Set the output data type with Java class.
+     * @param clazz Java class which represents output data type
+     */
+    public void setOutputType(Class<?> clazz) {
+        this.outputType = new DataType(clazz);
+        this.contractString = null;
+    }
+    
+    @Override
+    public String toString() {
+        if (contractString == null) {
+            this.contractString = "DataType[input=" + this.inputType + ", output=" + this.outputType + "]";
+        }
+        return contractString;
+    }
+
+    public boolean isEmpty() {
+        return inputType == null && outputType == null;
+    }
+
+    @Override
+    public boolean equals(Object target) {
+        if (!(target instanceof Contract)) {
+            return false;
+        }
+        Contract targetContract = (Contract)target;
+        if (getInputType() != null || targetContract.getInputType() != null) {
+            if (getInputType() == null || targetContract.getInputType() == null
+                || !getInputType().equals(targetContract.getInputType())) {
+                return false;
+            }
+        }
+        if (getOutputType() != null || targetContract.getOutputType() != null) {
+            if (getOutputType() == null || targetContract.getOutputType() == null
+                || !getOutputType().equals(targetContract.getOutputType())) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return toString().hashCode();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/spi/DataType.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/DataType.java b/camel-core/src/main/java/org/apache/camel/spi/DataType.java
new file mode 100644
index 0000000..3efae96
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/spi/DataType.java
@@ -0,0 +1,89 @@
+/**
+ * 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.spi;
+
+import org.apache.camel.util.StringHelper;
+
+/**
+ * Represents the data type URN which is used for message data type contract.
+ */
+public class DataType {
+
+    private String model;
+    private String name;
+    private boolean isJavaType;
+    private String typeString;
+    
+    public DataType(String urn) {
+        if (urn != null) {
+            String split[] = StringHelper.splitOnCharacter(urn, ":", 2);
+            model = split[0];
+            isJavaType = model.equals("java");
+            if (split.length > 1) {
+                name = split[1];
+            }
+        }
+    }
+    
+    public DataType(Class<?> clazz) {
+        model = "java";
+        isJavaType = true;
+        name = clazz.getName();
+    }
+    
+    public String getModel() {
+        return model;
+    }
+    
+    public String getName() {
+        return name;
+    }
+    
+    public boolean isJavaType() {
+        return isJavaType;
+    }
+
+    @Override
+    public String toString() {
+        if (this.typeString == null) {
+            this.typeString = model + ":" + name;
+        }
+        return this.typeString;
+    }
+
+    @Override
+    public boolean equals(Object target) {
+        if (target instanceof DataType) {
+            DataType targetdt = (DataType)target;
+            String targetModel = targetdt.getModel();
+            String targetName = targetdt.getName();
+            if (targetModel == null) {
+                return false;
+            } else if (targetName == null) {
+                return targetModel.equals(getModel()) && getName() == null;
+            } else {
+                return targetModel.equals(getModel()) && targetName.equals(getName());
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return toString().hashCode();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java b/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
index 54e6ad0..194f544 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/RouteContext.java
@@ -192,4 +192,9 @@ public interface RouteContext extends RuntimeConfiguration, EndpointAware {
      */
     int getAndIncrement(ProcessorDefinition<?> node);
 
+    /**
+     * 
+     * @param contract
+     */
+    void setContract(Contract contract);
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/java/org/apache/camel/spi/Transformer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/Transformer.java b/camel-core/src/main/java/org/apache/camel/spi/Transformer.java
new file mode 100644
index 0000000..adee678
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/spi/Transformer.java
@@ -0,0 +1,128 @@
+/**
+ * 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.spi;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.support.ServiceSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <a href="http://camel.apache.org/transformer.html">Transformer</a>
+ * represents Any to Any data transformation which leverages data format and endpoint
+ * under the cover.
+ */
+public abstract class Transformer extends ServiceSupport implements CamelContextAware {
+
+    private CamelContext camelContext;
+    private String model;
+    private DataType from;
+    private DataType to;
+
+    /**
+     * Perform data transformation with specified from/to type.
+     * @param message message to apply transformation
+     * @param from 'from' data type
+     * @param to 'to' data type
+     */
+    public abstract void transform(Message message, DataType from, DataType to) throws Exception;
+
+    /**
+     * Get a data model which is supported by this transformer.
+     * @return data model
+     */
+    public String getModel() {
+        return model;
+    };
+
+    /**
+     * Get 'from' data type.
+     * @return 'from' data type
+     */
+    public DataType getFrom() {
+        return from;
+    };
+
+    /**
+     * Get 'to' data type.
+     * @return 'to' data type
+     */
+    public DataType getTo() {
+        return to;
+    };
+
+    /**
+     * Set data model.
+     * @param model data model
+     * @return this Transformer instance
+     */
+    public Transformer setModel(String model) {
+        this.model = model;
+        return this;
+    }
+
+    /**
+     * Set 'from' data type.
+     * @param from 'from' data type
+     * @return this Transformer instance
+     */
+    public Transformer setFrom(String from) {
+        this.from = new DataType(from);
+        return this;
+    }
+
+    /**
+     * Set 'to' data type.
+     * @param to 'to' data type
+     * @return this Transformer instance
+     */
+    public Transformer setTo(String to) {
+        this.to = new DataType(to);
+        return this;
+    }
+
+    @Override
+    public CamelContext getCamelContext() {
+        return this.camelContext;
+    }
+
+    @Override
+    public void setCamelContext(CamelContext context) {
+        this.camelContext = context;
+    }
+
+    @Override
+    public String toString() {
+        return String.format("%s[model='%s', from='%s', to='%s']", this.getClass().getSimpleName(), from, to);
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        // no-op
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        // no-op
+    }
+}


[3/4] camel git commit: CAMEL-10447 Add contract based type awareness and transformer which leverages the type metadata

Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
index 9859736..aef22fa 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
@@ -35,6 +35,7 @@ HystrixConfigurationDefinition
 IdempotentConsumerDefinition
 InOnlyDefinition
 InOutDefinition
+InputTypeDefinition
 InterceptDefinition
 InterceptFromDefinition
 InterceptSendToEndpointDefinition
@@ -51,6 +52,7 @@ OnFallbackDefinition
 OptimisticLockRetryPolicyDefinition
 OptionalIdentifiedDefinition
 OtherwiseDefinition
+OutputTypeDefinition
 PackageScanDefinition
 PipelineDefinition
 PolicyDefinition

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/main/resources/org/apache/camel/model/transformer/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/transformer/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/transformer/jaxb.index
new file mode 100644
index 0000000..24e0f2b
--- /dev/null
+++ b/camel-core/src/main/resources/org/apache/camel/model/transformer/jaxb.index
@@ -0,0 +1,21 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+CustomTransformerDefinition
+DataFormatTransformerDefinition
+EndpointTransformerDefinition
+TransformerDefinition
+TransformersDefinition

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/test/java/org/apache/camel/impl/transformer/TransformerContractTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/transformer/TransformerContractTest.java b/camel-core/src/test/java/org/apache/camel/impl/transformer/TransformerContractTest.java
new file mode 100644
index 0000000..263afd1
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/impl/transformer/TransformerContractTest.java
@@ -0,0 +1,173 @@
+/**
+ * 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.impl.transformer;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.TypeConverters;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.model.DataFormatDefinition;
+import org.apache.camel.model.dataformat.JaxbDataFormat;
+import org.apache.camel.model.transformer.DataFormatTransformerDefinition;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.RouteContext;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TransformerContractTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testInputTypeOnly() throws Exception {
+        context.getTypeConverterRegistry().addTypeConverters(new MyTypeConverters());
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:a")
+                    .inputType(A.class)
+                    .to("mock:a");
+            }
+        });
+        context.start();
+        
+        MockEndpoint mock = context.getEndpoint("mock:a", MockEndpoint.class);
+        mock.setExpectedCount(1);
+        Object answer = template.requestBody("direct:a", "foo");
+        mock.assertIsSatisfied();
+        Exchange ex = mock.getExchanges().get(0);
+        assertEquals(A.class, ex.getIn().getBody().getClass());
+        assertEquals(A.class, answer.getClass());
+    }
+
+    @Test
+    public void testOutputTypeOnly() throws Exception {
+        context.getTypeConverterRegistry().addTypeConverters(new MyTypeConverters());
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:a")
+                    .outputType(A.class)
+                    .to("mock:a");
+            }
+        });
+        context.start();
+        
+        MockEndpoint mock = context.getEndpoint("mock:a", MockEndpoint.class);
+        mock.setExpectedCount(1);
+        Object answer = template.requestBody("direct:a", "foo");
+        mock.assertIsSatisfied();
+        Exchange ex = mock.getExchanges().get(0);
+        assertEquals("foo", ex.getIn().getBody());
+        assertEquals(A.class, answer.getClass());
+    }
+
+    @Test
+    public void testScheme() throws Exception {
+        DataFormatTransformerDefinition transformerDef = new DataFormatTransformerDefinition();
+        transformerDef.setScheme("xml");
+        transformerDef.setDataFormatType(new MyDataFormatDefinition());
+        context.getTransformers().add(transformerDef);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:a")
+                    .inputType("xml")
+                    .outputType("xml")
+                    .to("mock:a")
+                    .to("direct:b")
+                    .to("mock:a2");
+                from("direct:b")
+                    .inputType("java")
+                    .outputType("java")
+                    .to("mock:b")
+                    .process(ex -> {
+                        ex.getIn().setBody(new B());
+                    });
+            }
+        });
+        context.start();
+        
+        MockEndpoint mocka = context.getEndpoint("mock:a", MockEndpoint.class);
+        MockEndpoint mocka2 = context.getEndpoint("mock:a2", MockEndpoint.class);
+        MockEndpoint mockb = context.getEndpoint("mock:b", MockEndpoint.class);
+        mocka.setExpectedCount(1);
+        mocka2.setExpectedCount(1);
+        mockb.setExpectedCount(1);
+        Object answer = template.requestBody("direct:a", "<foo/>");
+        mocka.assertIsSatisfied();
+        mocka2.assertIsSatisfied();
+        mockb.assertIsSatisfied();
+        Exchange exa = mocka.getExchanges().get(0);
+        Exchange exa2 = mocka2.getExchanges().get(0);
+        Exchange exb = mockb.getExchanges().get(0);
+        assertEquals("<foo/>", exa.getIn().getBody());
+        assertEquals(A.class, exb.getIn().getBody().getClass());
+        assertEquals(B.class, exa2.getIn().getBody().getClass());
+        assertEquals("<fooResponse/>", new String((byte[])answer));
+    }
+
+    public static class MyTypeConverters implements TypeConverters {
+        @Converter
+        public A toA(String in) {
+            return new A();
+        }
+    }
+
+    public static class MyDataFormatDefinition extends DataFormatDefinition {
+        public static DataFormat getDataFormat(RouteContext routeContext, DataFormatDefinition type, String ref) {
+            return new MyDataFormatDefinition().createDataFormat();
+        }
+        public DataFormat getDataFormat(RouteContext routeContext) {
+            return createDataFormat();
+        }
+        private DataFormat createDataFormat() {
+            return new DataFormat() {
+                @Override
+                public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
+                    assertEquals(B.class, graph.getClass());
+                    PrintWriter pw = new PrintWriter(new OutputStreamWriter(stream));
+                    pw.print("<fooResponse/>");
+                    pw.close();
+                }
+                @Override
+                public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
+                    BufferedReader br = new BufferedReader(new InputStreamReader(stream));
+                    assertEquals("<foo/>", br.readLine());
+                    return new A();
+                }
+            };
+        }
+    }
+
+    public static class A { }
+    public static class B { }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/camel-core/src/test/java/org/apache/camel/impl/transformer/TransformerRouteTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/transformer/TransformerRouteTest.java b/camel-core/src/test/java/org/apache/camel/impl/transformer/TransformerRouteTest.java
new file mode 100644
index 0000000..29bd215
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/impl/transformer/TransformerRouteTest.java
@@ -0,0 +1,349 @@
+/**
+ * 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.impl.transformer;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.util.Map;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.Consumer;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Converter;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.TypeConverters;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultAsyncProducer;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.model.DataFormatDefinition;
+import org.apache.camel.model.transformer.CustomTransformerDefinition;
+import org.apache.camel.model.transformer.DataFormatTransformerDefinition;
+import org.apache.camel.model.transformer.EndpointTransformerDefinition;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.DataType;
+import org.apache.camel.spi.RouteContext;
+import org.apache.camel.spi.Transformer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A TransformerTest demonstrates contract based declarative transformation via Java DSL.
+ */
+public class TransformerRouteTest extends ContextTestSupport {
+
+    protected static final Logger LOG = LoggerFactory.getLogger(TransformerRouteTest.class);
+
+    public void testJavaTransformer() throws Exception {
+        MockEndpoint abcresult = getMockEndpoint("mock:abcresult");
+        abcresult.expectedMessageCount(1);
+        abcresult.whenAnyExchangeReceived(new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                LOG.info("Asserting String -> XOrderResponse convertion");
+                assertEquals(XOrderResponse.class, exchange.getIn().getBody().getClass());
+            }
+            
+        });
+
+        MockEndpoint xyzresult = getMockEndpoint("mock:xyzresult");
+        xyzresult.expectedMessageCount(1);
+        xyzresult.whenAnyExchangeReceived(new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                LOG.info("Asserting String -> XOrderResponse convertion is not yet performed");
+                assertEquals("response", exchange.getIn().getBody());
+            }
+        });
+
+        Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
+        exchange.getIn().setBody(new AOrder());
+        Exchange answerEx = template.send("direct:abc", exchange);
+        if (answerEx.getException() != null) {
+            throw answerEx.getException();
+        }
+        assertEquals(AOrderResponse.class, answerEx.getOut().getBody().getClass());
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testDataFormatTransformer() throws Exception {
+        MockEndpoint xyzresult = getMockEndpoint("mock:xyzresult");
+        xyzresult.expectedMessageCount(1);
+        xyzresult.whenAnyExchangeReceived(new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                LOG.info("Asserting String -> XOrderResponse convertion is not yet performed");
+                assertEquals("response", exchange.getIn().getBody());
+            }
+        });
+
+        Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
+        exchange.getIn().setBody("{name:XOrder}");
+        Exchange answerEx = template.send("direct:dataFormat", exchange);
+        if (answerEx.getException() != null) {
+            throw answerEx.getException();
+        }
+        assertEquals("{name:XOrderResponse}", answerEx.getOut().getBody(String.class));
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testEndpointTransformer() throws Exception {
+        MockEndpoint xyzresult = getMockEndpoint("mock:xyzresult");
+        xyzresult.expectedMessageCount(1);
+        xyzresult.whenAnyExchangeReceived(new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                LOG.info("Asserting String -> XOrderResponse convertion is not yet performed");
+                assertEquals("response", exchange.getIn().getBody());
+            }
+        });
+
+        Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
+        exchange.getIn().setBody("<XOrder/>");
+        Exchange answerEx = template.send("direct:endpoint", exchange);
+        if (answerEx.getException() != null) {
+            throw answerEx.getException();
+        }
+        assertEquals("<XOrderResponse/>", answerEx.getOut().getBody(String.class));
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testCustomTransformer() throws Exception {
+        MockEndpoint xyzresult = getMockEndpoint("mock:xyzresult");
+        xyzresult.expectedMessageCount(1);
+        xyzresult.whenAnyExchangeReceived(new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                LOG.info("Asserting String -> XOrderResponse convertion is not yet performed");
+                assertEquals("response", exchange.getIn().getBody());
+            }
+        });
+
+        Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);
+        exchange.getIn().setBody("name=XOrder");
+        Exchange answerEx = template.send("direct:custom", exchange);
+        if (answerEx.getException() != null) {
+            throw answerEx.getException();
+        }
+        assertEquals("name=XOrderResponse", answerEx.getOut().getBody(String.class));
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.getTypeConverterRegistry().addTypeConverters(new MyTypeConverters());
+                from("direct:abc")
+                    .inputType(AOrder.class)
+                    .outputType(AOrderResponse.class)
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            LOG.info("Asserting input -> AOrder convertion");
+                            assertEquals(AOrder.class, exchange.getIn().getBody().getClass());
+                        }
+                    })
+                    .inOut("direct:xyz")
+                    .to("mock:abcresult");
+
+                from("direct:xyz")
+                    .inputType(XOrder.class)
+                    .outputType(XOrderResponse.class)
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            LOG.info("Asserting input -> XOrder convertion");
+                            assertEquals(XOrder.class, exchange.getIn().getBody().getClass());
+                            exchange.getIn().setBody("response");
+                        }
+                    }).to("mock:xyzresult");
+                
+                DataFormatTransformerDefinition dfdef = new DataFormatTransformerDefinition();
+                dfdef.setDataFormatType(new MyJsonDataFormatDefinition());
+                dfdef.setScheme("json");
+                context.getTransformers().add(dfdef);
+                from("direct:dataFormat")
+                    .inputType("json:JsonXOrder")
+                    .outputType("json:JsonXOrderResponse")
+                    .inOut("direct:xyz");
+                
+                context.addComponent("myxml", new MyXmlComponent());
+                EndpointTransformerDefinition edef1 = new EndpointTransformerDefinition();
+                edef1.setUri("myxml:endpoint");
+                edef1.setFrom("xml:XmlXOrder");
+                edef1.setTo(XOrder.class);
+                EndpointTransformerDefinition edef2 = new EndpointTransformerDefinition();
+                edef2.setUri("myxml:endpoint");
+                edef2.setFrom(XOrderResponse.class);
+                edef2.setTo("xml:XmlXOrderResponse");
+                context.getTransformers().add(edef1);
+                context.getTransformers().add(edef2);
+                from("direct:endpoint")
+                    .inputType("xml:XmlXOrder")
+                    .outputType("xml:XmlXOrderResponse")
+                    .inOut("direct:xyz");
+                
+                CustomTransformerDefinition bdef1 = new CustomTransformerDefinition();
+                bdef1.setType(OtherToXOrderTransformer.class.getName());
+                bdef1.setFrom("other:OtherXOrder");
+                bdef1.setTo(XOrder.class);
+                CustomTransformerDefinition bdef2 = new CustomTransformerDefinition();
+                bdef2.setType(XOrderResponseToOtherTransformer.class.getName());
+                bdef2.setFrom(XOrderResponse.class);
+                bdef2.setTo("other:OtherXOrderResponse");
+                context.getTransformers().add(bdef1);
+                context.getTransformers().add(bdef2);
+                from("direct:custom")
+                    .inputType("other:OtherXOrder")
+                    .outputType("other:OtherXOrderResponse")
+                    .inOut("direct:xyz");
+            }
+        };
+    }
+
+    public static class MyTypeConverters implements TypeConverters {
+        @Converter
+        public AOrder toAOrder(String order) {
+            LOG.info("TypeConverter: String -> AOrder");
+            return new AOrder();
+        }
+        
+        @Converter
+        public XOrder toXOrder(AOrder aorder) {
+            LOG.info("TypeConverter: AOrder -> XOrder");
+            return new XOrder();
+        }
+        
+        @Converter
+        public XOrderResponse toXOrderResponse(String res) {
+            LOG.info("TypeConverter: String -> XOrderResponse");
+            return new XOrderResponse();
+        }
+        
+        @Converter
+        public AOrderResponse toAOrderResponse(XOrderResponse xres) {
+            LOG.info("TypeConverter: XOrderResponse -> AOrderResponse");
+            return new AOrderResponse();
+        }
+    }
+
+    public static class MyJsonDataFormatDefinition extends DataFormatDefinition {
+        public static DataFormat getDataFormat(RouteContext routeContext, DataFormatDefinition type, String ref) {
+            return new MyJsonDataFormatDefinition().createDataFormat();
+        }
+        public DataFormat getDataFormat(RouteContext routeContext) {
+            return createDataFormat();
+        }
+        private DataFormat createDataFormat() {
+            return new DataFormat() {
+                @Override
+                public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
+                    assertEquals(graph.toString(), XOrderResponse.class, graph.getClass());
+                    LOG.info("DataFormat: XOrderResponse -> JSON");
+                    stream.write("{name:XOrderResponse}".getBytes());
+                }
+                @Override
+                public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
+                    BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
+                    String line = "";
+                    String input = "";
+                    while ((line = reader.readLine()) != null) {
+                        input += line;
+                    }
+                    reader.close();
+                    assertEquals("{name:XOrder}", input);
+                    LOG.info("DataFormat: JSON -> XOrder");
+                    return new XOrder();
+                }
+            };
+        }
+    }
+    
+    public static class MyXmlComponent extends DefaultComponent {
+        @Override
+        protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+            return new MyXmlEndpoint();
+        }
+        
+    }
+    
+    public static class MyXmlEndpoint extends DefaultEndpoint {
+        @Override
+        public Producer createProducer() throws Exception {
+            return new DefaultAsyncProducer(this) {
+                @Override
+                public boolean process(Exchange exchange, AsyncCallback callback) {
+                    Object input = exchange.getIn().getBody();
+                    if (input instanceof XOrderResponse) {
+                        LOG.info("Endpoint: XOrderResponse -> XML");
+                        exchange.getIn().setBody("<XOrderResponse/>");
+                    } else {
+                        assertEquals("<XOrder/>", input);
+                        LOG.info("Endpoint: XML -> XOrder");
+                        exchange.getIn().setBody(new XOrder());
+                        
+                    }
+                    callback.done(true);
+                    return true;
+                }
+            };
+        }
+        @Override
+        public Consumer createConsumer(Processor processor) throws Exception {
+            return null;
+        }
+        @Override
+        public boolean isSingleton() {
+            return false;
+        }
+        @Override
+        protected String createEndpointUri() {
+            return "myxml:endpoint";
+        }
+    }
+    
+    public static class OtherToXOrderTransformer extends Transformer {
+        @Override
+        public void transform(Message message, DataType from, DataType to) throws Exception {
+            assertEquals("name=XOrder", message.getBody());
+            LOG.info("Bean: Other -> XOrder");
+            message.setBody(new XOrder());
+        }
+    }
+    
+    public static class XOrderResponseToOtherTransformer extends Transformer {
+        @Override
+        public void transform(Message message, DataType from, DataType to) throws Exception {
+            LOG.info("Bean: XOrderResponse -> Other");
+            message.setBody("name=XOrderResponse");
+        }
+    }
+    
+    public static class AOrder { }
+    public static class AOrderResponse { }
+    public static class XOrder { }
+    public static class XOrderResponse { }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
index 6802312..59e9f38 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
@@ -65,6 +65,7 @@ import org.apache.camel.model.remote.KubernetesConfigurationDefinition;
 import org.apache.camel.model.remote.RibbonConfigurationDefinition;
 import org.apache.camel.model.rest.RestConfigurationDefinition;
 import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.model.transformer.TransformersDefinition;
 import org.apache.camel.spi.PackageScanFilter;
 import org.apache.camel.spi.Registry;
 import org.osgi.framework.BundleContext;
@@ -173,6 +174,8 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu
     private List<CamelEndpointFactoryBean> endpoints;
     @XmlElement(name = "dataFormats")
     private DataFormatsDefinition dataFormats;
+    @XmlElement(name = "transformers")
+    private TransformersDefinition transformers;
     @XmlElement(name = "redeliveryPolicyProfile")
     private List<CamelRedeliveryPolicyFactoryBean> redeliveryPolicies;
     @XmlElement(name = "onException")
@@ -645,6 +648,14 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu
         this.dataFormats = dataFormats;
     }
 
+    public void setTransformers(TransformersDefinition transformers) {
+        this.transformers = transformers;
+    }
+
+    public TransformersDefinition getTransformers() {
+        return transformers;
+    }
+
     public List<OnExceptionDefinition> getOnExceptions() {
         return onExceptions;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/CamelContextFactoryBean.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/CamelContextFactoryBean.java
index c75d30b..9299424 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/CamelContextFactoryBean.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/CamelContextFactoryBean.java
@@ -60,6 +60,7 @@ import org.apache.camel.model.ThreadPoolProfileDefinition;
 import org.apache.camel.model.dataformat.DataFormatsDefinition;
 import org.apache.camel.model.rest.RestConfigurationDefinition;
 import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.model.transformer.TransformersDefinition;
 import org.apache.camel.spi.PackageScanFilter;
 
 @XmlRootElement(name = "camelContext")
@@ -189,6 +190,9 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Def
     @XmlElement(name = "dataFormats")
     private DataFormatsDefinition dataFormats;
 
+    @XmlElement(name = "transformers")
+    private TransformersDefinition transformers;
+
     @XmlElement(name = "redeliveryPolicyProfile")
     private List<RedeliveryPolicyFactoryBean> redeliveryPolicies;
 
@@ -639,6 +643,14 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Def
         this.dataFormats = dataFormats;
     }
 
+    public TransformersDefinition getTransformers() {
+        return transformers;
+    }
+
+    public void setTransformers(TransformersDefinition transformers) {
+        this.transformers = transformers;
+    }
+
     public List<OnExceptionDefinition> getOnExceptions() {
         return onExceptions;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index fe5b826..a4bb342 100644
--- a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++ b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -70,6 +70,7 @@ import org.apache.camel.model.dataformat.DataFormatsDefinition;
 import org.apache.camel.model.rest.RestConfigurationDefinition;
 import org.apache.camel.model.rest.RestContainer;
 import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.model.transformer.TransformersDefinition;
 import org.apache.camel.processor.interceptor.BacklogTracer;
 import org.apache.camel.processor.interceptor.HandleFault;
 import org.apache.camel.processor.interceptor.TraceFormatter;
@@ -760,6 +761,8 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
 
     public abstract DataFormatsDefinition getDataFormats();
 
+    public abstract TransformersDefinition getTransformers();
+
     public abstract List<OnExceptionDefinition> getOnExceptions();
 
     public abstract List<OnCompletionDefinition> getOnCompletions();
@@ -833,6 +836,9 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
         if (getDataFormats() != null) {
             ctx.setDataFormats(getDataFormats().asMap());
         }
+        if (getTransformers() != null) {
+            ctx.setTransformers(getTransformers().getTransforms());
+        }
         if (getTypeConverterStatisticsEnabled() != null) {
             ctx.setTypeConverterStatisticsEnabled(getTypeConverterStatisticsEnabled());
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
index 651f280..9e11f6c 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
@@ -64,6 +64,7 @@ import org.apache.camel.model.remote.KubernetesConfigurationDefinition;
 import org.apache.camel.model.remote.RibbonConfigurationDefinition;
 import org.apache.camel.model.rest.RestConfigurationDefinition;
 import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.model.transformer.TransformersDefinition;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.PackageScanFilter;
 import org.apache.camel.spi.Registry;
@@ -182,6 +183,8 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
     private List<CamelEndpointFactoryBean> endpoints;
     @XmlElement(name = "dataFormats")
     private DataFormatsDefinition dataFormats;
+    @XmlElement(name = "transformers")
+    private TransformersDefinition transformers;
     @XmlElement(name = "redeliveryPolicyProfile")
     private List<CamelRedeliveryPolicyFactoryBean> redeliveryPolicies;
     @XmlElement(name = "onException")
@@ -875,6 +878,17 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
     }
 
     /**
+     * Configuration of transformers.
+     */
+    public void setTransformers(TransformersDefinition transformers) {
+        this.transformers = transformers;
+    }
+
+    public TransformersDefinition getTransformers() {
+        return transformers;
+    }
+
+    /**
      * Configuration of redelivery settings.
      */
     public void setRedeliveryPolicies(List<CamelRedeliveryPolicyFactoryBean> redeliveryPolicies) {

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
index 945c2e9..68ae70d 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
@@ -393,6 +393,7 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
                 builder.addPropertyValue("interceptFroms", factoryBean.getInterceptFroms());
                 builder.addPropertyValue("interceptSendToEndpoints", factoryBean.getInterceptSendToEndpoints());
                 builder.addPropertyValue("dataFormats", factoryBean.getDataFormats());
+                builder.addPropertyValue("transformers", factoryBean.getTransformers());
                 builder.addPropertyValue("onCompletions", factoryBean.getOnCompletions());
                 builder.addPropertyValue("onExceptions", factoryBean.getOnExceptions());
                 builder.addPropertyValue("builderRefs", factoryBean.getBuilderRefs());

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/components/camel-spring/src/test/java/org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.java
new file mode 100644
index 0000000..b075c59
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.java
@@ -0,0 +1,48 @@
+/**
+ * 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.spring.impl.transformer;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.transformer.TransformerRouteTest;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+/**
+ * A TransformerTest demonstrates contract based declarative transformation via Spring DSL.
+ */
+public class SpringTransformerRouteTest extends TransformerRouteTest {
+
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, "org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.xml");
+    }
+
+    public static class MyXmlProcessor implements Processor {
+        public void process(Exchange exchange) {
+            Object input = exchange.getIn().getBody();
+            if (input instanceof XOrderResponse) {
+                LOG.info("Endpoint: XOrderResponse -> XML");
+                exchange.getIn().setBody("<XOrderResponse/>");
+            } else {
+                assertEquals("<XOrder/>", input);
+                LOG.info("Endpoint: XML -> XOrder");
+                exchange.getIn().setBody(new XOrder());
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.xml
new file mode 100644
index 0000000..d8b4f72
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/transformer/SpringTransformerRouteTest.xml
@@ -0,0 +1,97 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       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
+    ">
+
+    <bean id="myTypeConverters" class="org.apache.camel.impl.transformer.TransformerRouteTest$MyTypeConverters"/>
+    <bean id="myJsonDataFormatDef" class="org.apache.camel.impl.transformer.TransformerRouteTest$MyJsonDataFormatDefinition"/>
+    <bean id="myXmlProcessor" class="org.apache.camel.spring.impl.transformer.SpringTransformerRouteTest$MyXmlProcessor"/>
+    <bean id="otherToXOrder" class="org.apache.camel.impl.transformer.TransformerRouteTest$OtherToXOrderTransformer"/>
+    <bean id="xOrderResponseToOther" class="org.apache.camel.impl.transformer.TransformerRouteTest$XOrderResponseToOtherTransformer"/>
+    
+    <camelContext xmlns="http://camel.apache.org/schema/spring">
+    
+        <endpoint id="myXmlEndpoint" uri="direct:endpointXmlTransformer"/>
+        
+        <transformers>
+            <dataFormatTransformer scheme="json">
+                <custom ref="myJsonDataFormatDef"/>
+            </dataFormatTransformer>
+            <endpointTransformer ref="myXmlEndpoint" from="xml:XmlXOrder" to="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrder"/>
+            <endpointTransformer ref="myXmlEndpoint" from="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrderResponse" to="xml:XmlXOrderResponse"/>
+            <customTransformer ref="otherToXOrder" from="other:OtherXOrder" to="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrder"/>
+            <customTransformer ref="xOrderResponseToOther" from="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrderResponse" to="other:OtherXOrderResponse"/>
+        </transformers>
+        
+        <route>
+            <from uri="direct:abc"/>
+            <inputType urn="java:org.apache.camel.impl.transformer.TransformerRouteTest$AOrder"/>
+            <outputType urn="java:org.apache.camel.impl.transformer.TransformerRouteTest$AOrderResponse"/>
+            <when>
+                <simple>${body} not is 'org.apache.camel.impl.transformer.TransformerRouteTest\\$AOrder'</simple>
+                <throwException exceptionType="java.lang.Exception" message="expected AOrder object but was '${body}'"/>
+            </when>
+            <inOut uri="direct:xyz"/>
+            <to uri="mock:abcresult"/>
+        </route>
+
+        <route>
+            <from uri="direct:xyz"/>
+            <inputType urn="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrder"/>
+            <outputType urn="java:org.apache.camel.impl.transformer.TransformerRouteTest$XOrderResponse"/>
+            <when>
+                <simple>${body} not is 'org.apache.camel.impl.transformer.TransformerRouteTest\\$XOrder'</simple>
+                <throwException exceptionType="java.lang.Exception" message="expected XOrder object but was '${body}'"/>
+            </when>
+            <setBody><constant>response</constant></setBody>
+            <to uri="mock:xyzresult"/>
+        </route>
+        
+        <route>
+            <from uri="direct:dataFormat"/>
+            <inputType urn="json:JsonXOrder"/>
+            <outputType urn="json:JsonXOrderResponse"/>
+            <inOut uri="direct:xyz"/>
+        </route>
+        
+        <route>
+            <from uri="direct:endpoint"/>
+            <inputType urn="xml:XmlXOrder"/>
+            <outputType urn="xml:XmlXOrderResponse"/>
+            <inOut uri="direct:xyz"/>
+        </route>
+        
+        <route>
+            <from uri="direct:endpointXmlTransformer"/>
+            <process ref="myXmlProcessor"/>
+        </route>
+        
+        <route>
+            <from uri="direct:custom"/>
+            <inputType urn="other:OtherXOrder"/>
+            <outputType urn="other:OtherXOrderResponse"/>
+            <inOut uri="direct:xyz"/>
+        </route>
+        
+    </camelContext>
+  
+</beans>

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/README.md
----------------------------------------------------------------------
diff --git a/examples/README.md b/examples/README.md
index 923e6b7..1e3d97d 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -119,6 +119,11 @@ All examples have been sort by type/category
 * [camel-example-cxf-proxy](camel-example-cxf-proxy/README.md)
 * [camel-example-cxf-tomcat](camel-example-cxf-tomcat/README.md)
 
+##### Input/Output type contract
+* [camel-example-transformer-blueprint](camel-example-transformer-blueprint/README.md)
+* [camel-example-transformer-cdi](camel-example-transformer-cdi/README.md)
+* [camel-example-transformer-demo](camel-example-transformer-demo/README.md)
+
 ### Documentation
 
 They are described in detail here <http://camel.apache.org/examples.html>

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-blueprint/README.md
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-blueprint/README.md b/examples/camel-example-transformer-blueprint/README.md
new file mode 100644
index 0000000..9907c9c
--- /dev/null
+++ b/examples/camel-example-transformer-blueprint/README.md
@@ -0,0 +1,51 @@
+# Declarative Transformer example using Blueprint XML
+
+
+### Introduction
+
+This example shows how to work with declarative transformation by declaring data types.
+
+### Build
+
+You will need to compile this example first:
+
+	mvn compile
+
+### Run without container
+
+To run the example, type
+
+	mvn camel:run
+
+To stop the example hit <kbd>ctrl</kbd>+<kbd>c</kbd>.
+
+### Run on karaf container
+
+To run the example on the karaf container
+
+#### Step 1: Start karaf container
+
+    karaf / karaf.bat
+
+#### Step 2: Deploy
+
+    feature:repo-add feature:repo-add mvn:org.apache.camel/camel-example-transformer-blueprint/${version}/xml/features
+    feature:install camel-example-transformer-blueprint
+
+#### Step 3: Check the output
+
+You will see the output in ${karaf}/data/karaf.log
+
+You can see the routing rules by looking at the Blueprint XML configuration lives in
+`src/main/resources/OSGI-INF/blueprint`
+
+### Forum, Help, etc
+
+If you hit an problems please let us know on the Camel Forums
+	<http://camel.apache.org/discussion-forums.html>
+
+Please help us make Apache Camel better - we appreciate any feedback you may
+have.  Enjoy!
+
+
+The Camel riders!

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-blueprint/pom.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-blueprint/pom.xml b/examples/camel-example-transformer-blueprint/pom.xml
new file mode 100644
index 0000000..7a5df6d
--- /dev/null
+++ b/examples/camel-example-transformer-blueprint/pom.xml
@@ -0,0 +1,121 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>examples</artifactId>
+    <version>2.19.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-example-transformer-blueprint</artifactId>
+  <packaging>bundle</packaging>
+  <name>Camel :: Example :: Transformer :: Blueprint</name>
+  <description>An example demonstrating declarative transformation along data type declaration using Blueprint DSL
+  </description>
+
+  <dependencies>
+    <!-- START SNIPPET: e1 -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-blueprint</artifactId>
+    </dependency>
+    
+    <!-- logging -->
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-slf4j-impl</artifactId>
+    </dependency>
+
+    <!-- for testing -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test-blueprint</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+        <groupId>xmlunit</groupId>
+        <artifactId>xmlunit</artifactId>
+        <scope>test</scope>
+        <version>1.6</version>
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-artifacts</id>
+            <phase>package</phase>
+            <goals>
+              <goal>attach-artifact</goal>
+            </goals>
+            <configuration>
+              <artifacts>
+                <artifact>
+                  <file>target/classes/features.xml</file>
+                  <type>xml</type>
+                  <classifier>features</classifier>
+                </artifact>
+              </artifacts>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
+            <Export-Package>${camel.osgi.export.pkg}</Export-Package>
+            <Import-Package>*</Import-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+
+      <!-- Allows the routes to be run via 'mvn camel:run' -->
+      <plugin>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-maven-plugin</artifactId>
+        <version>${project.version}</version>
+      </plugin>
+
+    </plugins>
+  </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-blueprint/src/main/resources/OSGI-INF/blueprint/camel-context.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-blueprint/src/main/resources/OSGI-INF/blueprint/camel-context.xml b/examples/camel-example-transformer-blueprint/src/main/resources/OSGI-INF/blueprint/camel-context.xml
new file mode 100644
index 0000000..67e3373
--- /dev/null
+++ b/examples/camel-example-transformer-blueprint/src/main/resources/OSGI-INF/blueprint/camel-context.xml
@@ -0,0 +1,53 @@
+<?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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+  <camelContext id="TransformerBlueprint" xmlns="http://camel.apache.org/schema/blueprint">
+
+    <!-- START SNIPPET: e1 -->
+    <transformers>
+        <endpointTransformer uri="xslt:transform.xsl" from="xml:MyRequest" to="xml:MyResponse"/>
+    </transformers>
+    <!-- END SNIPPET: e1 -->
+
+    <!-- START SNIPPET: e2 -->
+    <route id="timer-route">
+      <from uri="timer:foo?period=5s"/>
+      <log message="start --&gt;"/>
+      <setBody><constant>&lt;MyRequest&gt;foobar&lt;/MyRequest&gt;</constant></setBody>
+      <log message="--&gt; Sending:[${body}]"/>
+      <to uri="direct:a"/>
+      <log message="--&gt; Received:[${body}]"/>
+      <log message="&lt;-- end"/>
+    </route>
+    <!-- END SNIPPET: e2 -->
+
+    <!-- START SNIPPET: e3 -->
+    <route id="xslt-route">
+      <from uri="direct:a"/>
+      <inputType urn="xml:MyRequest"/>
+      <outputType urn="xml:MyResponse"/>
+      <log message="----&gt; Received:[${body}]"/>
+    </route>
+    <!-- END SNIPPET: e3 -->
+
+  </camelContext>
+  
+</blueprint>

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-blueprint/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-blueprint/src/main/resources/features.xml b/examples/camel-example-transformer-blueprint/src/main/resources/features.xml
new file mode 100644
index 0000000..92c60b3
--- /dev/null
+++ b/examples/camel-example-transformer-blueprint/src/main/resources/features.xml
@@ -0,0 +1,29 @@
+<?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.
+-->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0" name="camel-example-transformer-blueprint">
+    <repository>mvn:org.apache.camel.karaf/apache-camel/${project.version}/xml/features</repository>
+    
+    <feature name='camel-example-transformer-blueprint' version='${project.version}'>
+        <feature version="${project.version}">camel</feature>
+        <feature version="${project.version}">camel-blueprint</feature>
+        <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.xalan/${xalan-bundle-version}</bundle>
+        <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.bcel/${bcel-bundle-version}</bundle>
+        <bundle>mvn:org.apache.camel/camel-example-transformer-blueprint/${project.version}</bundle>
+    </feature>
+
+</features>

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-blueprint/src/main/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-blueprint/src/main/resources/log4j2.properties b/examples/camel-example-transformer-blueprint/src/main/resources/log4j2.properties
new file mode 100644
index 0000000..a1e0d92
--- /dev/null
+++ b/examples/camel-example-transformer-blueprint/src/main/resources/log4j2.properties
@@ -0,0 +1,28 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+appender.stdout.type = Console
+appender.stdout.name = stdout
+appender.stdout.layout.type = PatternLayout
+appender.stdout.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+rootLogger.level = INFO
+rootLogger.appenderRef.stdout.ref = stdout
+
+#logger.transformer.name = org.apache.camel.impl.transformer
+#logger.transformer.level = DEBUG
+#logger.processor.name = org.apache.camel.processor
+#logger.processor.level = DEBUG

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-blueprint/src/main/resources/transform.xsl
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-blueprint/src/main/resources/transform.xsl b/examples/camel-example-transformer-blueprint/src/main/resources/transform.xsl
new file mode 100644
index 0000000..2f2e514
--- /dev/null
+++ b/examples/camel-example-transformer-blueprint/src/main/resources/transform.xsl
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="Shift_JIS"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+    <xsl:template match="@*|node()">
+        <xsl:copy>
+            <xsl:apply-templates select="@*|node()"/>
+        </xsl:copy>
+    </xsl:template>
+
+    <xsl:template match="MyRequest">
+        <MyResponse>
+            <xsl:apply-templates/>
+        </MyResponse>
+    </xsl:template>
+</xsl:stylesheet>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-cdi/README.md
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-cdi/README.md b/examples/camel-example-transformer-cdi/README.md
new file mode 100644
index 0000000..2f47539
--- /dev/null
+++ b/examples/camel-example-transformer-cdi/README.md
@@ -0,0 +1,37 @@
+# Declarative Transformer example using CDI
+
+
+### Introduction
+
+This example shows how to work with declarative transformation by declaring data types.
+
+### Build
+
+You will need to compile this example first:
+
+	mvn compile
+
+### Run
+
+To run the example type
+
+	mvn camel:run
+
+You can see the routing rules by looking at the java code in the
+`src/main/java` directory.
+
+To stop the example hit <kbd>ctrl</kbd>+<kbd>c</kbd>.
+
+When we launch the example using the Camel Maven plugin, a standalone CDI container
+is created and started.
+
+### Forum, Help, etc
+
+If you hit an problems please let us know on the Camel Forums
+	<http://camel.apache.org/discussion-forums.html>
+
+Please help us make Apache Camel better - we appreciate any feedback you may
+have.  Enjoy!
+
+
+The Camel riders!

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-cdi/pom.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-cdi/pom.xml b/examples/camel-example-transformer-cdi/pom.xml
new file mode 100644
index 0000000..10c178d
--- /dev/null
+++ b/examples/camel-example-transformer-cdi/pom.xml
@@ -0,0 +1,102 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>examples</artifactId>
+    <version>2.19.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-example-transformer-cdi</artifactId>
+  <packaging>jar</packaging>
+  <name>Camel :: Example :: Transformer :: CDI</name>
+  <description>An example demonstrating declarative transformation along data type declaration using Java DSL and CDI
+  </description>
+
+  <dependencies>
+    <!-- START SNIPPET: e1 -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-cdi</artifactId>
+    </dependency>
+    
+    <!-- logging -->
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-slf4j-impl</artifactId>
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <!-- Allows the routes to be run via 'mvn camel:run' -->
+      <plugin>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-maven-plugin</artifactId>
+        <version>${project.version}</version>
+        <dependencies>
+          <dependency>
+            <groupId>org.apache.deltaspike.cdictrl</groupId>
+            <artifactId>deltaspike-cdictrl-weld</artifactId>
+            <version>${deltaspike-version}</version>
+          </dependency>
+          <dependency>
+            <groupId>org.jboss.weld.se</groupId>
+            <artifactId>weld-se</artifactId>
+            <version>${weld2-version}</version>
+          </dependency>
+          <!-- logging -->
+          <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-api</artifactId>
+            <version>${log4j2-version}</version>
+          </dependency>
+          <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-core</artifactId>
+            <version>${log4j2-version}</version>
+          </dependency>
+          <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-slf4j-impl</artifactId>
+            <version>${log4j2-version}</version>
+          </dependency>
+          <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-1.2-api</artifactId>
+            <version>${log4j2-version}</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+    </plugins>
+
+  </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-cdi/src/main/java/org/apache/camel/example/transformer/cdi/MyRoutes.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-cdi/src/main/java/org/apache/camel/example/transformer/cdi/MyRoutes.java b/examples/camel-example-transformer-cdi/src/main/java/org/apache/camel/example/transformer/cdi/MyRoutes.java
new file mode 100644
index 0000000..ee107a3
--- /dev/null
+++ b/examples/camel-example-transformer-cdi/src/main/java/org/apache/camel/example/transformer/cdi/MyRoutes.java
@@ -0,0 +1,56 @@
+/**
+ * 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.example.transformer.cdi;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.dataformat.JaxbDataFormat;
+import org.apache.camel.model.transformer.DataFormatTransformerDefinition;
+import org.apache.camel.model.transformer.EndpointTransformerDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Configures all our Camel routes, components, endpoints and beans
+ */
+public class MyRoutes extends RouteBuilder {
+
+    @Override
+    public void configure() {
+        EndpointTransformerDefinition eptd = new EndpointTransformerDefinition();
+        eptd.setUri("xslt:transform.xsl");
+        eptd.setFrom("xml:MyRequest");
+        eptd.setTo("xml:MyResponse");
+        getContext().getTransformers().add(eptd);
+        
+        from("timer:foo?period=5000").id("timer-route")
+            .log("start -->")
+            .setBody(constant("<MyRequest>foobar</MyRequest>"))
+            .log("--> Sending:[${body}]")
+            .to("direct:a")
+            .log("--> Received:[${body}]")
+            .log("<-- end");
+        
+        from("direct:a").id("xslt-route")
+            .inputType("xml:MyRequest")
+            .outputType("xml:MyResponse")
+            .log("----> Received:[${body}]");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-cdi/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-cdi/src/main/resources/META-INF/LICENSE.txt b/examples/camel-example-transformer-cdi/src/main/resources/META-INF/LICENSE.txt
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/examples/camel-example-transformer-cdi/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-cdi/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-cdi/src/main/resources/META-INF/NOTICE.txt b/examples/camel-example-transformer-cdi/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/examples/camel-example-transformer-cdi/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Apache Camel distribution.                    ==
+   =========================================================================
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+
+   Please read the different LICENSE files present in the licenses directory of
+   this distribution.

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-cdi/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-cdi/src/main/resources/META-INF/beans.xml b/examples/camel-example-transformer-cdi/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..112d56d
--- /dev/null
+++ b/examples/camel-example-transformer-cdi/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,18 @@
+<?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.
+-->
+<beans/>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-cdi/src/main/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-cdi/src/main/resources/log4j2.properties b/examples/camel-example-transformer-cdi/src/main/resources/log4j2.properties
new file mode 100644
index 0000000..a1e0d92
--- /dev/null
+++ b/examples/camel-example-transformer-cdi/src/main/resources/log4j2.properties
@@ -0,0 +1,28 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+appender.stdout.type = Console
+appender.stdout.name = stdout
+appender.stdout.layout.type = PatternLayout
+appender.stdout.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+rootLogger.level = INFO
+rootLogger.appenderRef.stdout.ref = stdout
+
+#logger.transformer.name = org.apache.camel.impl.transformer
+#logger.transformer.level = DEBUG
+#logger.processor.name = org.apache.camel.processor
+#logger.processor.level = DEBUG

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-cdi/src/main/resources/transform.xsl
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-cdi/src/main/resources/transform.xsl b/examples/camel-example-transformer-cdi/src/main/resources/transform.xsl
new file mode 100644
index 0000000..2f2e514
--- /dev/null
+++ b/examples/camel-example-transformer-cdi/src/main/resources/transform.xsl
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="Shift_JIS"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+    <xsl:template match="@*|node()">
+        <xsl:copy>
+            <xsl:apply-templates select="@*|node()"/>
+        </xsl:copy>
+    </xsl:template>
+
+    <xsl:template match="MyRequest">
+        <MyResponse>
+            <xsl:apply-templates/>
+        </MyResponse>
+    </xsl:template>
+</xsl:stylesheet>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/7ba090f5/examples/camel-example-transformer-demo/README.md
----------------------------------------------------------------------
diff --git a/examples/camel-example-transformer-demo/README.md b/examples/camel-example-transformer-demo/README.md
new file mode 100644
index 0000000..8f203f8
--- /dev/null
+++ b/examples/camel-example-transformer-demo/README.md
@@ -0,0 +1,33 @@
+# Declarative Transformer Demo using Spring XML
+
+
+### Introduction
+
+This example shows how to work with declarative transformation by declaring data types.
+
+### Build
+
+You will need to compile this example first:
+
+	mvn compile
+
+### Run
+
+To run the example type
+
+	mvn exec:java
+
+You can see the routing rules by looking at the Spring XML configuration lives in
+`src/main/resources/META-INF/spring`
+
+
+### Forum, Help, etc
+
+If you hit an problems please let us know on the Camel Forums
+	<http://camel.apache.org/discussion-forums.html>
+
+Please help us make Apache Camel better - we appreciate any feedback you may
+have.  Enjoy!
+
+
+The Camel riders!