Updated Branches: refs/heads/camel-2.12.x 8abdd6923 -> f2591ca3e refs/heads/master f4e8992f3 -> d6b118e5d
CAMEL-7119: Added useOriginal to agg strategies. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d6b118e5 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d6b118e5 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d6b118e5 Branch: refs/heads/master Commit: d6b118e5d17ce81955b8c43c776a956a640808e4 Parents: f4e8992 Author: Claus Ibsen <[email protected]> Authored: Thu Jan 9 17:31:26 2014 +0100 Committer: Claus Ibsen <[email protected]> Committed: Thu Jan 9 17:31:26 2014 +0100 ---------------------------------------------------------------------- .../UseOriginalAggregationStrategy.java | 8 ++- .../util/toolbox/AggregationStrategies.java | 13 +++- ...lticastKeepOriginalMessageUnchangedTest.java | 62 ++++++++++++++++++++ 3 files changed, 79 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/d6b118e5/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseOriginalAggregationStrategy.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseOriginalAggregationStrategy.java b/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseOriginalAggregationStrategy.java index b0ef089..d6b7059 100644 --- a/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseOriginalAggregationStrategy.java +++ b/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseOriginalAggregationStrategy.java @@ -17,7 +17,6 @@ package org.apache.camel.processor.aggregate; import org.apache.camel.Exchange; -import org.apache.camel.util.ObjectHelper; /** * An {@link org.apache.camel.processor.aggregate.AggregationStrategy} which just uses the original exchange @@ -32,8 +31,11 @@ public class UseOriginalAggregationStrategy implements AggregationStrategy { private final Exchange original; private final boolean propagateException; + public UseOriginalAggregationStrategy() { + this(null, true); + } + public UseOriginalAggregationStrategy(Exchange original, boolean propagateException) { - ObjectHelper.notNull(original, "Original Exchange"); this.original = original; this.propagateException = propagateException; } @@ -45,7 +47,7 @@ public class UseOriginalAggregationStrategy implements AggregationStrategy { original.setException(exception); } } - return original; + return original != null ? original : oldExchange; } protected Exception checkException(Exchange oldExchange, Exchange newExchange) { http://git-wip-us.apache.org/repos/asf/camel/blob/d6b118e5/camel-core/src/main/java/org/apache/camel/util/toolbox/AggregationStrategies.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/util/toolbox/AggregationStrategies.java b/camel-core/src/main/java/org/apache/camel/util/toolbox/AggregationStrategies.java index e269f0e..9877758 100644 --- a/camel-core/src/main/java/org/apache/camel/util/toolbox/AggregationStrategies.java +++ b/camel-core/src/main/java/org/apache/camel/util/toolbox/AggregationStrategies.java @@ -20,6 +20,7 @@ import org.apache.camel.processor.aggregate.AggregationStrategy; import org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter; import org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy; import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy; +import org.apache.camel.processor.aggregate.UseOriginalAggregationStrategy; /** * Toolbox class to create commonly used Aggregation Strategies in a fluent manner. @@ -51,13 +52,23 @@ public final class AggregationStrategies { /** * Use the latest incoming exchange. - * @see UseLatestAggregationStrategy + * + * @see org.apache.camel.processor.aggregate.UseLatestAggregationStrategy */ public static AggregationStrategy useLatest() { return new UseLatestAggregationStrategy(); } /** + * Use the original exchange. + * + * @see org.apache.camel.processor.aggregate.UseOriginalAggregationStrategy + */ + public static AggregationStrategy useOriginal() { + return new UseOriginalAggregationStrategy(); + } + + /** * Creates a {@link GroupedExchangeAggregationStrategy} aggregation strategy. */ public static AggregationStrategy groupedExchange() { http://git-wip-us.apache.org/repos/asf/camel/blob/d6b118e5/camel-core/src/test/java/org/apache/camel/processor/MulticastKeepOriginalMessageUnchangedTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/processor/MulticastKeepOriginalMessageUnchangedTest.java b/camel-core/src/test/java/org/apache/camel/processor/MulticastKeepOriginalMessageUnchangedTest.java new file mode 100644 index 0000000..b80c100 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/processor/MulticastKeepOriginalMessageUnchangedTest.java @@ -0,0 +1,62 @@ +/** + * 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.processor; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.util.toolbox.AggregationStrategies; + +/** + * @version + */ +public class MulticastKeepOriginalMessageUnchangedTest extends ContextTestSupport { + + public void testUnchanged() throws Exception { + getMockEndpoint("mock:a").expectedBodiesReceived("Hello World"); + getMockEndpoint("mock:a").message(0).header("foo").isNull(); + getMockEndpoint("mock:a").message(0).header("bar").isEqualTo("no"); + getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); + getMockEndpoint("mock:result").message(0).header("foo").isNull(); + getMockEndpoint("mock:result").message(0).header("bar").isEqualTo("no"); + getMockEndpoint("mock:foo").expectedBodiesReceived("Foo was here Hello World"); + getMockEndpoint("mock:foo").expectedHeaderReceived("foo", "yes"); + getMockEndpoint("mock:foo").message(0).header("bar").isNull(); + + template.sendBody("direct:a", "Hello World"); + + assertMockEndpointsSatisfied(); + } + + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + from("direct:a") + .setHeader("bar", constant("no")) + .to("mock:a") + .multicast(AggregationStrategies.useOriginal()).to("direct:foo").end() + .to("mock:result"); + + from("direct:foo") + .setHeader("foo", constant("yes")) + .removeHeader("bar") + .transform().simple("Foo was here ${body}") + .to("mock:foo"); + } + }; + } + +}
