Repository: camel Updated Branches: refs/heads/master bea22a4fe -> faa20255e
CAMEL-7622: Fixed bug with adviceWith after last code change in this area. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/faa20255 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/faa20255 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/faa20255 Branch: refs/heads/master Commit: faa20255e236fcdb44879c84ab9bb086a8671f72 Parents: bea22a4 Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Jul 22 11:16:22 2014 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Jul 22 11:16:22 2014 +0200 ---------------------------------------------------------------------- .../apache/camel/builder/AdviceWithTasks.java | 11 ++-- .../camel/issues/AdviceWithOnExceptionTest.java | 62 ++++++++++++++++++++ 2 files changed, 66 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/faa20255/camel-core/src/main/java/org/apache/camel/builder/AdviceWithTasks.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/builder/AdviceWithTasks.java b/camel-core/src/main/java/org/apache/camel/builder/AdviceWithTasks.java index 69f5a0a..694841c 100644 --- a/camel-core/src/main/java/org/apache/camel/builder/AdviceWithTasks.java +++ b/camel-core/src/main/java/org/apache/camel/builder/AdviceWithTasks.java @@ -312,7 +312,7 @@ public final class AdviceWithTasks { /** * Gets the outputs from the given parent. * <p/> - * This implementation deals with that outputs can be abstract and retrieves the correct non-nested output. + * This implementation deals with that outputs can be abstract and retrieves the <i>correct</i> parent output. * * @param parent the parent * @return <tt>null</tt> if no parent @@ -323,12 +323,9 @@ public final class AdviceWithTasks { return null; } List<ProcessorDefinition> outputs = parent.getOutputs(); - if (outputs.size() >= 1) { - // if the 1st output is abstract, then its onException,transacted,intercept etc so we should - // get the 'actual' outputs from that - if (outputs.get(0).isAbstract()) { - outputs = outputs.get(0).getOutputs(); - } + if (outputs.size() == 1 && outputs.get(0).isAbstract()) { + // if the output is abstract then get its output, as + outputs = outputs.get(0).getOutputs(); } return outputs; } http://git-wip-us.apache.org/repos/asf/camel/blob/faa20255/camel-core/src/test/java/org/apache/camel/issues/AdviceWithOnExceptionTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/issues/AdviceWithOnExceptionTest.java b/camel-core/src/test/java/org/apache/camel/issues/AdviceWithOnExceptionTest.java new file mode 100644 index 0000000..4772baa --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/issues/AdviceWithOnExceptionTest.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.issues; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.AdviceWithRouteBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.RouteDefinition; + +/** + * @version + */ +public class AdviceWithOnExceptionTest extends ContextTestSupport { + + public void testAdviceWithOnException() throws Exception { + RouteDefinition route = context.getRouteDefinitions().get(0); + route.adviceWith(context, new AdviceWithRouteBuilder() { + @Override + public void configure() throws Exception { + weaveById("b").after().to("mock:result"); + } + }); + context.start(); + + getMockEndpoint("mock:a").expectedMessageCount(1); + getMockEndpoint("mock:b").expectedMessageCount(1); + getMockEndpoint("mock:result").expectedMessageCount(1); + + template.sendBody("direct:start", "Hello World"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + onException(IllegalArgumentException.class).handled(true).to("mock:handled"); + + from("direct:start") + .to("mock:a").id("a") + .to("mock:b").id("b"); + } + }; + } + +}