This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.10.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.10.x by this push:
new 5c662d6b896 CAMEL-21987: camel-jbang - Run with --source-dir may not
load content for static HTTP server
5c662d6b896 is described below
commit 5c662d6b896d1f65210bbca11789c766e722bff8
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Apr 19 11:57:25 2025 +0200
CAMEL-21987: camel-jbang - Run with --source-dir may not load content for
static HTTP server
---
.../main/camel-main-configuration-metadata.json | 1 +
.../http/main/DefaultMainHttpServerFactory.java | 1 +
.../component/platform/http/main/MainHttpServer.java | 16 ++++++++++++++++
.../HttpServerConfigurationPropertiesConfigurer.java | 7 +++++++
.../META-INF/camel-main-configuration-metadata.json | 1 +
core/camel-main/src/main/docs/main.adoc | 3 ++-
.../main/HttpServerConfigurationProperties.java | 20 ++++++++++++++++++++
.../main/java/org/apache/camel/main/KameletMain.java | 4 +++-
8 files changed, 51 insertions(+), 2 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
index 71a1bfd7be6..90713cd74c9 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
@@ -288,6 +288,7 @@
{ "name": "camel.server.sendEnabled", "description": "Whether to enable
sending messages to Camel via HTTP. This makes it possible to use Camel to send
messages to Camel endpoint URIs via HTTP.", "sourceType":
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean",
"javaType": "boolean", "defaultValue": "false" },
{ "name": "camel.server.staticContextPath", "description": "The
context-path to use for serving static content. By default, the root path is
used. And if there is an index.html page then this is automatically loaded.",
"sourceType": "org.apache.camel.main.HttpServerConfigurationProperties",
"type": "string", "javaType": "java.lang.String", "defaultValue": "\/" },
{ "name": "camel.server.staticEnabled", "description": "Whether serving
static files is enabled. If enabled then Camel can host html\/js and other web
files that makes it possible to include small web applications.", "sourceType":
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean",
"javaType": "boolean", "defaultValue": "false" },
+ { "name": "camel.server.staticSourceDir", "description": "Additional
directory that holds static content when static is enabled.", "sourceType":
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "string",
"javaType": "java.lang.String" },
{ "name": "camel.server.uploadEnabled", "description": "Whether to enable
file upload via HTTP (not intended for production use). This functionality is
for development to be able to reload Camel routes and code with source changes
(if reload is enabled). If enabled then you can upload\/delete files via HTTP
PUT\/DELETE on context-path: \/q\/upload\/{name}. You must also configure the
uploadSourceDir option.", "sourceType":
"org.apache.camel.main.HttpServerConfigurationProperties", "t [...]
{ "name": "camel.server.uploadSourceDir", "description": "Source directory
when upload is enabled.", "sourceType":
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "string",
"javaType": "java.lang.String" },
{ "name": "camel.server.useGlobalSslContextParameters", "description":
"Whether to use global SSL configuration for securing the embedded HTTP
server.", "sourceType":
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean",
"javaType": "boolean", "defaultValue": "false" },
diff --git
a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/DefaultMainHttpServerFactory.java
b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/DefaultMainHttpServerFactory.java
index 7daae15af58..e274eb09338 100644
---
a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/DefaultMainHttpServerFactory.java
+++
b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/DefaultMainHttpServerFactory.java
@@ -69,6 +69,7 @@ public class DefaultMainHttpServerFactory implements
CamelContextAware, MainHttp
server.setInfoEnabled(configuration.isInfoEnabled());
server.setStaticEnabled(configuration.isStaticEnabled());
server.setStaticContextPath(configuration.getStaticContextPath());
+ server.setStaticSourceDir(configuration.getStaticSourceDir());
server.setDevConsoleEnabled(configuration.isDevConsoleEnabled());
server.setHealthCheckEnabled(configuration.isHealthCheckEnabled());
server.setHealthPath(configuration.getHealthPath());
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 dd123a1dcbb..4afe3e15584 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
@@ -124,6 +124,7 @@ public class MainHttpServer extends ServiceSupport
implements CamelContextAware,
private VertxPlatformHttpServerConfiguration configuration = new
VertxPlatformHttpServerConfiguration();
private boolean infoEnabled;
private boolean staticEnabled;
+ private String staticSourceDir;
private String staticContextPath;
private boolean devConsoleEnabled;
private boolean healthCheckEnabled;
@@ -189,6 +190,15 @@ public class MainHttpServer extends ServiceSupport
implements CamelContextAware,
this.staticEnabled = staticEnabled;
}
+ public String getStaticSourceDir() {
+ return staticSourceDir;
+ }
+
+ @ManagedAttribute(description = "The source dir for serving static
content")
+ public void setStaticSourceDir(String staticSourceDir) {
+ this.staticSourceDir = staticSourceDir;
+ }
+
@ManagedAttribute(description = "The context-path for serving static
content")
public String getStaticContextPath() {
return staticContextPath;
@@ -562,6 +572,9 @@ public class MainHttpServer extends ServiceSupport
implements CamelContextAware,
InputStream is = null;
File f = new File(u);
+ if (!f.exists() && staticSourceDir != null) {
+ f = new File(staticSourceDir, u);
+ }
if (f.exists()) {
// load directly from file system first
try {
@@ -575,6 +588,9 @@ public class MainHttpServer extends ServiceSupport
implements CamelContextAware,
// common folder for java app servers like quarkus and
spring-boot
is =
camelContext.getClassResolver().loadResourceAsStream("META-INF/resources/" + u);
}
+ if (is == null && staticSourceDir != null) {
+ is =
camelContext.getClassResolver().loadResourceAsStream(staticSourceDir + "/" + u);
+ }
}
if (is != null) {
String mime =
MimeMapping.getMimeTypeForFilename(f.getName());
diff --git
a/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerConfigurationPropertiesConfigurer.java
b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerConfigurationPropertiesConfigurer.java
index e47a448a491..7e7013586f3 100644
---
a/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerConfigurationPropertiesConfigurer.java
+++
b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerConfigurationPropertiesConfigurer.java
@@ -45,6 +45,7 @@ public class HttpServerConfigurationPropertiesConfigurer
extends org.apache.came
map.put("SendEnabled", boolean.class);
map.put("StaticContextPath", java.lang.String.class);
map.put("StaticEnabled", boolean.class);
+ map.put("StaticSourceDir", java.lang.String.class);
map.put("UploadEnabled", boolean.class);
map.put("UploadSourceDir", java.lang.String.class);
map.put("UseGlobalSslContextParameters", boolean.class);
@@ -97,6 +98,8 @@ public class HttpServerConfigurationPropertiesConfigurer
extends org.apache.came
case "staticContextPath":
target.setStaticContextPath(property(camelContext, java.lang.String.class,
value)); return true;
case "staticenabled":
case "staticEnabled": target.setStaticEnabled(property(camelContext,
boolean.class, value)); return true;
+ case "staticsourcedir":
+ case "staticSourceDir":
target.setStaticSourceDir(property(camelContext, java.lang.String.class,
value)); return true;
case "uploadenabled":
case "uploadEnabled": target.setUploadEnabled(property(camelContext,
boolean.class, value)); return true;
case "uploadsourcedir":
@@ -157,6 +160,8 @@ public class HttpServerConfigurationPropertiesConfigurer
extends org.apache.came
case "staticContextPath": return java.lang.String.class;
case "staticenabled":
case "staticEnabled": return boolean.class;
+ case "staticsourcedir":
+ case "staticSourceDir": return java.lang.String.class;
case "uploadenabled":
case "uploadEnabled": return boolean.class;
case "uploadsourcedir":
@@ -213,6 +218,8 @@ public class HttpServerConfigurationPropertiesConfigurer
extends org.apache.came
case "staticContextPath": return target.getStaticContextPath();
case "staticenabled":
case "staticEnabled": return target.isStaticEnabled();
+ case "staticsourcedir":
+ case "staticSourceDir": return target.getStaticSourceDir();
case "uploadenabled":
case "uploadEnabled": return target.isUploadEnabled();
case "uploadsourcedir":
diff --git
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
index 71a1bfd7be6..90713cd74c9 100644
---
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
+++
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
@@ -288,6 +288,7 @@
{ "name": "camel.server.sendEnabled", "description": "Whether to enable
sending messages to Camel via HTTP. This makes it possible to use Camel to send
messages to Camel endpoint URIs via HTTP.", "sourceType":
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean",
"javaType": "boolean", "defaultValue": "false" },
{ "name": "camel.server.staticContextPath", "description": "The
context-path to use for serving static content. By default, the root path is
used. And if there is an index.html page then this is automatically loaded.",
"sourceType": "org.apache.camel.main.HttpServerConfigurationProperties",
"type": "string", "javaType": "java.lang.String", "defaultValue": "\/" },
{ "name": "camel.server.staticEnabled", "description": "Whether serving
static files is enabled. If enabled then Camel can host html\/js and other web
files that makes it possible to include small web applications.", "sourceType":
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean",
"javaType": "boolean", "defaultValue": "false" },
+ { "name": "camel.server.staticSourceDir", "description": "Additional
directory that holds static content when static is enabled.", "sourceType":
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "string",
"javaType": "java.lang.String" },
{ "name": "camel.server.uploadEnabled", "description": "Whether to enable
file upload via HTTP (not intended for production use). This functionality is
for development to be able to reload Camel routes and code with source changes
(if reload is enabled). If enabled then you can upload\/delete files via HTTP
PUT\/DELETE on context-path: \/q\/upload\/{name}. You must also configure the
uploadSourceDir option.", "sourceType":
"org.apache.camel.main.HttpServerConfigurationProperties", "t [...]
{ "name": "camel.server.uploadSourceDir", "description": "Source directory
when upload is enabled.", "sourceType":
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "string",
"javaType": "java.lang.String" },
{ "name": "camel.server.useGlobalSslContextParameters", "description":
"Whether to use global SSL configuration for securing the embedded HTTP
server.", "sourceType":
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean",
"javaType": "boolean", "defaultValue": "false" },
diff --git a/core/camel-main/src/main/docs/main.adoc
b/core/camel-main/src/main/docs/main.adoc
index 076867005fc..bebf3479d0f 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -187,7 +187,7 @@ The camel.routecontroller supports 12 options, which are
listed below.
=== Camel Embedded HTTP Server (only for standalone; not Spring Boot or
Quarkus) configurations
-The camel.server supports 26 options, which are listed below.
+The camel.server supports 27 options, which are listed below.
[width="100%",cols="2,5,^1,2",options="header"]
|===
@@ -215,6 +215,7 @@ The camel.server supports 26 options, which are listed
below.
| *camel.server.sendEnabled* | Whether to enable sending messages to Camel via
HTTP. This makes it possible to use Camel to send messages to Camel endpoint
URIs via HTTP. | false | boolean
| *camel.server.staticContextPath* | The context-path to use for serving
static content. By default, the root path is used. And if there is an
index.html page then this is automatically loaded. | / | String
| *camel.server.staticEnabled* | Whether serving static files is enabled. If
enabled then Camel can host html/js and other web files that makes it possible
to include small web applications. | false | boolean
+| *camel.server.staticSourceDir* | Additional directory that holds static
content when static is enabled. | | String
| *camel.server.uploadEnabled* | Whether to enable file upload via HTTP (not
intended for production use). This functionality is for development to be able
to reload Camel routes and code with source changes (if reload is enabled). If
enabled then you can upload/delete files via HTTP PUT/DELETE on context-path:
/q/upload/\{name}. You must also configure the uploadSourceDir option. | false
| boolean
| *camel.server.uploadSourceDir* | Source directory when upload is enabled. |
| String
| *camel.server.useGlobalSsl{zwsp}ContextParameters* | Whether to use global
SSL configuration for securing the embedded HTTP server. | false | boolean
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java
b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java
index 33f5afa81a5..8cfbfd51717 100644
---
a/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java
+++
b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java
@@ -44,6 +44,7 @@ public class HttpServerConfigurationProperties implements
BootstrapCloseable {
private String fileUploadDirectory;
private boolean infoEnabled;
private boolean staticEnabled;
+ private String staticSourceDir;
@Metadata(defaultValue = "/")
private String staticContextPath = "/";
private boolean devConsoleEnabled;
@@ -199,6 +200,17 @@ public class HttpServerConfigurationProperties implements
BootstrapCloseable {
this.staticEnabled = staticEnabled;
}
+ public String getStaticSourceDir() {
+ return staticSourceDir;
+ }
+
+ /**
+ * Additional directory that holds static content when static is enabled.
+ */
+ public void setStaticSourceDir(String staticSourceDir) {
+ this.staticSourceDir = staticSourceDir;
+ }
+
public String getStaticContextPath() {
return staticContextPath;
}
@@ -472,6 +484,14 @@ public class HttpServerConfigurationProperties implements
BootstrapCloseable {
return this;
}
+ /**
+ * Additional directory that holds static content when static is enabled.
+ */
+ public HttpServerConfigurationProperties withStaticSourceDir(String
staticSourceDir) {
+ this.staticSourceDir = staticSourceDir;
+ return this;
+ }
+
/**
* The context-path to use for serving static content. By default, the
root path is used. And if there is an
* index.html page then this is automatically loaded.
diff --git
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
index e805168735e..dc93855cff4 100644
---
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
+++
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -650,11 +650,13 @@ public class KameletMain extends MainCommandLineSupport {
// reloader
if (sourceDir != null) {
+ configure().httpServer().withStaticSourceDir(sourceDir);
+ configure().httpServer().withUploadSourceDir(sourceDir);
+
if (console || health) {
// allow to upload/download source (source-dir is intended
to be dynamic) via http when HTTP console enabled
configure().httpServer().withEnabled(true);
configure().httpServer().withUploadEnabled(true);
- configure().httpServer().withUploadSourceDir(sourceDir);
configure().httpServer().withDownloadEnabled(true);
}
RouteOnDemandReloadStrategy reloader = new
RouteOnDemandReloadStrategy(sourceDir, true);