This is an automated email from the ASF dual-hosted git repository.
Croway 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 0ed739ce5064 CAMEL-25533: camel-jbang - apply camel.server.* settings
to the HTTP server started for platform-http (4.22.x) (#27668)
0ed739ce5064 is described below
commit 0ed739ce5064510477c72b19e532094edec51b5f
Author: Federico Mariani <[email protected]>
AuthorDate: Sun Oct 11 10:22:06 2026 +0200
CAMEL-25533: camel-jbang - apply camel.server.* settings to the HTTP server
started for platform-http (4.22.x) (#27668)
* CAMEL-25533: camel-jbang - apply camel.server.* settings to the HTTP
server started for platform-http
camel run starts an embedded HTTP server when a route uses platform-http,
also when camel.server.enabled is not
set, but created it with the default configuration: only --port was taken
(from the run settings), so
camel.server.port, host, path and the other camel.server.* settings of
application.properties were ignored without
any message, while the auto-configuration summary listed them. camel-main
binds them only on the server it starts
itself, when camel.server.enabled=true.
The implicit server now binds the camel.server.* properties the same way,
with placeholders resolved; --port keeps
precedence, and the run settings record the port actually used.
* CAMEL-25533: camel-jbang - also apply the camel.server.* OS environment
variables to the HTTP server started for platform-http
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* CAMEL-25533: trim overlapping test assertions
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../camel/main/download/MainHttpServerFactory.java | 49 +++++++++
.../main/download/MainHttpServerFactoryTest.java | 121 +++++++++++++++++++++
2 files changed, 170 insertions(+)
diff --git
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/MainHttpServerFactory.java
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/MainHttpServerFactory.java
index 1185429e912c..1b8ae3fce291 100644
---
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/MainHttpServerFactory.java
+++
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/MainHttpServerFactory.java
@@ -16,17 +16,29 @@
*/
package org.apache.camel.main.download;
+import java.util.Properties;
+
import org.apache.camel.CamelContext;
import org.apache.camel.Service;
import org.apache.camel.component.platform.http.main.MainHttpServer;
import org.apache.camel.component.platform.http.main.ManagementHttpServer;
import org.apache.camel.main.HttpServerConfigurationProperties;
import org.apache.camel.main.MainConstants;
+import org.apache.camel.main.MainHelper;
import org.apache.camel.main.util.CamelJBangSettingsHelper;
import org.apache.camel.support.CamelContextHelper;
+import org.apache.camel.util.OrderedLocationProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.camel.util.StringHelper.startsWithIgnoreCase;
public class MainHttpServerFactory {
+ private static final Logger LOG =
LoggerFactory.getLogger(MainHttpServerFactory.class);
+
+ private static final String PREFIX_SERVER = "camel.server.";
+
public static MainHttpServer setupHttpServer(CamelContext camelContext,
boolean silent) {
// if we only use management then there is no main server already
MainHttpServer server = camelContext.hasService(MainHttpServer.class);
@@ -35,6 +47,8 @@ public class MainHttpServerFactory {
if (server == null && managementHttpServer == null) {
// set up a default http server on configured port if not already
done
HttpServerConfigurationProperties config = new
HttpServerConfigurationProperties(null);
+ // apply the camel.server.* settings (port, host, path ...) as
camel-main does when the server is enabled
+ configureHttpServer(camelContext, config);
String port =
CamelJBangSettingsHelper.readSettings("camel.server.port");
if (port != null) {
config.setPort(CamelContextHelper.parseInt(camelContext,
port));
@@ -56,6 +70,41 @@ public class MainHttpServerFactory {
return server;
}
+ /**
+ * Binds the camel.server.* properties (application.properties,
--properties, initial and override properties, OS
+ * environment variables and JVM system properties) on the configuration
of the HTTP server that is started
+ * implicitly for platform-http, as camel-main only applies them to the
server it starts itself when
+ * camel.server.enabled=true.
+ */
+ static void configureHttpServer(CamelContext camelContext,
HttpServerConfigurationProperties config) {
+ OrderedLocationProperties prop = (OrderedLocationProperties)
camelContext.getPropertiesComponent()
+ .loadProperties(name -> startsWithIgnoreCase(name,
PREFIX_SERVER), MainHelper::optionKey);
+ // OS environment variables and then JVM system properties override,
as in camel-main
+ Properties propENV =
MainHelper.loadEnvironmentVariablesAsProperties(new String[] { PREFIX_SERVER });
+ for (String key : propENV.stringPropertyNames()) {
+ prop.put("ENV", MainHelper.optionKey(key),
propENV.getProperty(key));
+ }
+ Properties propJVM =
MainHelper.loadJvmSystemPropertiesAsProperties(new String[] { PREFIX_SERVER });
+ for (String key : propJVM.stringPropertyNames()) {
+ prop.put("SYS", MainHelper.optionKey(key),
propJVM.getProperty(key));
+ }
+
+ // all the keys start with camel.server. as every source is filtered
on it
+ OrderedLocationProperties options = new OrderedLocationProperties();
+ for (Object k : prop.keySet()) {
+ String option = k.toString().substring(PREFIX_SERVER.length());
+ // enabled has no meaning here, as the server is started because
platform-http is in use
+ if (!"enabled".equalsIgnoreCase(option)) {
+ options.put(prop.getLocation(k), option, prop.get(k));
+ }
+ }
+ if (!options.isEmpty()) {
+ LOG.debug("Configuring embedded HTTP server for platform-http from
properties: {}", options.size());
+ MainHelper.setPropertiesOnTarget(camelContext, config, options,
PREFIX_SERVER, false, true,
+ new OrderedLocationProperties());
+ }
+ }
+
private static org.apache.camel.main.MainHttpServerFactory
resolveMainHttpServerFactory(CamelContext camelContext)
throws Exception {
// lookup in service registry first
diff --git
a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/MainHttpServerFactoryTest.java
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/MainHttpServerFactoryTest.java
new file mode 100644
index 000000000000..da35416c6878
--- /dev/null
+++
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/MainHttpServerFactoryTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.main.download;
+
+import java.util.Properties;
+
+import org.apache.camel.component.platform.http.main.MainHttpServer;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * The HTTP server started implicitly for platform-http (camel.server.enabled
is not set) uses the camel.server.*
+ * settings.
+ */
+public class MainHttpServerFactoryTest {
+
+ private DefaultCamelContext context;
+
+ @BeforeEach
+ void setUp() {
+ context = new DefaultCamelContext();
+ }
+
+ @AfterEach
+ void tearDown() {
+ context.stop();
+ }
+
+ @Test
+ void shouldUseDefaultPortWithoutServerProperties() {
+ MainHttpServerFactory.setupHttpServer(context, false);
+
+ MainHttpServer server = context.hasService(MainHttpServer.class);
+ assertNotNull(server);
+ assertEquals(8080, server.getPort());
+ assertEquals("0.0.0.0", server.getHost());
+ assertEquals("/", server.getPath());
+ }
+
+ @Test
+ void shouldApplyServerProperties() {
+ Properties prop = new Properties();
+ prop.put("camel.server.port", "9090");
+ prop.put("camel.server.host", "localhost");
+ prop.put("camel.server.path", "/api");
+ prop.put("camel.server.max-body-size", "2048");
+ context.getPropertiesComponent().setInitialProperties(prop);
+
+ MainHttpServerFactory.setupHttpServer(context, false);
+
+ MainHttpServer server = context.hasService(MainHttpServer.class);
+ assertNotNull(server);
+ assertEquals(9090, server.getPort());
+ assertEquals("localhost", server.getHost());
+ assertEquals("/api", server.getPath());
+ assertEquals(2048L, server.getMaxBodySize());
+ }
+
+ @Test
+ void shouldResolvePlaceholderInServerPort() {
+ Properties prop = new Properties();
+ prop.put("camel.server.port", "{{myPort}}");
+ prop.put("myPort", "9191");
+ context.getPropertiesComponent().setInitialProperties(prop);
+
+ MainHttpServerFactory.setupHttpServer(context, false);
+
+ MainHttpServer server = context.hasService(MainHttpServer.class);
+ assertNotNull(server);
+ assertEquals(9191, server.getPort());
+ }
+
+ @Test
+ void shouldOverrideServerPropertiesWithJvmSystemProperties() {
+ Properties prop = new Properties();
+ prop.put("camel.server.host", "localhost");
+ context.getPropertiesComponent().setInitialProperties(prop);
+
+ System.setProperty("camel.server.host", "127.0.0.1");
+ try {
+ MainHttpServerFactory.setupHttpServer(context, false);
+ } finally {
+ System.clearProperty("camel.server.host");
+ }
+
+ MainHttpServer server = context.hasService(MainHttpServer.class);
+ assertNotNull(server);
+ assertEquals("127.0.0.1", server.getHost());
+ }
+
+ @Test
+ void shouldNotStartServerWhenSilent() {
+ Properties prop = new Properties();
+ prop.put("camel.server.port", "9090");
+ context.getPropertiesComponent().setInitialProperties(prop);
+
+ MainHttpServerFactory.setupHttpServer(context, true);
+
+ assertNull(context.hasService(MainHttpServer.class));
+ }
+}