This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-4.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.22.x by this push:
     new 59fe687a1522 CAMEL-24594: camel-platform-http-vertx - Add tests 
verifying REST DSL response marshal failure returns HTTP 500 with empty body 
(not silent 200)
59fe687a1522 is described below

commit 59fe687a152245d121490fe0bf0bfd45daf8bfaa
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Sep 2 19:14:07 2026 +0200

    CAMEL-24594: camel-platform-http-vertx - Add tests verifying REST DSL 
response marshal failure returns HTTP 500 with empty body (not silent 200)
    
    Co-Authored-By: Claude Opus 4.8 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../vertx/VertxRestBindingMarshalFailureTest.java  | 119 +++++++++++++++++++++
 1 file changed, 119 insertions(+)

diff --git 
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxRestBindingMarshalFailureTest.java
 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxRestBindingMarshalFailureTest.java
new file mode 100644
index 000000000000..059e9b05697f
--- /dev/null
+++ 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxRestBindingMarshalFailureTest.java
@@ -0,0 +1,119 @@
+/*
+ * 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.apache.camel.model.rest.RestBindingMode;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.emptyString;
+
+/**
+ * Simulated reproducer for CAMEL-24594: when the REST DSL response binding 
(bindingMode json) fails to marshal the
+ * response body, the failure must be surfaced to the caller as a server error 
(HTTP 500) - it must NOT be silently
+ * returned as an HTTP 200 with an empty body.
+ * <p/>
+ * As {@code muteException} is enabled by default on platform-http, the 
response body must stay empty so no exception or
+ * error message is leaked to the caller.
+ * <p/>
+ * The marshalling failure is simulated with a POJO whose getter throws, which 
makes Jackson fail during serialization
+ * regardless of the configured {@code ObjectMapper} (no dependency on 
java.time / JavaTimeModule required).
+ */
+public class VertxRestBindingMarshalFailureTest {
+
+    @Test
+    public void testResponseMarshalFailureIsNotSilent200() throws Exception {
+        final CamelContext context = 
VertxPlatformHttpEngineTest.createCamelContext();
+
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    restConfiguration().bindingMode(RestBindingMode.json);
+
+                    rest("/demo")
+                            .get("/{id}").to("direct:demo");
+
+                    from("direct:demo")
+                            // the response POJO cannot be marshalled to json
+                            .process(e -> e.getMessage().setBody(new 
BadPojo()));
+                }
+            });
+
+            VertxPlatformHttpEngineTest.startCamelContext(context);
+
+            given()
+                    .when()
+                    .get("/demo/42")
+                    .then()
+                    // a serialization failure must surface as a server error, 
with no exception/message leaked
+                    .statusCode(500)
+                    .body(emptyString());
+        } finally {
+            context.stop();
+        }
+    }
+
+    @Test
+    public void testFailureOriginatesInRestDslBindingMarshal() throws 
Exception {
+        final CamelContext context = 
VertxPlatformHttpEngineTest.createCamelContext();
+
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    restConfiguration().bindingMode(RestBindingMode.json)
+                            // disable muting so the stacktrace is returned - 
only to PROVE where the failure happened
+                            .endpointProperty("muteException", "false");
+
+                    rest("/demo")
+                            .get("/{id}").to("direct:demo");
+
+                    from("direct:demo")
+                            .process(e -> e.getMessage().setBody(new 
BadPojo()));
+                }
+            });
+
+            VertxPlatformHttpEngineTest.startCamelContext(context);
+
+            given()
+                    .when()
+                    .get("/demo/42")
+                    .then()
+                    .statusCode(500)
+                    // the thrown getter exception was surfaced
+                    .body(containsString("Cannot serialize this POJO on 
purpose"))
+                    // ...and it happened while the REST DSL binding 
marshalled the response body
+                    .body(containsString("RestBindingAdvice"))
+                    .body(containsString("MarshalProcessor"));
+        } finally {
+            context.stop();
+        }
+    }
+
+    /**
+     * A POJO that always fails to marshal because its getter throws.
+     */
+    public static class BadPojo {
+        public String getName() {
+            throw new IllegalStateException("Cannot serialize this POJO on 
purpose");
+        }
+    }
+}

Reply via email to