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 6ee0a2ec448 CAMEL-21987: camel-jbang - Run with --source-dir may not
load content for static HTTP server
6ee0a2ec448 is described below
commit 6ee0a2ec44854ffa35214034c4f2963a75922ec1
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 d0bb8edc242..54457232325 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
@@ -298,6 +298,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 2a96b201f09..d907fe9e765 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 d2853a7d442..67120cf2470 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;
@@ -190,6 +191,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;
@@ -576,6 +586,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 {
@@ -589,6 +602,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 897a6c11006..dface0fc64b 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
@@ -46,6 +46,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);
@@ -100,6 +101,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":
@@ -162,6 +165,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":
@@ -220,6 +225,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 d0bb8edc242..54457232325 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
@@ -298,6 +298,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 e2f68315638..17b2821a896 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 27 options, which are listed below.
+The camel.server supports 28 options, which are listed below.
[width="100%",cols="2,5,^1,2",options="header"]
|===
@@ -216,6 +216,7 @@ The camel.server supports 27 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 23ee307b674..ffb959d97df 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;
@@ -201,6 +202,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;
}
@@ -485,6 +497,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 0508fb78b8d..d47fa441692 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
@@ -674,11 +674,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);