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

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7b88dff41e5efa8bc70580839448384ecfd1c7d0
Author: Pasquale Congiusti <pasquale.congiu...@gmail.com>
AuthorDate: Mon Apr 21 15:15:58 2025 +0200

    feat(main): base development to include management port
    
    Ref CAMEL-21950
---
 .../component/knative/http/KnativeHttpTestSupport.java  |  7 +++++--
 .../component/platform/http/main/MainHttpServer.java    |  4 ++--
 .../platform/http/vertx/VertxPlatformHttpConsumer.java  |  7 +++++--
 .../platform/http/vertx/VertxPlatformHttpEngine.java    | 12 ++++++++++--
 .../platform/http/vertx/VertxPlatformHttpRouter.java    | 17 ++++++++++++++---
 .../platform/http/vertx/VertxPlatformHttpServer.java    |  5 +++--
 .../http/vertx/VertxPlatformHttpEngineTest.java         |  6 ++++--
 .../http/vertx/VertxPlatformHttpPooledExchangeTest.java |  3 ++-
 .../java/org/apache/camel/main/BaseMainSupport.java     | 10 ++++++++++
 9 files changed, 55 insertions(+), 16 deletions(-)

diff --git 
a/components/camel-knative/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTestSupport.java
 
b/components/camel-knative/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTestSupport.java
index b37f3ca9d75..6756d4e2633 100644
--- 
a/components/camel-knative/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTestSupport.java
+++ 
b/components/camel-knative/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTestSupport.java
@@ -20,6 +20,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
+import io.restassured.RestAssured;
 import org.apache.camel.CamelContext;
 import org.apache.camel.cloudevents.CloudEvent;
 import org.apache.camel.component.knative.KnativeComponent;
@@ -60,14 +61,16 @@ public final class KnativeHttpTestSupport {
             @Override
             protected void doBuild() throws Exception {
                 super.doBuild();
-                this.setRouter(VertxPlatformHttpRouter.lookup(context));
+                this.setRouter(VertxPlatformHttpRouter.lookup(context,
+                        
VertxPlatformHttpRouter.getRouterNameFromPort(RestAssured.port)));
             }
         });
         component.setProducerFactory(new KnativeHttpProducerFactory(context) {
             @Override
             protected void doBuild() throws Exception {
                 super.doBuild();
-                this.setVertx(VertxPlatformHttpRouter.lookup(context).vertx());
+                this.setVertx(VertxPlatformHttpRouter
+                        .lookup(context, 
VertxPlatformHttpRouter.getRouterNameFromPort(RestAssured.port)).vertx());
             }
         });
 
diff --git 
a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java
 
b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java
index 67120cf2470..4a2bf6c2481 100644
--- 
a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java
+++ 
b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java
@@ -435,9 +435,9 @@ public class MainHttpServer extends ServiceSupport 
implements CamelContextAware,
     @Override
     protected void doStart() throws Exception {
         ObjectHelper.notNull(camelContext, "CamelContext");
-
         ServiceHelper.startService(server, pluginRegistry, producer, consumer);
-        router = VertxPlatformHttpRouter.lookup(camelContext);
+        String routerName = 
VertxPlatformHttpRouter.getRouterNameFromPort(getPort());
+        router = VertxPlatformHttpRouter.lookup(camelContext, routerName);
         platformHttpComponent = camelContext.getComponent("platform-http", 
PlatformHttpComponent.class);
 
         setupConsoles();
diff --git 
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
 
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
index 05b77e1dce8..94a17da24c3 100644
--- 
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
+++ 
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java
@@ -84,10 +84,12 @@ public class VertxPlatformHttpConsumer extends 
DefaultConsumer
     private VertxPlatformHttpRouter router;
     private HttpRequestBodyHandler httpRequestBodyHandler;
     private CookieConfiguration cookieConfiguration;
+    private final String routerName;
 
     public VertxPlatformHttpConsumer(PlatformHttpEndpoint endpoint,
                                      Processor processor,
-                                     List<Handler<RoutingContext>> handlers) {
+                                     List<Handler<RoutingContext>> handlers,
+                                     String routerName) {
         super(endpoint, processor);
 
         this.handlers = handlers;
@@ -95,6 +97,7 @@ public class VertxPlatformHttpConsumer extends DefaultConsumer
                 = endpoint.getFileNameExtWhitelist() == null ? null : 
endpoint.getFileNameExtWhitelist().toLowerCase(Locale.US);
         this.muteExceptions = endpoint.isMuteException();
         this.handleWriteResponseError = endpoint.isHandleWriteResponseError();
+        this.routerName = routerName;
     }
 
     @Override
@@ -107,7 +110,7 @@ public class VertxPlatformHttpConsumer extends 
DefaultConsumer
         super.doInit();
         methods = Method.parseList(getEndpoint().getHttpMethodRestrict());
         path = configureEndpointPath(getEndpoint());
-        router = 
VertxPlatformHttpRouter.lookup(getEndpoint().getCamelContext());
+        router = 
VertxPlatformHttpRouter.lookup(getEndpoint().getCamelContext(), routerName);
         if (!getEndpoint().isHttpProxy() && getEndpoint().isUseStreaming()) {
             httpRequestBodyHandler = new 
StreamingHttpRequestBodyHandler(router.bodyHandler());
         } else if (!getEndpoint().isHttpProxy() && 
!getEndpoint().isUseBodyHandler()) {
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 3ed88761ac9..79886763149 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
@@ -90,7 +90,8 @@ public class VertxPlatformHttpEngine extends ServiceSupport 
implements PlatformH
         return new VertxPlatformHttpConsumer(
                 endpoint,
                 processor,
-                handlers);
+                handlers,
+                
VertxPlatformHttpRouter.getRouterNameFromPort(getServerPort()));
     }
 
     @Override
