This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch CAMEL-22937 in repository https://gitbox.apache.org/repos/asf/camel.git
commit fa35650171ac5423407f9149a822d2a39903c045 Author: Andrea Cosentino <[email protected]> AuthorDate: Mon Feb 2 15:24:55 2026 +0100 CAMEL-22937 - camel-jbang: using different custom ports for both embedded and management server runs into an error Signed-off-by: Andrea Cosentino <[email protected]> --- .../http/vertx/VertxPlatformHttpEngine.java | 16 +++++++ .../http/vertx/VertxPlatformHttpEngineTest.java | 54 ++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngine.java b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngine.java index 3f92369b45a4..4498d0f90a9a 100644 --- a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngine.java +++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngine.java @@ -19,6 +19,7 @@ package org.apache.camel.component.platform.http.vertx; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import io.vertx.core.Handler; import io.vertx.ext.web.RoutingContext; @@ -115,6 +116,21 @@ public class VertxPlatformHttpEngine extends ServiceSupport implements PlatformH port = router.getServer().getServer().actualPort(); } } + // When there are multiple servers (e.g., main server and management server), + // findSingleByType returns null. In this case, look for any available router + // registered in the registry and use its server port. + if (port == 0) { + Map<String, VertxPlatformHttpRouter> routers + = camelContext.getRegistry().findByTypeWithName(VertxPlatformHttpRouter.class); + for (VertxPlatformHttpRouter router : routers.values()) { + if (router.getServer() != null && router.getServer().getServer() != null) { + port = router.getServer().getServer().actualPort(); + if (port > 0) { + break; + } + } + } + } if (port == 0) { //fallback to default diff --git a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java index 6cf069d9df7b..15e8082ec9e7 100644 --- a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java +++ b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java @@ -1223,6 +1223,60 @@ public class VertxPlatformHttpEngineTest { } } + @Test + public void testMultipleServersScenario() throws Exception { + // This test simulates CAMEL-22937: when both main server and management server are running, + // findSingleByType returns null because there are multiple instances of VertxPlatformHttpServer. + // The engine should still be able to find a valid router port. + int mainPort = AvailablePortFinder.getNextAvailable(); + int managementPort = AvailablePortFinder.getNextAvailable(); + + VertxPlatformHttpServerConfiguration mainConf = new VertxPlatformHttpServerConfiguration(); + mainConf.setBindPort(mainPort); + + VertxPlatformHttpServerConfiguration managementConf = new VertxPlatformHttpServerConfiguration(); + managementConf.setBindPort(managementPort); + + RestAssured.port = mainPort; + + CamelContext context = new DefaultCamelContext(); + // Add two servers to simulate main + management server scenario + context.addService(new VertxPlatformHttpServer(mainConf)); + context.addService(new VertxPlatformHttpServer(managementConf)); + + try { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("platform-http:/test") + .routeId("test") + .setBody().constant("test-response"); + } + }); + + context.start(); + + // Verify the engine can find a valid port even with multiple servers + PlatformHttpEngine engine = context.getRegistry().findSingleByType(PlatformHttpEngine.class); + assertNotNull(engine); + int serverPort = engine.getServerPort(); + // The port should be one of the configured ports, not the default 8080 + assertThat(serverPort).isIn(mainPort, managementPort); + + // Verify the route works on the correct port + given() + .port(serverPort) + .when() + .get("/test") + .then() + .statusCode(200) + .body(equalTo("test-response")); + + } finally { + context.stop(); + } + } + static CamelContext createCamelContext() throws Exception { return createCamelContext(null); }
