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


The following commit(s) were added to refs/heads/main by this push:
     new 3f720075f48d CAMEL-25249: camel-vertx - reply with a failure when the 
route fails, and also reply without a body (#27246)
3f720075f48d is described below

commit 3f720075f48dab1cba43081078a949924e2e68e3
Author: allthingssecurity <[email protected]>
AuthorDate: Fri Oct 2 17:53:02 2026 +0530

    CAMEL-25249: camel-vertx - reply with a failure when the route fails, and 
also reply without a body (#27246)
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../camel/component/vertx/VertxConsumer.java       | 21 ++++++-
 .../vertx/VertxRequestReplyFailureTest.java        | 68 ++++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_23.adoc    |  9 +++
 3 files changed, 96 insertions(+), 2 deletions(-)

diff --git 
a/components/camel-vertx/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxConsumer.java
 
b/components/camel-vertx/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxConsumer.java
index 98eb9a0b0375..d66e9429193e 100644
--- 
a/components/camel-vertx/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxConsumer.java
+++ 
b/components/camel-vertx/camel-vertx/src/main/java/org/apache/camel/component/vertx/VertxConsumer.java
@@ -31,6 +31,16 @@ public class VertxConsumer extends DefaultConsumer {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(VertxConsumer.class);
 
+    /**
+     * The failure code of the reply when the exchange failed.
+     */
+    static final int FAILURE_CODE = 500;
+
+    /**
+     * The failure message of the reply when the exchange failed: the 
exception of the route is not sent to the sender.
+     */
+    static final String FAILURE_MESSAGE = "Exchange processing failed";
+
     private final VertxEndpoint endpoint;
     private transient MessageConsumer<?> messageConsumer;
 
@@ -54,8 +64,15 @@ public class VertxConsumer extends DefaultConsumer {
                 @Override
                 public void done(boolean doneSync) {
                     if (reply) {
-                        Object body = exchange.getMessage().getBody();
-                        if (body != null) {
+                        Exception cause = exchange.getException();
+                        if (cause != null) {
+                            // let the sender know that the request failed, 
instead of replying with the message body,
+                            // without sending the exception of the route
+                            LOG.debug("Sending failure reply to: {} due to: 
{}", event.replyAddress(), cause.getMessage());
+                            event.fail(FAILURE_CODE, FAILURE_MESSAGE);
+                        } else {
+                            // always reply (also with no body) so the sender 
does not wait until its timeout
+                            Object body = exchange.getMessage().getBody();
                             LOG.debug("Sending reply to: {} with body: {}", 
event.replyAddress(), body);
                             event.reply(body);
                         }
diff --git 
a/components/camel-vertx/camel-vertx/src/test/java/org/apache/camel/component/vertx/VertxRequestReplyFailureTest.java
 
b/components/camel-vertx/camel-vertx/src/test/java/org/apache/camel/component/vertx/VertxRequestReplyFailureTest.java
new file mode 100644
index 000000000000..72327afbae70
--- /dev/null
+++ 
b/components/camel-vertx/camel-vertx/src/test/java/org/apache/camel/component/vertx/VertxRequestReplyFailureTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.vertx;
+
+import io.vertx.core.eventbus.ReplyException;
+import io.vertx.core.eventbus.ReplyFailure;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * The reply of a request/reply over the event bus must tell the sender that 
the route failed, and must also be sent
+ * when the route returns no body.
+ */
+public class VertxRequestReplyFailureTest extends VertxBaseTestSupport {
+
+    @Test
+    public void testFailedRouteRepliesWithFailure() {
+        Exchange out = template.request("direct:fail", e -> 
e.getIn().setBody("Camel"));
+
+        ReplyException cause = assertInstanceOf(ReplyException.class, 
out.getException());
+        assertEquals(ReplyFailure.RECIPIENT_FAILURE, cause.failureType());
+        assertEquals(VertxConsumer.FAILURE_CODE, cause.failureCode());
+        // the exception of the route is not sent to the sender
+        assertEquals(VertxConsumer.FAILURE_MESSAGE, cause.getMessage());
+    }
+
+    @Test
+    public void testNullBodyIsReplied() {
+        Exchange out = template.request("direct:empty", e -> 
e.getIn().setBody("Camel"));
+
+        assertNull(out.getException());
+        assertNull(out.getMessage().getBody());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:fail").to("vertx:foo.fail");
+                from("vertx:foo.fail")
+                        .throwException(new 
IllegalArgumentException("Forced"));
+
+                from("direct:empty").to("vertx:foo.empty");
+                from("vertx:foo.empty")
+                        .setBody(constant(null));
+            }
+        };
+    }
+}
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
index 4d595f816a14..e9800640e408 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
@@ -756,6 +756,15 @@ whose request times out now fails with a 
`TimeoutException`, like `GET`, instead
 An agent that answers with an OID inside the subtree that does not increase 
now also fails the exchange with a
 `CamelExchangeException` ("OID not increasing", like net-snmp's `snmpwalk`), 
instead of repeating the request.
 
+=== camel-vertx - request/reply over the event bus
+
+When a `vertx` consumer receives a message that expects a reply and the route 
fails, the sender now gets a failure
+reply (a `ReplyException` with failure type `RECIPIENT_FAILURE`, failure code 
500 and the message
+`Exchange processing failed`; the exception of the route is not sent to the 
sender). Before, the consumer replied with
+the message body as if the route had succeeded, which usually echoed the 
request back. A route that ends without a
+body now replies with an empty (`null`) body instead of not replying, so the
+sender no longer waits until its reply timeout (30 seconds by default).
+
 === Components and Language removal
 
 ==== camel-csimple, camel-csimple-joor and csimple-maven-plugin

Reply via email to