Repository: camel
Updated Branches:
  refs/heads/master c86ec768c -> e8ca6615a


CAMEL-10468: Java8 DSL: Add support for aggregation strategy with different 
body types


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

Branch: refs/heads/master
Commit: e8ca6615a27e527079f0f6ae344743f061512768
Parents: c86ec76
Author: lburgazzoli <[email protected]>
Authored: Fri Nov 11 11:25:40 2016 +0100
Committer: lburgazzoli <[email protected]>
Committed: Fri Nov 11 11:25:40 2016 +0100

----------------------------------------------------------------------
 .../camel/builder/AggregationStrategyClause.java   | 17 +++++++++++++----
 .../camel/processor/enricher/EnricherDslTest.java  |  8 ++++----
 2 files changed, 17 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e8ca6615/camel-core/src/main/java/org/apache/camel/builder/AggregationStrategyClause.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/builder/AggregationStrategyClause.java
 
b/camel-core/src/main/java/org/apache/camel/builder/AggregationStrategyClause.java
index c72f904..81114c4 100644
--- 
a/camel-core/src/main/java/org/apache/camel/builder/AggregationStrategyClause.java
+++ 
b/camel-core/src/main/java/org/apache/camel/builder/AggregationStrategyClause.java
@@ -95,14 +95,23 @@ public class AggregationStrategyClause<T> implements 
AggregationStrategy {
      *
      * Note: this is experimental and subject to changes in future releases.
      */
-    public <B> T body(final Class<B> type, final BiFunction<B, B, B> function) 
{
+    public <B> T body(final Class<B> type, final BiFunction<B, B, Object> 
function) {
+        return body(type, type, function);
+    }
+
+    /**
+     * TODO: document
+     *
+     * Note: this is experimental and subject to changes in future releases.
+     */
+    public <O, N> T body(final Class<O> oldType, final Class<N> newType, final 
BiFunction<O, N, Object> function) {
         return exchange((Exchange oldExchange, Exchange newExchange) -> {
             Message oldMessage = oldExchange != null ? oldExchange.getIn() : 
null;
             Message newMessage = ObjectHelper.notNull(newExchange, 
"NewExchange").getIn();
 
-            B result = function.apply(
-                oldMessage != null ? oldMessage.getBody(type) : null,
-                newMessage != null ? newMessage.getBody(type) : null);
+            Object result = function.apply(
+                oldMessage != null ? oldMessage.getBody(oldType) : null,
+                newMessage != null ? newMessage.getBody(newType) : null);
 
             if (oldExchange != null) {
                 oldExchange.getIn().setBody(result);

http://git-wip-us.apache.org/repos/asf/camel/blob/e8ca6615/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherDslTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherDslTest.java
 
b/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherDslTest.java
index ca7d8fd..b0b6a97 100644
--- 
a/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherDslTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherDslTest.java
@@ -26,9 +26,9 @@ public class EnricherDslTest extends ContextTestSupport {
         MockEndpoint mock = getMockEndpoint("mock:enriched");
         mock.expectedBodiesReceived("res-1", "res-2", "res-3");
 
-        template.sendBody("direct:start", "1");
-        template.sendBody("direct:start", "2");
-        template.sendBody("direct:start", "3");
+        template.sendBody("direct:start", 1);
+        template.sendBody("direct:start", 2);
+        template.sendBody("direct:start", 3);
 
         mock.assertIsSatisfied();
     }
@@ -40,7 +40,7 @@ public class EnricherDslTest extends ContextTestSupport {
             public void configure() throws Exception {
                 from("direct:start")
                     .enrichWith("direct:resource")
-                        .body(String.class, (o, n) -> n + o)
+                        .body(Integer.class, String.class, (o, n) -> n + o)
                     .to("mock:enriched");
 
                 // set an empty message

Reply via email to