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 56ea9dd9ce68 CAMEL-27997: camel-platform-http - dev consoles print the
right server URLs (#31225)
56ea9dd9ce68 is described below
commit 56ea9dd9ce68cdbbe408581f59697dd62460c510
Author: Adriano Machado <[email protected]>
AuthorDate: Thu Dec 3 14:24:11 2026 -0500
CAMEL-27997: camel-platform-http - dev consoles print the right server URLs
(#31225)
* CAMEL-27997: camel-platform-http - dev consoles print the right server
URLs
* CAMEL-27997: camel-platform-http-main - call super.doStop() in the server
lifecycle
* CAMEL-27997: camel-platform-http-main - include the context path and bind
host in the dev console URLs
* CAMEL-27997: camel-platform-http - update the description of the server
URL of the console
Co-authored-by: Claude <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
---
.../apache/camel/catalog/dev-consoles-openapi.json | 6 +-
.../camel/catalog/dev-consoles/platform-http.json | 6 +-
.../platform/http/main/MainHttpServer.java | 33 +++++
.../http/main/MainHttpServerDevConsole.java | 8 +-
.../platform/http/main/ManagementHttpServer.java | 10 ++
.../http/main/PlatformHttpDevConsoleUrlTest.java | 163 +++++++++++++++++++++
.../http/vertx/VertxPlatformHttpServer.java | 12 ++
.../vertx/VertxPlatformHttpServerSchemeTest.java | 73 +++++++++
.../apache/camel/dev-console/platform-http.json | 6 +-
.../platform/http/PlatformHttpComponent.java | 27 ++++
.../platform/http/PlatformHttpConsole.java | 79 ++++++----
11 files changed, 384 insertions(+), 39 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
index 23f849db51e7..35eacfc83e6f 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
@@ -5364,7 +5364,11 @@
"properties": {
"server": {
"type": "string",
-
"description": "The base URL of the endpoints: always http:\/\/0.0.0.0,
with the port of the server when known (only present when the platform-http
component exists)"
+
"description": "The base URL of the endpoints: scheme, bind host, port
and context path of the server when known, otherwise http:\/\/0.0.0.0 with the
port of the engine (only present when the platform-http component exists)"
+
},
+
"managementServer": {
+
"type": "string",
+
"description": "The base URL of the server of the management endpoints,
which can differ from the server when they have their own port (only present
when there are management endpoints)"
},
"endpoints": {
"type": "array",
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/platform-http.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/platform-http.json
index 5d103fae1eda..9f975626be16 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/platform-http.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/platform-http.json
@@ -17,7 +17,11 @@
"properties": {
"server": {
"type": "string",
- "description": "The base URL of the endpoints: always
http:\/\/0.0.0.0, with the port of the server when known (only present when the
platform-http component exists)"
+ "description": "The base URL of the endpoints: scheme, bind host, port
and context path of the server when known, otherwise http:\/\/0.0.0.0 with the
port of the engine (only present when the platform-http component exists)"
+ },
+ "managementServer": {
+ "type": "string",
+ "description": "The base URL of the server of the management
endpoints, which can differ from the server when they have their own port (only
present when there are management endpoints)"
},
"endpoints": {
"type": "array",
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 799a733de68b..a3159f009efe 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
@@ -138,6 +138,11 @@ public class MainHttpServer extends ServiceSupport
implements CamelContextAware,
configuration.setBindPort(port);
}
+ @ManagedAttribute(description = "HTTP scheme (http or https)")
+ public String getScheme() {
+ return server != null ? server.getScheme() : "http";
+ }
+
@ManagedAttribute(description = "HTTP server hostname")
public String getHost() {
return configuration.getBindHost();
@@ -214,6 +219,24 @@ public class MainHttpServer extends ServiceSupport
implements CamelContextAware,
camelContext.addService(server);
}
+ /**
+ * The base URL where the endpoints of the given server are served:
scheme, bind host, port and context path
+ * (without a trailing slash).
+ */
+ static String baseUrl(VertxPlatformHttpServer server) {
+ return server.getScheme() + "://" + server.getHost() + ":" +
server.getPort() + normalizePath(server.getPath());
+ }
+
+ /**
+ * The context path with a leading slash and no trailing slash, or empty
for the root path.
+ */
+ static String normalizePath(String path) {
+ if (path == null || "/".equals(path)) {
+ return "";
+ }
+ return path.endsWith("/") ? path.substring(0, path.length() - 1) :
path;
+ }
+
@Override
protected void doStart() throws Exception {
ObjectHelper.notNull(camelContext, "CamelContext");
@@ -221,11 +244,21 @@ public class MainHttpServer extends ServiceSupport
implements CamelContextAware,
String routerName =
VertxPlatformHttpRouter.getRouterNameFromPort(getPort());
router = VertxPlatformHttpRouter.lookup(camelContext, routerName);
platformHttpComponent = camelContext.getComponent("platform-http",
PlatformHttpComponent.class);
+ // tell the dev console where the endpoints are served
+ platformHttpComponent.setServerUrl(baseUrl(server));
setupConsoles();
setupStartupSummary();
}
+ @Override
+ protected void doStop() throws Exception {
+ if (platformHttpComponent != null) {
+ platformHttpComponent.setServerUrl(null);
+ }
+ super.doStop();
+ }
+
protected void setupConsoles() {
if (staticEnabled) {
setupStatic();
diff --git
a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServerDevConsole.java
b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServerDevConsole.java
index 3514926763a9..f7c7cbcadfa4 100644
---
a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServerDevConsole.java
+++
b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServerDevConsole.java
@@ -48,12 +48,8 @@ public class MainHttpServerDevConsole extends
AbstractDevConsole {
MainHttpServer server =
getCamelContext().hasService(MainHttpServer.class);
if (server != null) {
- String p = server.getPath();
- if (p != null && p.startsWith("/")) {
- p = p.substring(1);
- }
- String url = String.format("%s:%s%s", server.getHost(),
server.getPort(), p);
- sb.append(String.format(" Server: http://%s", url));
+ sb.append(String.format(" Server: %s://%s:%s%s",
server.getScheme(), server.getHost(), server.getPort(),
+ MainHttpServer.normalizePath(server.getPath())));
if (server.getMaxBodySize() != null) {
sb.append(String.format("%n Max Body Size: %s",
server.getMaxBodySize()));
}
diff --git
a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/ManagementHttpServer.java
b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/ManagementHttpServer.java
index 1f0b9381fb78..ead20e699271 100644
---
a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/ManagementHttpServer.java
+++
b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/ManagementHttpServer.java
@@ -493,11 +493,21 @@ public class ManagementHttpServer extends ServiceSupport
implements CamelContext
String routerName =
VertxPlatformHttpRouter.getRouterNameFromPort(getPort());
router = VertxPlatformHttpRouter.lookup(camelContext, routerName);
platformHttpComponent = camelContext.getComponent("platform-http",
PlatformHttpComponent.class);
+ // tell the dev console where the endpoints are served
+
platformHttpComponent.setManagementServerUrl(MainHttpServer.baseUrl(server));
setupConsoles();
setupStartupSummary();
}
+ @Override
+ protected void doStop() throws Exception {
+ if (platformHttpComponent != null) {
+ platformHttpComponent.setManagementServerUrl(null);
+ }
+ super.doStop();
+ }
+
@Override
protected void doShutdown() throws Exception {
ServiceHelper.stopAndShutdownServices(pluginRegistry);
diff --git
a/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/PlatformHttpDevConsoleUrlTest.java
b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/PlatformHttpDevConsoleUrlTest.java
new file mode 100644
index 000000000000..ba0fbbd4a53e
--- /dev/null
+++
b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/PlatformHttpDevConsoleUrlTest.java
@@ -0,0 +1,163 @@
+/*
+ * 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.main;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.console.DevConsole;
+import org.apache.camel.main.Main;
+import org.apache.camel.support.PluginHelper;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The dev consoles print the URLs the endpoints are really reached with: the
management endpoints on the port of the
+ * management server when it has its own, and the context path of the HTTP
server with its leading slash. Users copy
+ * these URLs (and the Camel CLI shows them), so a wrong port or a missing
slash sends them to a server that does not
+ * answer.
+ */
+class PlatformHttpDevConsoleUrlTest {
+
+ @RegisterExtension
+ AvailablePortFinder.Port port = AvailablePortFinder.find();
+
+ @RegisterExtension
+ AvailablePortFinder.Port managementPort = AvailablePortFinder.find();
+
+ private Main main;
+
+ @AfterEach
+ void stopMain() {
+ if (main != null) {
+ main.stop();
+ }
+ }
+
+ @Test
+ void managementEndpointsOnTheirOwnPort() {
+ startMain("camel.management.port",
Integer.toString(managementPort.getPort()));
+
+ String server = "http://0.0.0.0:" + port.getPort();
+ String managementServer = "http://0.0.0.0:" + managementPort.getPort();
+
+ JsonObject json = callJson("platform-http");
+ assertEquals(server, json.getString("server"));
+ assertEquals(managementServer, json.getString("managementServer"));
+ assertEquals(server + "/hello", url(json, "endpoints", "/hello"));
+ assertEquals(managementServer + "/observe/info", url(json,
"managementEndpoints", "/observe/info"));
+
+ String text = callText("platform-http");
+ assertTrue(text.contains(server + "/hello"), text);
+ assertTrue(text.contains(managementServer + "/observe/info"), text);
+ assertFalse(text.contains(server + "/observe/info"), text);
+ }
+
+ @Test
+ void managementEndpointsSharingThePortOfTheHttpServer() {
+ startMain("camel.management.port", Integer.toString(port.getPort()));
+
+ String server = "http://0.0.0.0:" + port.getPort();
+
+ JsonObject json = callJson("platform-http");
+ assertEquals(server, json.getString("server"));
+ assertEquals(server, json.getString("managementServer"));
+ assertEquals(server + "/observe/info", url(json,
"managementEndpoints", "/observe/info"));
+ }
+
+ @Test
+ void mainHttpServerKeepsTheSlashOfThePath() {
+ startMain("camel.management.port",
Integer.toString(managementPort.getPort()),
+ "camel.server.path", "/api");
+
+ String server = "http://0.0.0.0:" + port.getPort() + "/api";
+ String text = callText("main-http-server");
+ assertTrue(text.contains("Server: " + server), text);
+
+ // the endpoints are served below the context path of the server
+ JsonObject json = callJson("platform-http");
+ assertEquals(server, json.getString("server"));
+ assertEquals(server + "/hello", url(json, "endpoints", "/hello"));
+ }
+
+ @Test
+ void managementServerKeepsItsOwnPath() {
+ startMain("camel.management.port",
Integer.toString(managementPort.getPort()),
+ "camel.management.path", "/mgmt/");
+
+ String managementServer = "http://0.0.0.0:" + managementPort.getPort()
+ "/mgmt";
+
+ JsonObject json = callJson("platform-http");
+ assertEquals(managementServer, json.getString("managementServer"));
+ assertEquals(managementServer + "/observe/info", url(json,
"managementEndpoints", "/observe/info"));
+ }
+
+ @Test
+ void rootPathDoesNotEndWithASlash() {
+ startMain("camel.management.port",
Integer.toString(managementPort.getPort()));
+
+ String text = callText("main-http-server");
+ assertTrue(text.matches("(?s)\\s*Server: http://0\\.0\\.0\\.0:" +
port.getPort() + "\\R.*"), text);
+ }
+
+ private void startMain(String... properties) {
+ main = new Main();
+ main.configure().addRoutesBuilder(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("platform-http:/hello").setBody(constant("Hello"));
+ }
+ });
+ main.addOverrideProperty("camel.server.enabled", "true");
+ main.addOverrideProperty("camel.server.port",
Integer.toString(port.getPort()));
+ main.addOverrideProperty("camel.management.enabled", "true");
+ main.addOverrideProperty("camel.management.infoEnabled", "true");
+ for (int i = 0; i < properties.length; i += 2) {
+ main.addOverrideProperty(properties[i], properties[i + 1]);
+ }
+ main.start();
+ }
+
+ private DevConsole console(String id) {
+ return
PluginHelper.getDevConsoleResolver(main.getCamelContext()).resolveDevConsole(id);
+ }
+
+ private String callText(String id) {
+ return (String) console(id).call(DevConsole.MediaType.TEXT);
+ }
+
+ private JsonObject callJson(String id) {
+ return (JsonObject) console(id).call(DevConsole.MediaType.JSON);
+ }
+
+ private static String url(JsonObject json, String key, String path) {
+ JsonArray endpoints = (JsonArray) json.get(key);
+ for (Object o : endpoints) {
+ JsonObject endpoint = (JsonObject) o;
+ if (path.equals(endpoint.getString("path"))) {
+ return endpoint.getString("url");
+ }
+ }
+ return null;
+ }
+}
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 8251db4d3ebc..a71aad226a26 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
@@ -163,6 +163,18 @@ public class VertxPlatformHttpServer extends
ServiceSupport implements CamelCont
return configuration.isUseGlobalSslContextParameters();
}
+ /**
+ * The scheme the server is reached with: https when SSL is configured (by
the same rule as the server setup), or
+ * http.
+ */
+ @ManagedAttribute(description = "HTTP scheme (http or https)")
+ public String getScheme() {
+ boolean ssl = configuration.getSslContextParameters() != null
+ || configuration.isUseGlobalSslContextParameters() && context
!= null
+ && context.getSSLContextParameters() != null;
+ return ssl ? "https" : "http";
+ }
+
// *******************************
//
// Helpers
diff --git
a/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServerSchemeTest.java
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServerSchemeTest.java
new file mode 100644
index 000000000000..da7a96d628e7
--- /dev/null
+++
b/components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServerSchemeTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.impl.DefaultCamelContext;
+import org.apache.camel.support.jsse.SSLContextParameters;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * The scheme of the server must follow the SSL setup of the server (see
VertxPlatformHttpServerSupport.configureSSL),
+ * as the dev consoles and the Camel CLI print URLs with it: a server with SSL
is not reached with http.
+ */
+class VertxPlatformHttpServerSchemeTest {
+
+ @Test
+ void httpWithoutSsl() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ assertEquals("http", server(context, new
VertxPlatformHttpServerConfiguration()).getScheme());
+ }
+ }
+
+ @Test
+ void httpsWithSslContextParameters() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ VertxPlatformHttpServerConfiguration configuration = new
VertxPlatformHttpServerConfiguration();
+ configuration.setSslContextParameters(new SSLContextParameters());
+ assertEquals("https", server(context, configuration).getScheme());
+ }
+ }
+
+ @Test
+ void httpsWithGlobalSslContextParameters() throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ context.setSSLContextParameters(new SSLContextParameters());
+ VertxPlatformHttpServerConfiguration configuration = new
VertxPlatformHttpServerConfiguration();
+ configuration.setUseGlobalSslContextParameters(true);
+ assertEquals("https", server(context, configuration).getScheme());
+ }
+ }
+
+ @Test
+ void httpWhenGlobalSslContextParametersAreMissing() throws Exception {
+ // using the global SSL configuration without one sets up no SSL
+ try (CamelContext context = new DefaultCamelContext()) {
+ VertxPlatformHttpServerConfiguration configuration = new
VertxPlatformHttpServerConfiguration();
+ configuration.setUseGlobalSslContextParameters(true);
+ assertEquals("http", server(context, configuration).getScheme());
+ }
+ }
+
+ private static VertxPlatformHttpServer server(CamelContext context,
VertxPlatformHttpServerConfiguration configuration) {
+ VertxPlatformHttpServer server = new
VertxPlatformHttpServer(configuration);
+ server.setCamelContext(context);
+ return server;
+ }
+}
diff --git
a/components/camel-platform-http/src/generated/resources/META-INF/org/apache/camel/dev-console/platform-http.json
b/components/camel-platform-http/src/generated/resources/META-INF/org/apache/camel/dev-console/platform-http.json
index 5d103fae1eda..9f975626be16 100644
---
a/components/camel-platform-http/src/generated/resources/META-INF/org/apache/camel/dev-console/platform-http.json
+++
b/components/camel-platform-http/src/generated/resources/META-INF/org/apache/camel/dev-console/platform-http.json
@@ -17,7 +17,11 @@
"properties": {
"server": {
"type": "string",
- "description": "The base URL of the endpoints: always
http:\/\/0.0.0.0, with the port of the server when known (only present when the
platform-http component exists)"
+ "description": "The base URL of the endpoints: scheme, bind host, port
and context path of the server when known, otherwise http:\/\/0.0.0.0 with the
port of the engine (only present when the platform-http component exists)"
+ },
+ "managementServer": {
+ "type": "string",
+ "description": "The base URL of the server of the management
endpoints, which can differ from the server when they have their own port (only
present when there are management endpoints)"
},
"endpoints": {
"type": "array",
diff --git
a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
index 8f56718f6c58..d200fa0130d0 100644
---
a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
+++
b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
@@ -92,6 +92,8 @@ public class PlatformHttpComponent extends
HeaderFilterStrategyComponent
private final Set<HttpEndpointModel> httpManagementEndpoints = new
LinkedHashSet<>();
private final List<PlatformHttpListener> listeners = new ArrayList<>();
private volatile boolean localEngine;
+ private volatile String serverUrl;
+ private volatile String managementServerUrl;
public PlatformHttpComponent() {
this(null);
@@ -270,6 +272,31 @@ public class PlatformHttpComponent extends
HeaderFilterStrategyComponent
return Collections.unmodifiableSet(httpManagementEndpoints);
}
+ /**
+ * The base URL (scheme, host and port) of the HTTP server that serves the
http endpoints, or null when the HTTP
+ * server does not tell. Set by the embedded HTTP server
(camel-platform-http-main), and shown by the dev console.
+ */
+ public String getServerUrl() {
+ return serverUrl;
+ }
+
+ public void setServerUrl(String serverUrl) {
+ this.serverUrl = serverUrl;
+ }
+
+ /**
+ * The base URL (scheme, host and port) of the HTTP server that serves the
http management endpoints, or null when
+ * the HTTP server does not tell. Set by the embedded HTTP management
server (camel-platform-http-main), and shown
+ * by the dev console.
+ */
+ public String getManagementServerUrl() {
+ return managementServerUrl;
+ }
+
+ public void setManagementServerUrl(String managementServerUrl) {
+ this.managementServerUrl = managementServerUrl;
+ }
+
@Override
protected void doStart() throws Exception {
super.doStart();
diff --git
a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConsole.java
b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConsole.java
index 80e30a889549..40777050d328 100644
---
a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConsole.java
+++
b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConsole.java
@@ -39,7 +39,9 @@ public class PlatformHttpConsole extends AbstractDevConsole {
}
public record Response(
- @Metadata(description = "The base URL of the endpoints: always
http://0.0.0.0, with the port of the server when known (only present when the
platform-http component exists)") String server,
+ @Metadata(description = "The base URL of the endpoints: scheme,
bind host, port and context path of the server when known, otherwise
http://0.0.0.0 with the port of the engine (only present when the platform-http
component exists)") String server,
+ @Metadata(description = "The base URL of the server of the
management endpoints, which can differ from the server"
+ + " when they have their own port (only
present when there are management endpoints)") String managementServer,
@Metadata(description = "The registered HTTP endpoints (only
present when there are any)") List<EndpointEntry> endpoints,
@Metadata(description = "The registered HTTP management endpoints,
such as health and info (only present when there are any)") List<EndpointEntry>
managementEndpoints) {
}
@@ -57,37 +59,30 @@ public class PlatformHttpConsole extends AbstractDevConsole
{
// currently be creating which can lead to a dead-lock in Spring Boot
PlatformHttpComponent http = (PlatformHttpComponent)
getCamelContext().hasComponent("platform-http");
if (http != null) {
- String server = "http://0.0.0.0";
- int port = http.getEngine().getServerPort();
- if (port > 0) {
- server += ":" + port;
- }
+ String server = serverUrl(http);
sb.append("Endpoints:\n");
- Set<HttpEndpointModel> models = http.getHttpEndpoints();
- for (HttpEndpointModel model : models) {
- if (model.getVerbs() != null) {
- sb.append(String.format(" %s%s (%s)%n", server,
model.getUri(), model.getVerbs()));
- } else {
- sb.append(String.format(" %s%s%n", server,
model.getUri()));
- }
- }
+ appendEndpoints(sb, server, http.getHttpEndpoints());
sb.append("\nManagement Endpoints:\n");
- models = http.getHttpManagementEndpoints();
- for (HttpEndpointModel model : models) {
- if (model.getVerbs() != null) {
- sb.append(String.format(" %s%s (%s)%n", server,
model.getUri(), model.getVerbs()));
- } else {
- sb.append(String.format(" %s%s%n", server,
model.getUri()));
- }
- }
+ appendEndpoints(sb, managementServerUrl(http, server),
http.getHttpManagementEndpoints());
}
return sb.toString();
}
+ private static void appendEndpoints(StringBuilder sb, String server,
Set<HttpEndpointModel> models) {
+ for (HttpEndpointModel model : models) {
+ if (model.getVerbs() != null) {
+ sb.append(String.format(" %s%s (%s)%n", server,
model.getUri(), model.getVerbs()));
+ } else {
+ sb.append(String.format(" %s%s%n", server, model.getUri()));
+ }
+ }
+ }
+
@Override
protected Map<String, Object> doCallJson(Map<String, Object> options) {
String server = null;
+ String managementServer = null;
List<EndpointEntry> endpoints = null;
List<EndpointEntry> managementEndpoints = null;
@@ -95,22 +90,46 @@ public class PlatformHttpConsole extends AbstractDevConsole
{
// currently be creating which can lead to a dead-lock in Spring Boot
PlatformHttpComponent http = (PlatformHttpComponent)
getCamelContext().hasComponent("platform-http");
if (http != null) {
- server = "http://0.0.0.0";
- int port = http.getEngine().getServerPort();
- if (port > 0) {
- server += ":" + port;
- }
+ server = serverUrl(http);
List<EndpointEntry> list = buildEndpointList(http, server, false);
endpoints = list.isEmpty() ? null : list;
- list = buildEndpointList(http, server, true);
- managementEndpoints = list.isEmpty() ? null : list;
+ String base = managementServerUrl(http, server);
+ list = buildEndpointList(http, base, true);
+ if (!list.isEmpty()) {
+ managementEndpoints = list;
+ managementServer = base;
+ }
}
- Response response = new Response(server, endpoints,
managementEndpoints);
+ Response response = new Response(server, managementServer, endpoints,
managementEndpoints);
return JsonRecordSupport.toJsonObject(response);
}
+ /**
+ * The base URL of the server of the http endpoints: as told by the HTTP
server (camel-platform-http-main), or else
+ * from the scheme and port of the engine (such as with Spring Boot or
Quarkus).
+ */
+ private static String serverUrl(PlatformHttpComponent http) {
+ if (http.getServerUrl() != null) {
+ return http.getServerUrl();
+ }
+ String server = http.getEngine().getScheme() + "://0.0.0.0";
+ int port = http.getEngine().getServerPort();
+ if (port > 0) {
+ server += ":" + port;
+ }
+ return server;
+ }
+
+ /**
+ * The base URL of the server of the http management endpoints, which is
the server of the http endpoints unless the
+ * management server tells otherwise (such as when it has its own port).
+ */
+ private static String managementServerUrl(PlatformHttpComponent http,
String server) {
+ return http.getManagementServerUrl() != null ?
http.getManagementServerUrl() : server;
+ }
+
private static List<EndpointEntry> buildEndpointList(PlatformHttpComponent
http, String server, boolean management) {
Set<HttpEndpointModel> models = management ?
http.getHttpManagementEndpoints() : http.getHttpEndpoints();
List<EndpointEntry> list = new ArrayList<>();