This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 776830004b517395488491157a7123aaae3302df Author: Claus Ibsen <[email protected]> AuthorDate: Fri Oct 8 09:53:34 2021 +0200 CAMEL-17048: Fixed transacted/sage EIP would add EIPs last that came before them. Though as Camel end user transacted should always be first so its uncommon to have this problem. --- .../apache/camel/model/RouteDefinitionHelper.java | 6 +- .../camel/issues/TransactedSetHeaderIssueTest.java | 95 ++++++++++++++++++++++ 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java index f765b68..fd73a1f 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java @@ -677,7 +677,7 @@ public final class RouteDefinitionHelper { if (saga != null) { // the outputs should be moved to the transacted policy - saga.getOutputs().addAll(lower); + saga.getOutputs().addAll(0, lower); // and add it as the single output lower.clear(); lower.add(saga); @@ -699,8 +699,8 @@ public final class RouteDefinitionHelper { } if (transacted != null) { - // the outputs should be moved to the transacted policy - transacted.getOutputs().addAll(lower); + // the outputs should be moved to the start of the transacted policy + transacted.getOutputs().addAll(0, lower); // and add it as the single output lower.clear(); lower.add(transacted); diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/TransactedSetHeaderIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/TransactedSetHeaderIssueTest.java new file mode 100644 index 0000000..bbf473a --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/issues/TransactedSetHeaderIssueTest.java @@ -0,0 +1,95 @@ +/* + * 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.NamedNode; +import org.apache.camel.Processor; +import org.apache.camel.Route; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.spi.Policy; +import org.junit.jupiter.api.Test; + +public class TransactedSetHeaderIssueTest extends ContextTestSupport { + + private Policy policy = new Policy() { + @Override + public void beforeWrap(Route route, NamedNode definition) { + // noop + } + + @Override + public Processor wrap(Route route, Processor processor) { + return processor; + } + }; + + @Override + public boolean isUseRouteBuilder() { + return false; + } + + @Test + public void testSetHeaderOk() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + context.getRegistry().bind("myPolicy", policy); + + from("direct:start") + .transacted("myPolicy") + .setHeader("foo", constant(123)) + .to("log:foo") + .to("mock:result"); + } + }); + context.start(); + + getMockEndpoint("mock:result").expectedMessageCount(1); + getMockEndpoint("mock:result").expectedHeaderReceived("foo", 123); + + template.sendBody("direct:start", "Hello World"); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testSetHeaderIssue() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + context.getRegistry().bind("myPolicy", policy); + + from("direct:start") + .setHeader("foo", constant(123)) + // transacted should be first but camel will automatic "correct" this + .transacted("myPolicy") + .to("log:foo") + .to("mock:result"); + } + }); + context.start(); + + getMockEndpoint("mock:result").expectedMessageCount(1); + getMockEndpoint("mock:result").expectedHeaderReceived("foo", 123); + + template.sendBody("direct:start", "Hello World"); + + assertMockEndpointsSatisfied(); + } + +}