@@ -108,12 +109,19 @@ public class VertxPlatformHttpEngine extends 
ServiceSupport implements PlatformH
                 }
             }
             if (port == 0) {
-                VertxPlatformHttpRouter router = 
VertxPlatformHttpRouter.lookup(camelContext);
+                VertxPlatformHttpRouter router
+                        = CamelContextHelper.findSingleByType(camelContext, 
VertxPlatformHttpRouter.class);
                 if (router != null && router.getServer() != null && 
router.getServer().getServer() != null) {
                     port = router.getServer().getServer().actualPort();
                 }
             }
+
+            if (port == 0) {
+                //fallback to default
+                return 8080;
+            }
         }
+
         return port;
     }
 }
diff --git 
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpRouter.java
 
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpRouter.java
index 2e3e17ba980..9fa653ee676 100644
--- 
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpRouter.java
+++ 
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpRouter.java
@@ -35,16 +35,18 @@ import org.apache.camel.support.CamelContextHelper;
 public class VertxPlatformHttpRouter implements Router {
     public static final String PLATFORM_HTTP_ROUTER_NAME = 
PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME + "-router";
 
+    private final String name;
     private final VertxPlatformHttpServer server;
     private final Vertx vertx;
     private final Router delegate;
     private AllowForwardHeaders allowForward;
 
-    public VertxPlatformHttpRouter(VertxPlatformHttpServer server, Vertx 
vertx, Router delegate) {
+    public VertxPlatformHttpRouter(VertxPlatformHttpServer server, Vertx 
vertx, Router delegate, String name) {
         this.server = server;
         this.vertx = vertx;
         this.delegate = delegate;
         this.allowForward = AllowForwardHeaders.NONE;
+        this.name = name;
     }
 
     public Vertx vertx() {
@@ -55,6 +57,10 @@ public class VertxPlatformHttpRouter implements Router {
         return server;
     }
 
+    public String getName() {
+        return this.name;
+    }
+
     @Override
     public Route route() {
         return delegate.route();
@@ -286,10 +292,15 @@ public class VertxPlatformHttpRouter implements Router {
     //
     // **********************
 
-    public static VertxPlatformHttpRouter lookup(CamelContext camelContext) {
+    public static VertxPlatformHttpRouter lookup(CamelContext camelContext, 
String routerName) {
         return CamelContextHelper.mandatoryLookup(
                 camelContext,
-                VertxPlatformHttpRouter.PLATFORM_HTTP_ROUTER_NAME,
+                routerName,
                 VertxPlatformHttpRouter.class);
     }
+
+    public static String getRouterNameFromPort(int port) {
+        return VertxPlatformHttpRouter.PLATFORM_HTTP_ROUTER_NAME + "-" + port;
+    }
+
 }
diff --git 
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
 
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
index d7e225d099f..698ed330145 100644
--- 
a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
+++ 
b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServer.java
@@ -197,9 +197,10 @@ public class VertxPlatformHttpServer extends 
ServiceSupport implements CamelCont
 
         router.route(configuration.getPath() + "*").subRouter(subRouter);
 
+        String routerName = 
VertxPlatformHttpRouter.getRouterNameFromPort(configuration.getPort());
         context.getRegistry().bind(
-                VertxPlatformHttpRouter.PLATFORM_HTTP_ROUTER_NAME,
-                new VertxPlatformHttpRouter(this, vertx, subRouter) {
+                routerName,
+                new VertxPlatformHttpRouter(this, vertx, subRouter, 
routerName) {
                     @Override
                     public Handler<RoutingContext> bodyHandler() {
                         return createBodyHandler(getCamelContext(), 
configuration);
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 1ec67a4bc51..bb989a32874 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
@@ -127,7 +127,8 @@ public class VertxPlatformHttpEngineTest {
         try {
             context.start();
 
-            assertThat(VertxPlatformHttpRouter.lookup(context)).isNotNull();
+            assertThat(VertxPlatformHttpRouter.lookup(context, 
VertxPlatformHttpRouter.getRouterNameFromPort(RestAssured.port)))
+                    .isNotNull();
             
assertThat(context.getComponent("platform-http")).isInstanceOfSatisfying(PlatformHttpComponent.class,
 component -> {
                 
assertThat(component.getEngine()).isInstanceOf(VertxPlatformHttpEngine.class);
             });
@@ -678,7 +679,8 @@ public class VertxPlatformHttpEngineTest {
         try {
             context.start();
 
-            VertxPlatformHttpRouter router = 
VertxPlatformHttpRouter.lookup(context);
+            VertxPlatformHttpRouter router
+                    = VertxPlatformHttpRouter.lookup(context, 
VertxPlatformHttpRouter.getRouterNameFromPort(RestAssured.port));
             router.route().order(0).handler(basicAuthHandler);
 
             RestAssured.get("/secure")
diff --git 
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpPooledExchangeTest.java
 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpPooledExchangeTest.java
index 05083e3a2f3..1ca531ce878 100644
--- 
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpPooledExchangeTest.java
+++ 
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpPooledExchangeTest.java
@@ -45,7 +45,8 @@ public class VertxPlatformHttpPooledExchangeTest {
         try {
             context.start();
 
-            assertThat(VertxPlatformHttpRouter.lookup(context)).isNotNull();
+            assertThat(VertxPlatformHttpRouter.lookup(context, 
VertxPlatformHttpRouter.getRouterNameFromPort(RestAssured.port)))
+                    .isNotNull();
             
assertThat(context.getComponent("platform-http")).isInstanceOfSatisfying(PlatformHttpComponent.class,
 component -> {
                 
assertThat(component.getEngine()).isInstanceOf(VertxPlatformHttpEngine.class);
             });
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 5f3ee73f5b2..2505843ddef 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -1886,6 +1886,8 @@ public abstract class BaseMainSupport extends BaseService 
{
             return;
         }
 
+        System.out.println("********* Starting server on port " + 
server.getPort());
+
         // auto-detect camel-platform-http-main on classpath
         MainHttpServerFactory sf = resolveMainHttpServerFactory(camelContext);
         // create http server as a service managed by camel context
@@ -1893,6 +1895,14 @@ public abstract class BaseMainSupport extends 
BaseService {
         // force eager starting as embedded http server is used for
         // container platform to check readiness and need to be started eager
         camelContext.addService(http, true, true);
+
+        // TODO just test POC
+        HttpServerConfigurationProperties server2 = 
mainConfigurationProperties.httpServer();
+        setPropertiesOnTarget(camelContext, server2, properties, 
"camel.server.",
+                mainConfigurationProperties.isAutoConfigurationFailFast(), 
true, autoConfiguredProperties);
+        server2.setPort(9876);
+        Service http2 = sf.newHttpServer(camelContext, server2);
+        camelContext.addService(http2, true, true);
     }
 
     private void setVaultProperties(

Reply via email to