You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2016/09/08 15:42:02 UTC

[2/4] camel git commit: CAMEL-7831: create a java8 only demo showing how to use lambda expressions for Predicate / Expression inside the Java DSL (using Message as a typesafe parameter)

CAMEL-7831: create a java8 only demo showing how to use lambda expressions for Predicate / Expression inside the Java DSL (using Message as a typesafe parameter)


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

Branch: refs/heads/master
Commit: f7e603ac38880a9cb399177474d7d0a6d940765e
Parents: 69744b3
Author: lburgazzoli <lb...@gmail.com>
Authored: Mon Sep 5 18:02:43 2016 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Thu Sep 8 15:55:11 2016 +0200

----------------------------------------------------------------------
 .../apache/camel/builder/ExpressionBuilder.java | 141 ++++++++++++++-
 .../apache/camel/builder/ExpressionClause.java  | 174 ++++++++++++++++++-
 .../camel/builder/ExpressionBuilderTest.java    |  11 ++
 .../camel/builder/ExpressionFunctionTest.java   |  67 +++++++
 examples/camel-example-dsl-java8/pom.xml        |  87 ++++++++++
 .../camel/example/dsl/java8/MyApplication.java  |  35 ++++
 .../apache/camel/example/dsl/java8/MyRoute.java |  63 +++++++
 .../src/main/resources/log4j2.properties        |  23 +++
 examples/pom.xml                                |   1 +
 9 files changed, 600 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f7e603ac/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
index d80306a..a138271 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
@@ -25,10 +25,13 @@ import java.util.Comparator;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Random;
 import java.util.Scanner;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiFunction;
+import java.util.function.Function;
 import java.util.regex.Pattern;
 
 import org.apache.camel.CamelContext;
