You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/11/01 13:24:03 UTC
[camel] branch camel-2.20.x updated: CAMEL-11962: Fixed transacted
with AdviceWith recent fix.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-2.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.20.x by this push:
new 5decb45 CAMEL-11962: Fixed transacted with AdviceWith recent fix.
5decb45 is described below
commit 5decb451142df337f14e92f2ab63943972e5016b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Nov 1 14:23:30 2017 +0100
CAMEL-11962: Fixed transacted with AdviceWith recent fix.
---
.../org/apache/camel/builder/AdviceWithTasks.java | 12 +++-
.../camel/issues/AdviceWithTransactedTest.java | 75 ++++++++++++++++++++++
2 files changed, 84 insertions(+), 3 deletions(-)
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 a604111..27f3456 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
@@ -27,6 +27,7 @@ import org.apache.camel.model.FromDefinition;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.ProcessorDefinitionHelper;
import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.TransactedDefinition;
import org.apache.camel.util.EndpointHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -433,9 +434,14 @@ public final class AdviceWithTasks {
List<ProcessorDefinition<?>> outputs = new ArrayList<>();
// skip abstract nodes in the beginning as they are cross cutting functionality such as onException, onCompletion etc
for (ProcessorDefinition output : route.getOutputs()) {
- boolean invalid = outputs.isEmpty() && output.isAbstract();
- if (!invalid) {
- outputs.add(output);
+ // special for transacted, which we need to unwrap
+ if (output instanceof TransactedDefinition) {
+ outputs.addAll(output.getOutputs());
+ } else {
+ boolean invalid = outputs.isEmpty() && output.isAbstract();
+ if (!invalid) {
+ outputs.add(output);
+ }
}
}
diff --git a/camel-core/src/test/java/org/apache/camel/issues/AdviceWithTransactedTest.java b/camel-core/src/test/java/org/apache/camel/issues/AdviceWithTransactedTest.java
new file mode 100644
index 0000000..36c65e7
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/issues/AdviceWithTransactedTest.java
@@ -0,0 +1,75 @@
+/**
+ * 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.Processor;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.spi.Policy;
+import org.apache.camel.spi.RouteContext;
+
+/**
+ * @version
+ */
+public class AdviceWithTransactedTest extends ContextTestSupport {
+
+ public void testAdviceTransacted() throws Exception {
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+ getMockEndpoint("mock:advice").expectedMessageCount(1);
+
+ context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ weaveAddFirst().to("mock:advice");
+ }
+ });
+
+ template.sendBody("direct:advice", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:advice")
+ // use policy instead of transacted (but its similar)
+ .policy(new MyDummyPolicy())
+ .log("Advice ${body}")
+ .to("mock:result");
+ }
+ };
+ }
+
+ private static final class MyDummyPolicy implements Policy {
+
+ @Override
+ public void beforeWrap(RouteContext routeContext, ProcessorDefinition<?> definition) {
+ // noop
+ }
+
+ @Override
+ public Processor wrap(RouteContext routeContext, Processor processor) {
+ return processor;
+ }
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].