This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.10.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.10.x by this push:
new cd46568fe0e CAMEL-22251: platform-http-vertx: Fix when exchange is
failed to not remove the caused excep tion which then otherwise leads to
UnitOfwork seeing the exchange as completed succesfully instead of failed.
(#18659)
cd46568fe0e is described below
commit cd46568fe0e42b3201c76a4cb5aebb5c5962d161
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Jul 21 11:22:54 2025 +0200
CAMEL-22251: platform-http-vertx: Fix when exchange is failed to not remove
the caused excep tion which then otherwise leads to UnitOfwork seeing the
exchange as completed succesfully instead of failed. (#18659)
* CAMEL-22251: platform-http-vertx: Fix when exchange is failed to not
remove the caused exception which then otherwise leads to UnitOfwork seeing the
exchange as completed succesfully instead of failed.
---
components/camel-jetty/pom.xml | 6 ++
.../component/jetty/JettyEventNotifierTest.java | 110 ++++++++++++++++++++
.../http/vertx/VertxPlatformHttpSupport.java | 3 -
.../http/vertx/VertxPlatformEventNotifierTest.java | 111 +++++++++++++++++++++
.../http/vertx/VertxPlatformHttpBasicTest.java | 83 +++++++++++++++
5 files changed, 310 insertions(+), 3 deletions(-)
diff --git a/components/camel-jetty/pom.xml b/components/camel-jetty/pom.xml
index 95a822b7874..fa843d48428 100644
--- a/components/camel-jetty/pom.xml
+++ b/components/camel-jetty/pom.xml
@@ -159,6 +159,12 @@
<version>${squareup-okhttp-version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>io.rest-assured</groupId>
+ <artifactId>rest-assured</artifactId>
+ <version>${rest-assured-version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
diff --git
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEventNotifierTest.java
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEventNotifierTest.java
new file mode 100644
index 00000000000..eadf3ca5806
--- /dev/null
+++
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyEventNotifierTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.jetty;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.CamelEvent;
+import org.apache.camel.support.EventNotifierSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.is;
+
+public class JettyEventNotifierTest extends BaseJettyTest {
+
+ private final List<String> events = new ArrayList<>();
+
+ @Test
+ void testEventNotifierOk() throws Exception {
+ context.getManagementStrategy().addEventNotifier(new
MyEventListener());
+ events.clear();
+
+ try {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("jetty:http://0.0.0.0:{{port}}/camel/ok").routeId("jetty")
+ .setBody().constant("Bye World");
+ }
+ });
+
+ context.start();
+
+ given()
+ .port(getPort())
+ .body("Hello World")
+ .post("/camel/ok")
+ .then()
+ .statusCode(200)
+ .body(is("Bye World"));
+
+ Assertions.assertEquals(2, events.size());
+ Assertions.assertEquals("ExchangeCreated (failed:false)",
events.get(0));
+ Assertions.assertEquals("ExchangeCompleted (failed:false)",
events.get(1));
+ } finally {
+ context.stop();
+ }
+ }
+
+ @Test
+ void testEventNotifierError() throws Exception {
+ context.getManagementStrategy().addEventNotifier(new
MyEventListener());
+ events.clear();
+
+ try {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+
from("jetty:http://0.0.0.0:{{port}}/camel/fail").routeId("jetty")
+ .throwException(new
IllegalArgumentException("Forced error"));
+ }
+ });
+
+ context.start();
+
+ given()
+ .port(getPort())
+ .body("Hello World")
+ .post("/camel/fail")
+ .then()
+ .statusCode(500)
+ .body(is(""));
+
+ Assertions.assertEquals(2, events.size());
+ Assertions.assertEquals("ExchangeCreated (failed:false)",
events.get(0));
+ Assertions.assertEquals("ExchangeFailed (failed:true)",
events.get(1));
+ } finally {
+ context.stop();
+ }
+ }
+
+ class MyEventListener extends EventNotifierSupport {
+
+ public void notify(CamelEvent event) throws Exception {
+ if (event.getSource() instanceof Exchange) {
+ Exchange ex = (Exchange) event.getSource();
+ events.add(event.getType().name() + " (failed:" +
ex.isFailed() + ")");
+ }
+ }
+ }
+
+}
diff --git
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSupport.java
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSupport.java
index d084778a578..c0683453834 100644
---
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSupport.java
+++
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpSupport.java
@@ -41,7 +41,6 @@ import org.apache.camel.NoTypeConversionAvailableException;
import org.apache.camel.TypeConverter;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.support.ExceptionHelper;
-import org.apache.camel.support.ExchangeHelper;
import org.apache.camel.support.MessageHelper;
import org.apache.camel.support.ObjectHelper;
import org.apache.camel.support.http.HttpUtil;
@@ -122,8 +121,6 @@ public final class VertxPlatformHttpSupport {
message.setHeader(Exchange.CONTENT_TYPE,
DEFAULT_CONTENT_TYPE_ON_EXCEPTION);
}
- // and mark the exception as failure handled, as we handled it by
returning it as the response
- ExchangeHelper.setFailureHandled(exchange);
return body;
}
diff --git
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformEventNotifierTest.java
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformEventNotifierTest.java
new file mode 100644
index 00000000000..92ab4e36ca3
--- /dev/null
+++
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformEventNotifierTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.platform.http.vertx;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.CamelEvent;
+import org.apache.camel.support.EventNotifierSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.is;
+
+public class VertxPlatformEventNotifierTest {
+
+ private final List<String> events = new ArrayList<>();
+
+ @Test
+ void testEventNotifierOk() throws Exception {
+ final CamelContext context =
VertxPlatformHttpEngineTest.createCamelContext();
+ context.getManagementStrategy().addEventNotifier(new
MyEventListener());
+ events.clear();
+
+ try {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("platform-http:/camel/ok")
+ .setBody().constant("Bye World");
+ }
+ });
+
+ context.start();
+
+ given()
+ .body("Hello World")
+ .post("/camel/ok")
+ .then()
+ .statusCode(200)
+ .body(is("Bye World"));
+
+ Assertions.assertEquals(2, events.size());
+ Assertions.assertEquals("ExchangeCreated (failed:false)",
events.get(0));
+ Assertions.assertEquals("ExchangeCompleted (failed:false)",
events.get(1));
+ } finally {
+ context.stop();
+ }
+ }
+
+ @Test
+ void testEventNotifierError() throws Exception {
+ final CamelContext context =
VertxPlatformHttpEngineTest.createCamelContext();
+ context.getManagementStrategy().addEventNotifier(new
MyEventListener());
+ events.clear();
+
+ try {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("platform-http:/camel/fail")
+ .throwException(new
IllegalArgumentException("Forced error"));
+ }
+ });
+
+ context.start();
+
+ given()
+ .body("Hello World")
+ .post("/camel/fail")
+ .then()
+ .statusCode(500)
+ .body(is(""));
+
+ Assertions.assertEquals(2, events.size());
+ Assertions.assertEquals("ExchangeCreated (failed:false)",
events.get(0));
+ Assertions.assertEquals("ExchangeFailed (failed:true)",
events.get(1));
+ } finally {
+ context.stop();
+ }
+ }
+
+ class MyEventListener extends EventNotifierSupport {
+
+ public void notify(CamelEvent event) throws Exception {
+ if (event.getSource() instanceof Exchange) {
+ Exchange ex = (Exchange) event.getSource();
+ events.add(event.getType().name() + " (failed:" +
ex.isFailed() + ")");
+ }
+ }
+ }
+
+}
diff --git
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpBasicTest.java
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpBasicTest.java
new file mode 100644
index 00000000000..cc81b7e4d93
--- /dev/null
+++
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpBasicTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.platform.http.vertx;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.is;
+
+public class VertxPlatformHttpBasicTest {
+
+ @Test
+ void testBasicOk() throws Exception {
+ final CamelContext context =
VertxPlatformHttpEngineTest.createCamelContext();
+
+ try {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("platform-http:/camel/ok")
+ .setBody().constant("Bye World");
+
+ from("platform-http:/camel/fail")
+ .throwException(new
IllegalArgumentException("Forced error"));
+ }
+ });
+
+ context.start();
+
+ given()
+ .body("Hello World")
+ .post("/camel/ok")
+ .then()
+ .statusCode(200)
+ .body(is("Bye World"));
+ } finally {
+ context.stop();
+ }
+ }
+
+ @Test
+ void testBasicError() throws Exception {
+ final CamelContext context =
VertxPlatformHttpEngineTest.createCamelContext();
+
+ try {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("platform-http:/camel/fail")
+ .throwException(new
IllegalArgumentException("Forced error"));
+ }
+ });
+
+ context.start();
+
+ given()
+ .body("Hello World")
+ .post("/camel/fail")
+ .then()
+ .statusCode(500)
+ .body(is(""));
+ } finally {
+ context.stop();
+ }
+ }
+
+}