@@ -80,7 +83,7 @@ public final class ExpressionBuilder {
     private ExpressionBuilder() {
     }
     
-     /**
+    /**
      * Returns an expression for the inbound message attachments
      *
      * @return an expression object which will return the inbound message attachments
@@ -893,6 +896,80 @@ public final class ExpressionBuilder {
     }
 
     /**
+     * Returns a functional expression for the exchanges inbound message body
+     */
+    public static Expression bodyExpression(final Function<Object, Object> function) {
+        return new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(
+                    exchange.getIn().getBody()
+                );
+            }
+
+            @Override
+            public String toString() {
+                return "bodyExpression";
+            }
+        };
+    }
+
+    /**
+     * Returns a functional expression for the exchanges inbound message body and headers
+     */
+    public static Expression bodyExpression(final BiFunction<Object, Map<String, Object>, Object> function) {
+        return new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(
+                    exchange.getIn().getBody(),
+                    exchange.getIn().getHeaders()
+                );
+            }
+
+            @Override
+            public String toString() {
+                return "bodyExpression";
+            }
+        };
+    }
+
+    /**
+     * Returns a functional expression for the exchanges inbound message body converted to a desired type
+     */
+    public static <T> Expression bodyExpression(final Class<T> bodyType, final Function<T, Object> function) {
+        return new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(
+                    exchange.getIn().getBody(bodyType)
+                );
+            }
+
+            @Override
+            public String toString() {
+                return "bodyExpression (" + bodyType +  ")";
+            }
+        };
+    }
+
+    /**
+     * Returns a functional expression for the exchanges inbound message body converted to a desired type and headers
+     */
+    public static <T> Expression bodyExpression(final Class<T> bodyType, final BiFunction<T, Map<String, Object>, Object> function) {
+        return new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(
+                    exchange.getIn().getBody(bodyType),
+                    exchange.getIn().getHeaders()
+                );
+            }
+
+            @Override
+            public String toString() {
+                return "bodyExpression (" + bodyType +  ")";
+            }
+        };
+    }
+
+    /**
      * Returns the expression for the exchanges inbound message body invoking methods defined
      * in a simple OGNL notation
      *
@@ -1319,6 +1396,36 @@ public final class ExpressionBuilder {
     }
 
     /**
+     * Returns a functional expression for the exchange
+     */
+    public static Expression exchangeExpression(final Function<Exchange, Object> function) {
+        return new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(exchange);
+            }
+
+            @Override
+            public String toString() {
+                return "exchangeExpression";
+            }
+        };
+    }
+
+    /**
+     * Returns the expression for the IN message
+     */
+    public static Expression messageExpression() {
+        return inMessageExpression();
+    }
+
+    /**
+     * Returns a functional expression for the IN message
+     */
+    public static Expression messageExpression(final Function<Message, Object> function) {
+        return inMessageExpression(function);
+    }
+
+    /**
      * Returns the expression for the IN message
      */
     public static Expression inMessageExpression() {
@@ -1335,6 +1442,22 @@ public final class ExpressionBuilder {
     }
 
     /**
+     * Returns a functional expression for the IN message
+     */
+    public static Expression inMessageExpression(final Function<Message, Object> function) {
+        return new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(exchange.getIn());
+            }
+
+            @Override
+            public String toString() {
+                return "inMessageExpression";
+            }
+        };
+    }
+
+    /**
      * Returns the expression for the OUT message
      */
     public static Expression outMessageExpression() {
@@ -1351,6 +1474,22 @@ public final class ExpressionBuilder {
     }
 
     /**
+     * Returns a functional expression for the OUT message
+     */
+    public static Expression outMessageExpression(final Function<Message, Object> function) {
+        return new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(exchange.getOut());
+            }
+
+            @Override
+            public String toString() {
+                return "outMessageExpression";
+            }
+        };
+    }
+
+    /**
      * Returns an expression which converts the given expression to the given type
      */
     public static Expression convertToExpression(final Expression expression, final Class<?> type) {

http://git-wip-us.apache.org/repos/asf/camel/blob/f7e603ac/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java b/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
index 3a73651..8da22c8 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/ExpressionClause.java
@@ -17,11 +17,16 @@
 package org.apache.camel.builder;
 
 import java.util.Map;
+import java.util.function.BiFunction;
+import java.util.function.Function;
 
+import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
+import org.apache.camel.Message;
 import org.apache.camel.builder.xml.Namespaces;
 import org.apache.camel.model.ExpressionNode;
 import org.apache.camel.model.language.ExpressionDefinition;
+import org.apache.camel.support.ExpressionAdapter;
 
 /**
  * Represents an expression clause within the DSL which when the expression is
@@ -67,6 +72,35 @@ public class ExpressionClause<T> extends ExpressionDefinition {
     }
 
     /**
+     * A functional expression of the exchange
+     *
+     * Note: this is experimental and subject to changes in future releases.
+     */
+    public T exchange(final Function<Exchange, Object> function) {
+        return delegate.expression(new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(exchange);
+            }
+        });
+    }
+
+    /**
+     * An expression of an inbound message
+     */
+    public T message() {
+        return inMessage();
+    }
+
+    /**
+     * A functional expression of an inbound message
+     *
+     * Note: this is experimental and subject to changes in future releases.
+     */
+    public T message(final Function<Message, Object> function) {
+        return inMessage(function);
+    }
+
+    /**
      * An expression of an inbound message
      */
     public T inMessage() {
@@ -74,13 +108,39 @@ public class ExpressionClause<T> extends ExpressionDefinition {
     }
 
     /**
-     * An expression of an inbound message
+     * A functional expression of an inbound message
+     *
+     * Note: this is experimental and subject to changes in future releases.
+     */
+    public T inMessage(final Function<Message, Object> function) {
+        return delegate.expression(new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(exchange.getIn());
+            }
+        });
+    }
+
+    /**
+     * An expression of an outbound message
      */
     public T outMessage() {
         return delegate.outMessage();
     }
 
     /**
+     * A functional expression of an outbound message
+     *
+     * Note: this is experimental and subject to changes in future releases.
+     */
+    public T outMessage(final Function<Message, Object> function) {
+        return delegate.expression(new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(exchange.getOut());
+            }
+        });
+    }
+
+    /**
      * An expression of an inbound message body
      */
     public T body() {
@@ -88,6 +148,34 @@ public class ExpressionClause<T> extends ExpressionDefinition {
     }
 
     /**
+     * A functional expression of an inbound message body
+     *
+     * Note: this is experimental and subject to changes in future releases.
+     */
+    public T body(final Function<Object, Object> function) {
+        return delegate.expression(new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(exchange.getIn().getBody());
+            }
+        });
+    }
+
+    /**
+     * A functional expression of an inbound message body and headers
+     *
+     * Note: this is experimental and subject to changes in future releases.
+     */
+    public T body(final BiFunction<Object, Map<String, Object>, Object> function) {
+        return delegate.expression(new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(
+                    exchange.getIn().getBody(),
+                    exchange.getIn().getHeaders());
+            }
+        });
+    }
+
+    /**
      * An expression of an inbound message body converted to the expected type
      */
     public T body(Class<?> expectedType) {
@@ -95,6 +183,34 @@ public class ExpressionClause<T> extends ExpressionDefinition {
     }
 
     /**
+     * A functional expression of an inbound message body converted to the expected type
+     *
+     * Note: this is experimental and subject to changes in future releases.
+     */
+    public <B> T body(Class<B> expectedType, final Function<B, Object> function) {
+        return delegate.expression(new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(exchange.getIn().getBody(expectedType));
+            }
+        });
+    }
+
+    /**
+     * A functional expression of an inbound message body converted to the expected type and headers
+     *
+     * Note: this is experimental and subject to changes in future releases.
+     */
+    public <B> T body(Class<B> expectedType, final BiFunction<B, Map<String, Object>, Object> function) {
+        return delegate.expression(new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(
+                    exchange.getIn().getBody(expectedType),
+                    exchange.getIn().getHeaders());
+            }
+        });
+    }
+
+    /**
      * An expression of an outbound message body
      */
     public T outBody() {
@@ -102,6 +218,34 @@ public class ExpressionClause<T> extends ExpressionDefinition {
     }
 
     /**
+     * A functional expression of an outbound message body
+     *
+     * Note: this is experimental and subject to changes in future releases.
+     */
+    public T outBody(final Function<Object, Object> function) {
+        return delegate.expression(new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(exchange.getOut().getBody());
+            }
+        });
+    }
+
+    /**
+     * A functional expression of an outbound message body and headers
+     *
+     * Note: this is experimental and subject to changes in future releases.
+     */
+    public T outBody(final BiFunction<Object, Map<String, Object>, Object> function) {
+        return delegate.expression(new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(
+                    exchange.getOut().getBody(),
+                    exchange.getOut().getHeaders());
+            }
+        });
+    }
+
+    /**
      * An expression of an outbound message body converted to the expected type
      */
     public T outBody(Class<?> expectedType) {
@@ -109,6 +253,34 @@ public class ExpressionClause<T> extends ExpressionDefinition {
     }
 
     /**
+     * A functional expression of an outbound message body converted to the expected type
+     *
+     * Note: this is experimental and subject to changes in future releases.
+     */
+    public <B> T outBody(Class<B> expectedType, final Function<B, Object> function) {
+        return delegate.expression(new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(exchange.getOut().getBody(expectedType));
+            }
+        });
+    }
+
+    /**
+     * A functional expression of an outbound message body converted to the expected type and headers
+     *
+     * Note: this is experimental and subject to changes in future releases.
+     */
+    public <B> T outBody(Class<B> expectedType, final BiFunction<B, Map<String, Object>, Object> function) {
+        return delegate.expression(new ExpressionAdapter() {
+            public Object evaluate(Exchange exchange) {
+                return function.apply(
+                    exchange.getOut().getBody(expectedType),
+                    exchange.getOut().getHeaders());
+            }
+        });
+    }
+
+    /**
      * An expression of an inbound message header of the given name
      */
     public T header(String name) {

http://git-wip-us.apache.org/repos/asf/camel/blob/f7e603ac/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java b/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java
index ac4a16e..3cefd46 100644
--- a/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java
+++ b/camel-core/src/test/java/org/apache/camel/builder/ExpressionBuilderTest.java
@@ -110,6 +110,17 @@ public class ExpressionBuilderTest extends TestSupport {
         assertEquals("Hello there!", parseSimpleOrFallbackToConstantExpression("$simple{body}", camelContext).evaluate(exchange, String.class));
     }
 
+    public void testFunction() throws Exception {
+        assertExpression(
+            messageExpression(m -> m.getExchange().getIn().getHeader("name")),
+            exchange,
+            "James");
+        assertExpression(
+            messageExpression(m -> m.getHeader("name")),
+            exchange,
+            "James");
+    }
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();

http://git-wip-us.apache.org/repos/asf/camel/blob/f7e603ac/camel-core/src/test/java/org/apache/camel/builder/ExpressionFunctionTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/builder/ExpressionFunctionTest.java b/camel-core/src/test/java/org/apache/camel/builder/ExpressionFunctionTest.java
new file mode 100644
index 0000000..2cdae6c
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/builder/ExpressionFunctionTest.java
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.builder;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+
+import static org.apache.camel.builder.ExpressionBuilder.messageExpression;
+
+/**
+ * @version 
+ */
+public class ExpressionFunctionTest extends ContextTestSupport {
+
+    public void testTransform() throws Exception {
+        MockEndpoint functionMock = getMockEndpoint("mock:function");
+        functionMock.expectedMessageCount(1);
+        functionMock.expectedBodyReceived().constant("function");
+
+        MockEndpoint inFunctionMock = getMockEndpoint("mock:inFunction");
+        inFunctionMock.expectedMessageCount(1);
+        inFunctionMock.expectedBodyReceived().constant("inFunction");
+
+        MockEndpoint inFunction2Mock = getMockEndpoint("mock:inFunction2");
+        inFunction2Mock.expectedMessageCount(1);
+        inFunction2Mock.expectedBodyReceived().constant("inFunction2");
+
+        template.sendBodyAndHeader("direct:function", "Hello World", "type", "function");
+        template.sendBodyAndHeader("direct:inFunction", "Hello World", "type", "inFunction");
+        template.sendBodyAndHeader("direct:inFunction2", "Hello World", "type", "inFunction2");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:function")
+                    .transform().message(m -> m.getExchange().getIn().getHeader("type"))
+                    .to("mock:function");
+                from("direct:inFunction")
+                    .transform().message(m -> m.getHeader("type"))
+                    .to("mock:inFunction");
+                from("direct:inFunction2")
+                    .transform(messageExpression(m -> m.getHeader("type")))
+                    .to("mock:inFunction2");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/f7e603ac/examples/camel-example-dsl-java8/pom.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-dsl-java8/pom.xml b/examples/camel-example-dsl-java8/pom.xml
new file mode 100644
index 0000000..417bd1d
--- /dev/null
+++ b/examples/camel-example-dsl-java8/pom.xml
@@ -0,0 +1,87 @@
+<?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.18.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-example-dsl-java8</artifactId>
+  <packaging>jar</packaging>
+  <name>Camel :: Example :: DSL :: Java8 :: Spring JavaConfig</name>
+  <description>An example for showing Camel Spring JavaConfig DSL for Java 8</description>
+
+  <dependencies>
+
+    <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-spring-javaconfig</artifactId>
+    </dependency>
+
+    <!-- logging -->
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-api</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-slf4j-impl</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-jul</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <!-- Allows the example to be run via 'mvn compile exec:java' -->
+      <plugin>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-maven-plugin</artifactId>
+        <version>${project.version}</version>
+        <configuration>
+          <basedPackages>org.apache.camel.example.dsl.java8</basedPackages>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/f7e603ac/examples/camel-example-dsl-java8/src/main/java/org/apache/camel/example/dsl/java8/MyApplication.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-dsl-java8/src/main/java/org/apache/camel/example/dsl/java8/MyApplication.java b/examples/camel-example-dsl-java8/src/main/java/org/apache/camel/example/dsl/java8/MyApplication.java
new file mode 100644
index 0000000..d6e2ba8
--- /dev/null
+++ b/examples/camel-example-dsl-java8/src/main/java/org/apache/camel/example/dsl/java8/MyApplication.java
@@ -0,0 +1,35 @@
+/**
+ * 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.dsl.java8;
+
+import org.apache.camel.spring.javaconfig.CamelConfiguration;
+import org.apache.camel.spring.javaconfig.Main;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@ComponentScan
+public class MyApplication extends CamelConfiguration {
+    /**
+     * Allow this route to be run as an application
+     */
+    public static void main(String[] args) throws Exception {
+        Main main = new Main();
+        main.setConfigClass(MyApplication.class);
+        main.run();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/f7e603ac/examples/camel-example-dsl-java8/src/main/java/org/apache/camel/example/dsl/java8/MyRoute.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-dsl-java8/src/main/java/org/apache/camel/example/dsl/java8/MyRoute.java b/examples/camel-example-dsl-java8/src/main/java/org/apache/camel/example/dsl/java8/MyRoute.java
new file mode 100644
index 0000000..bcfb294
--- /dev/null
+++ b/examples/camel-example-dsl-java8/src/main/java/org/apache/camel/example/dsl/java8/MyRoute.java
@@ -0,0 +1,63 @@
+/**
+ * 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.dsl.java8;
+
+import java.util.Date;
+import java.util.Objects;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.stereotype.Component;
+
+@Component
+public class MyRoute extends RouteBuilder {
+    @Override
+    public void configure() throws Exception {
+        from("timer:simple?period=503")
+            .id("simple-route")
+            .transform()
+                .exchange(this::dateToTime)
+            .choice()
+                .when()
+                    .body(Integer.class, b ->  (b & 1) == 0)
+                    .log("Received even number")
+                .when()
+                    .body(Integer.class, (b, h) -> h.containsKey("skip") ? false : (b & 1) == 0)
+                    .log("Received odd number")
+                .when()
+                    .body(Objects::isNull)
+                    .log("Received null body")
+                .when()
+                    .body(Integer.class, b ->  (b & 1) != 0)
+                    .log("Received odd number")
+                .endChoice();
+
+
+         //   .transform(this::dateToTime2)
+         //   .transform(function(
+         //       (Exchange e) -> e.getProperty(Exchange.TIMER_FIRED_TIME, Date.class).getTime()
+         //   ))
+    }
+
+    private Long dateToTime(Exchange e) {
+        return e.getProperty(Exchange.TIMER_FIRED_TIME, Date.class).getTime();
+    }
+
+    private <T> T dateToTime2(Exchange exchange, Class<T> type) {
+        return null;
+    }
+}

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

http://git-wip-us.apache.org/repos/asf/camel/blob/f7e603ac/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 737cfa5..ec1c38c 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -53,6 +53,7 @@
     <module>camel-example-cxf-proxy</module>
     <module>camel-example-cxf-tomcat</module>
     <module>camel-example-console</module>
+    <module>camel-example-dsl-java8</module>
     <module>camel-example-etl</module>
     <module>camel-example-ftp</module>
     <module>camel-example-guice-jms</module>