This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch fix/CAMEL-24149 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 009984ab1271e1a570cb7401a43b27a3bf2fa10e Author: Claus Ibsen <[email protected]> AuthorDate: Fri Jul 17 10:52:49 2026 +0200 CAMEL-24149: camel-saga - SagaProducer reads ExchangeExtension first, survives removeHeaders Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../apache/camel/component/saga/SagaProducer.java | 11 +++- .../saga/SagaProducerRemoveHeadersTest.java | 69 ++++++++++++++++++++++ 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/components/camel-saga/src/main/java/org/apache/camel/component/saga/SagaProducer.java b/components/camel-saga/src/main/java/org/apache/camel/component/saga/SagaProducer.java index 31ee7fc95156..4aa208c648f7 100644 --- a/components/camel-saga/src/main/java/org/apache/camel/component/saga/SagaProducer.java +++ b/components/camel-saga/src/main/java/org/apache/camel/component/saga/SagaProducer.java @@ -44,14 +44,19 @@ public class SagaProducer extends DefaultAsyncProducer { @Override public boolean process(Exchange exchange, AsyncCallback callback) { - String currentSaga = exchange.getIn().getHeader(SagaConstants.SAGA_LONG_RUNNING_ACTION, String.class); - if (currentSaga == null) { + String sagaId = exchange.getExchangeExtension().getSagaLongRunningAction(); + if (sagaId == null) { + sagaId = exchange.getIn().getHeader(SagaConstants.SAGA_LONG_RUNNING_ACTION, String.class); + } + if (sagaId == null) { + String action = success ? "complete" : "compensate"; exchange.setException( - new IllegalStateException("Current exchange is not bound to a saga context: cannot complete")); + new IllegalStateException("Current exchange is not bound to a saga context: cannot " + action)); callback.done(true); return true; } + final String currentSaga = sagaId; camelSagaService.getSaga(currentSaga).thenApply(coordinator -> { if (coordinator == null) { throw new IllegalStateException("No coordinator found for saga id " + currentSaga); diff --git a/core/camel-core/src/test/java/org/apache/camel/component/saga/SagaProducerRemoveHeadersTest.java b/core/camel-core/src/test/java/org/apache/camel/component/saga/SagaProducerRemoveHeadersTest.java new file mode 100644 index 000000000000..52bf95b33124 --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/component/saga/SagaProducerRemoveHeadersTest.java @@ -0,0 +1,69 @@ +/* + * 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.component.saga; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.SagaCompletionMode; +import org.apache.camel.saga.InMemorySagaService; +import org.junit.jupiter.api.Test; + +public class SagaProducerRemoveHeadersTest extends ContextTestSupport { + + @Test + public void testManualCompleteAfterRemoveHeaders() throws InterruptedException { + MockEndpoint completed = getMockEndpoint("mock:completed"); + completed.expectedMessageCount(1); + + template.sendBody("direct:manual-workflow", "manual-complete"); + + completed.assertIsSatisfied(); + } + + @Test + public void testManualCompensateAfterRemoveHeaders() throws InterruptedException { + MockEndpoint compensated = getMockEndpoint("mock:compensated"); + compensated.expectedMessageCount(1); + + template.sendBody("direct:manual-workflow", "manual-compensate"); + + compensated.assertIsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + + context.addService(new InMemorySagaService()); + + from("direct:manual-workflow") + .saga().compensation("mock:compensated").completion("mock:completed") + .completionMode(SagaCompletionMode.MANUAL) + .removeHeaders("*") + .choice() + .when(body().isEqualTo(constant("manual-complete"))) + .to("saga:complete") + .when(body().isEqualTo(constant("manual-compensate"))) + .to("saga:compensate") + .end(); + } + }; + } +}
