This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 251dd33787c4a22e3d6edc54104b8f5a2fbc5f03 Author: Guillaume Nodet <[email protected]> AuthorDate: Tue Mar 10 10:56:08 2020 +0100 CAMEL-14684: add unit test and update migration guide --- .../BodyOnlyAggregationStrategyTest.java | 90 ++++++++++++++++++++++ .../modules/ROOT/pages/camel-3x-upgrade-guide.adoc | 22 ++++++ 2 files changed, 112 insertions(+) diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/BodyOnlyAggregationStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/BodyOnlyAggregationStrategyTest.java new file mode 100644 index 0000000..ca654c4 --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/BodyOnlyAggregationStrategyTest.java @@ -0,0 +1,90 @@ +/* + * 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.aggregator; + +import org.apache.camel.AggregationStrategy; +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.ExtendedExchange; +import org.apache.camel.builder.DeadLetterChannelBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +/** + * Unit test for CAMEL-14684 + */ +public class BodyOnlyAggregationStrategyTest extends ContextTestSupport { + + @Test + public void exceptionRouteTest() throws Exception { + getMockEndpoint("mock:error").expectedMessageCount(1); + getMockEndpoint("mock:failingRoute").expectedMessageCount(1); + getMockEndpoint("mock:nextRoute").expectedMessageCount(0); + + template.sendBody("direct:start", null); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + DeadLetterChannelBuilder deadLetterChannelBuilder = deadLetterChannel("direct:error"); + deadLetterChannelBuilder.setUseOriginalMessage(true); + + from("direct:failingRoute") + .errorHandler(deadLetterChannelBuilder) + .to("mock:failingRoute") + .throwException(new RuntimeException("Boem!")); + + from("direct:error") + .to("mock:error"); + + from("direct:nextRoute") + .to("mock:nextRoute"); + + from("direct:start") + .enrich("direct:failingRoute", new BodyOnlyAggregationStrategy()) + .to("direct:nextRoute"); + } + }; + } + + /** + * This aggregation strategy will only take the body from the called route and returns the old exchange. + * Only the property CamelErrorHandlerHandled is taken from the route to make sure the route stops on an exception. + */ + public static class BodyOnlyAggregationStrategy implements AggregationStrategy { + + @Override + public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { + oldExchange.getIn().setBody(newExchange.getIn().getBody()); + + oldExchange.adapt(ExtendedExchange.class).setErrorHandlerHandled( + newExchange.adapt(ExtendedExchange.class).getErrorHandlerHandled() + ); + // deprecated usage: + // if (newExchange.getProperties().get(Exchange.ERRORHANDLER_HANDLED) != null) { + // oldExchange.getProperties().put(Exchange.ERRORHANDLER_HANDLED, newExchange.getProperties().get(Exchange.ERRORHANDLER_HANDLED)); + //} + + return oldExchange; + } + } +} diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc index 234ebf7..08dd296 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide.adoc @@ -421,6 +421,28 @@ Should now be: exchange.setRollbackOnly(true); ---- +==== Exchange.ERRORHANDLER_HANDLED + +The exchange property `Exchange.ERRORHANDLER_HANDLED` was used to indicate that the error handling mechanism for a given exchange +had completed. This property sometimes had to be conveyed by aggregation strategies, so instead of + +[source,java] +---- + oldExchange.getProperties().put( + Exchange.ERRORHANDLER_HANDLED, + newExchange.getProperties().get(Exchange.ERRORHANDLER_HANDLED)); +---- + +one should now use: + +[source,java] +---- + Boolean handled = newExchange.adapt(ExtendedExchange.class) + .getErrorHandlerHandled(); + oldExchange.adapt(ExtendedExchange.class) + .setErrorHandlerHandled(handled); +---- + ==== ModelHelper removed The class `org.apache.camel.model.ModelHelper` has been removed. Instead you can use its functionality from `ExtendedCamelContext` by
