This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch send in repository https://gitbox.apache.org/repos/asf/camel.git
commit de5dc0e304f3328ca115d4d0614e16117d4a0309 Author: Claus Ibsen <[email protected]> AuthorDate: Thu Sep 5 10:17:32 2024 +0200 CAMEL-21136: Add /q/send to camel-main/camel-jbang for sending messages to Camel via HTTP --- .../apache/camel/catalog/dev-consoles.properties | 1 - .../catalog/dev-consoles/kubernetes-secrets.json | 15 ---------- .../main/camel-main-configuration-metadata.json | 1 + .../platform/http/main/MainHttpServer.java | 34 ++++++++++++++++++++++ ...ttpServerConfigurationPropertiesConfigurer.java | 6 ++++ .../camel-main-configuration-metadata.json | 1 + core/camel-main/src/main/docs/main.adoc | 3 +- .../main/HttpServerConfigurationProperties.java | 22 ++++++++++++++ 8 files changed, 66 insertions(+), 17 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles.properties b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles.properties index 0d11272191f..d634e0271ec 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles.properties +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles.properties @@ -18,7 +18,6 @@ inflight java-security jvm kafka -kubernetes-secrets log main-configuration memory diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/kubernetes-secrets.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/kubernetes-secrets.json deleted file mode 100644 index 81da7a37aeb..00000000000 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/kubernetes-secrets.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "console": { - "kind": "console", - "group": "camel", - "name": "kubernetes-secrets", - "title": "Kubernetes Secrets", - "description": "Kubernetes Cluster Secrets", - "deprecated": false, - "javaType": "org.apache.camel.component.kubernetes.secrets.vault.SecretsDevConsole", - "groupId": "org.apache.camel", - "artifactId": "camel-kubernetes", - "version": "4.8.0-SNAPSHOT" - } -} - 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 6870397226c..e169a45d9a5 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 @@ -276,6 +276,7 @@ { "name": "camel.server.metricsEnabled", "description": "Whether to enable metrics. If enabled then you can access metrics on context-path: \/q\/metrics", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.server.path", "description": "Context-path to use for embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "\/" }, { "name": "camel.server.port", "description": "Port to use for binding embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", "javaType": "int", "defaultValue": 8080 }, + { "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.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 [...] 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 86ad9cb221e..8c73cd2fd22 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 @@ -114,6 +114,7 @@ public class MainHttpServer extends ServiceSupport implements CamelContextAware, private boolean uploadEnabled; private String uploadSourceDir; private boolean downloadEnabled; + private boolean sendEnabled; @Override public CamelContext getCamelContext() { @@ -249,6 +250,19 @@ public class MainHttpServer extends ServiceSupport implements CamelContextAware, this.downloadEnabled = downloadEnabled; } + @ManagedAttribute(description = "Whether send message is enabled (q/send)") + public boolean isSendEnabled() { + return 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. + */ + public void setSendEnabled(boolean sendEnabled) { + this.sendEnabled = sendEnabled; + } + @ManagedAttribute(description = "HTTP server port number") public int getPort() { return configuration.getBindPort(); @@ -385,6 +399,9 @@ public class MainHttpServer extends ServiceSupport implements CamelContextAware, if (downloadEnabled) { setupDownloadConsole(); } + if (sendEnabled) { + setupSendConsole(); + } // metrics will be setup in camel-micrometer-prometheus } @@ -1165,4 +1182,21 @@ public class MainHttpServer extends ServiceSupport implements CamelContextAware, null, "text/plain,application/octet-stream", null); } + protected void setupSendConsole() { + final Route download = router.route("/q/send/*") + .method(HttpMethod.GET).method(HttpMethod.POST); + + Handler<RoutingContext> handler = new Handler<RoutingContext>() { + @Override + public void handle(RoutingContext ctx) { + ctx.end("Sending data"); + } + }; + // use blocking handler as the task can take longer time to complete + download.handler(new BlockingHandlerDecorator(handler, true)); + + platformHttpComponent.addHttpEndpoint("/q/send", "GET,POST", + null, null, null); + } + } 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 af40d20036f..d7cc0cc53cd 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 @@ -53,6 +53,8 @@ public class HttpServerConfigurationPropertiesConfigurer extends org.apache.came case "metricsEnabled": target.setMetricsEnabled(property(camelContext, boolean.class, value)); return true; case "path": target.setPath(property(camelContext, java.lang.String.class, value)); return true; case "port": target.setPort(property(camelContext, int.class, value)); return true; + case "sendenabled": + case "sendEnabled": target.setSendEnabled(property(camelContext, boolean.class, value)); return true; case "staticcontextpath": case "staticContextPath": target.setStaticContextPath(property(camelContext, java.lang.String.class, value)); return true; case "staticenabled": @@ -100,6 +102,8 @@ public class HttpServerConfigurationPropertiesConfigurer extends org.apache.came case "metricsEnabled": return boolean.class; case "path": return java.lang.String.class; case "port": return int.class; + case "sendenabled": + case "sendEnabled": return boolean.class; case "staticcontextpath": case "staticContextPath": return java.lang.String.class; case "staticenabled": @@ -148,6 +152,8 @@ public class HttpServerConfigurationPropertiesConfigurer extends org.apache.came case "metricsEnabled": return target.isMetricsEnabled(); case "path": return target.getPath(); case "port": return target.getPort(); + case "sendenabled": + case "sendEnabled": return target.isSendEnabled(); case "staticcontextpath": case "staticContextPath": return target.getStaticContextPath(); case "staticenabled": 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 6870397226c..e169a45d9a5 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 @@ -276,6 +276,7 @@ { "name": "camel.server.metricsEnabled", "description": "Whether to enable metrics. If enabled then you can access metrics on context-path: \/q\/metrics", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.server.path", "description": "Context-path to use for embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "\/" }, { "name": "camel.server.port", "description": "Port to use for binding embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", "javaType": "int", "defaultValue": 8080 }, + { "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.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 [...] diff --git a/core/camel-main/src/main/docs/main.adoc b/core/camel-main/src/main/docs/main.adoc index 0f95836ea0d..1ae7acb68a4 100644 --- a/core/camel-main/src/main/docs/main.adoc +++ b/core/camel-main/src/main/docs/main.adoc @@ -170,7 +170,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 22 options, which are listed below. +The camel.server supports 23 options, which are listed below. [width="100%",cols="2,5,^1,2",options="header"] |=== @@ -192,6 +192,7 @@ The camel.server supports 22 options, which are listed below. | *camel.server.metricsEnabled* | Whether to enable metrics. If enabled then you can access metrics on context-path: /q/metrics | false | boolean | *camel.server.path* | Context-path to use for embedded HTTP server | / | String | *camel.server.port* | Port to use for binding embedded HTTP server | 8080 | int +| *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.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 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 96d5e0128b6..a9bb82c78d7 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 @@ -50,6 +50,7 @@ public class HttpServerConfigurationProperties implements BootstrapCloseable { private boolean uploadEnabled; private String uploadSourceDir; private boolean downloadEnabled; + private boolean sendEnabled; @Metadata(label = "security") private boolean authenticationEnabled; @@ -264,6 +265,18 @@ public class HttpServerConfigurationProperties implements BootstrapCloseable { this.downloadEnabled = downloadEnabled; } + public boolean isSendEnabled() { + return 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. + */ + public void setSendEnabled(boolean sendEnabled) { + this.sendEnabled = sendEnabled; + } + public boolean isAuthenticationEnabled() { return authenticationEnabled; } @@ -470,6 +483,15 @@ public class HttpServerConfigurationProperties implements BootstrapCloseable { return this; } + /** + * 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. + */ + public HttpServerConfigurationProperties withSendEnabled(boolean sendEnabled) { + this.sendEnabled = sendEnabled; + return this; + } + /** * Whether to enable HTTP authentication for embedded server (for standalone applications; not Spring Boot or * Quarkus).
