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 7d189b543207 CAMEL-26930: camel-kamelet-main - the HTTP server for
platform-http takes its port from the run, not from the run settings file of
the folder (#29984)
7d189b543207 is described below
commit 7d189b54320704d1d9fea4c0073ae984fe7c7157
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 15 13:09:03 2026 +0100
CAMEL-26930: camel-kamelet-main - the HTTP server for platform-http takes
its port from the run, not from the run settings file of the folder (#29984)
A point of item 7 of
[CAMEL-26930](https://issues.apache.org/jira/browse/CAMEL-26930) that was found
by reading the code; it extends item 1 of CAMEL-26912.
## Problem
When a route uses platform-http, the run starts an HTTP server for it
(`MainHttpServerFactory.setupHttpServer` in camel-kamelet-main). It applied the
`camel.server.*` configuration, and then took the port from
`.camel-jbang/camel-jbang-run.properties` of the current directory. That file
is written by every `camel run` in that folder, for `camel export`. So a second
run in the same folder (another integration, or the same one with `--port`), or
a run whose server starts later (such as [...]
## Change
The port is the one of the configuration of the run: `camel run --port` is
in its initial properties already (`RunSettings.write` sets the initial
property and writes the setting), as are `application.properties`, environment
variables and system properties. The run settings file is no longer read for
it. The port is still written to the file when the run did not write it, for
`camel export`.
## Tests
- `MainHttpServerFactoryTest.theRunSettingsOfAnotherRunDoNotChangeThePort`
(new): with `camel.server.port=7777` in the run settings file and 9090 in the
configuration, the server gets 9090; without the fix it got 7777. The test
restores the file of the module folder.
- camel-kamelet-main: 85 pass. camel-jbang-run: 323 pass. camel-jbang-core:
3087 + 266 pass (`DependencyUpdateTest` flaked once and passed on the rerun).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../camel/main/download/MainHttpServerFactory.java | 12 +++-----
.../main/download/MainHttpServerFactoryTest.java | 34 ++++++++++++++++++++++
2 files changed, 38 insertions(+), 8 deletions(-)
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 1b8ae3fce291..1b281519a0b2 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
@@ -26,7 +26,6 @@ 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;
@@ -49,13 +48,10 @@ public class MainHttpServerFactory {
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));
- } else {
-
CamelJBangSettingsHelper.writeSettingsIfNotExists("camel.server.port",
- String.valueOf(config.getPort()));
- }
+ // the port is from the configuration of this run (camel run
--port is in its initial properties); the run
+ // settings file of the current directory is shared, so another
run in the same folder could change the port
+ // of this one (CAMEL-26930). The port is written there for camel
export, when the run did not write it
+
CamelJBangSettingsHelper.writeSettingsIfNotExists("camel.server.port",
String.valueOf(config.getPort()));
if (!silent) {
try {
// enable http server if not silent
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
index da35416c6878..16f958e1f4d9 100644
---
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
@@ -16,6 +16,9 @@
*/
package org.apache.camel.main.download;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
import java.util.Properties;
import org.apache.camel.component.platform.http.main.MainHttpServer;
@@ -108,6 +111,37 @@ public class MainHttpServerFactoryTest {
assertEquals("127.0.0.1", server.getHost());
}
+ @Test
+ void theRunSettingsOfAnotherRunDoNotChangeThePort() throws Exception {
+ // another run in the same folder writes its port to
.camel-jbang/camel-jbang-run.properties (CAMEL-26930)
+ Path settings = Path.of(".camel-jbang", "camel-jbang-run.properties");
+ Path backup = Files.exists(settings) ?
Files.createTempFile("run-settings", ".properties") : null;
+ if (backup != null) {
+ Files.copy(settings, backup, StandardCopyOption.REPLACE_EXISTING);
+ }
+ boolean created = Files.notExists(settings.getParent());
+ Files.createDirectories(settings.getParent());
+ Files.writeString(settings, "camel.server.port=7777\n");
+ try {
+ Properties prop = new Properties();
+ prop.put("camel.server.port", "9090");
+ context.getPropertiesComponent().setInitialProperties(prop);
+
+ MainHttpServerFactory.setupHttpServer(context, false);
+
+ assertEquals(9090,
context.hasService(MainHttpServer.class).getPort());
+ } finally {
+ if (backup != null) {
+ Files.move(backup, settings,
StandardCopyOption.REPLACE_EXISTING);
+ } else {
+ Files.deleteIfExists(settings);
+ if (created) {
+ Files.deleteIfExists(settings.getParent());
+ }
+ }
+ }
+ }
+
@Test
void shouldNotStartServerWhenSilent() {
Properties prop = new Properties();