You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/12/08 09:46:42 UTC

[camel] branch main updated (d5dda39 -> 24dd1a9)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from d5dda39  Update bean-binding.adoc
     new 1d032c3  Polished
     new 24dd1a9  CAMEL-17299: camel-jbang - Add --port option to enable embedded http server

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../VertxPlatformHttpServerConfiguration.java      | 19 ++++++++++++++++++
 .../platform/http/PlatformHttpComponent.java       | 12 +++++------
 .../http/JettyCustomPlatformHttpEngine.java        |  2 +-
 dsl/camel-jbang/camel-jbang-core/pom.xml           |  4 ++++
 .../apache/camel/dsl/jbang/core/commands/Run.java  |  6 ++++++
 .../DependencyDownloaderComponentResolver.java     |  6 +++---
 .../java/org/apache/camel/main/KameletMain.java    |  6 ++++++
 .../org/apache/camel/main/VertxHttpServer.java     | 23 ++++++++++++++++++++--
 8 files changed, 65 insertions(+), 13 deletions(-)

[camel] 01/02: Polished

Posted by da...@apache.org.
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

commit 1d032c31a495276a219d70f69e9caa80f32b2816
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Dec 8 10:04:44 2021 +0100

    Polished
---
 .../camel/component/platform/http/PlatformHttpComponent.java | 12 +++++-------
 .../platform/http/JettyCustomPlatformHttpEngine.java         |  2 +-
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
index ead93d6..f67b023 100644
--- a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
+++ b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpComponent.java
@@ -45,14 +45,14 @@ import org.slf4j.LoggerFactory;
  */
 @Component("platform-http")
 public class PlatformHttpComponent extends DefaultComponent implements RestConsumerFactory, RestApiConsumerFactory {
-    private static final Logger LOGGER = LoggerFactory.getLogger(PlatformHttpComponent.class);
+    private static final Logger LOG = LoggerFactory.getLogger(PlatformHttpComponent.class);
 
     @Metadata(label = "advanced", description = "An HTTP Server engine implementation to serve the requests")
     private volatile PlatformHttpEngine engine;
 
     private volatile boolean localEngine;
 
-    private final Object lock;
+    private final Object lock = new Object();
 
     public PlatformHttpComponent() {
         this(null);
@@ -60,8 +60,6 @@ public class PlatformHttpComponent extends DefaultComponent implements RestConsu
 
     public PlatformHttpComponent(CamelContext context) {
         super(context);
-
-        this.lock = new Object();
     }
 
     @Override
@@ -182,13 +180,13 @@ public class PlatformHttpComponent extends DefaultComponent implements RestConsu
         if (engine == null) {
             synchronized (lock) {
                 if (engine == null) {
-                    LOGGER.debug("Lookup platform http engine from registry");
+                    LOG.debug("Lookup platform http engine from registry");
 
                     engine = getCamelContext().getRegistry()
                             .lookupByNameAndType(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME, PlatformHttpEngine.class);
 
                     if (engine == null) {
-                        LOGGER.debug("Lookup platform http engine from factory");
+                        LOG.debug("Lookup platform http engine from factory");
 
                         engine = getCamelContext()
                                 .adapt(ExtendedCamelContext.class)
@@ -216,7 +214,7 @@ public class PlatformHttpComponent extends DefaultComponent implements RestConsu
         try {
             RestConfiguration config = CamelContextHelper.getRestConfiguration(getCamelContext(), "platform-http");
 
-            // configure additional options on  configuration
+            // configure additional options on configuration
             if (config.getComponentProperties() != null && !config.getComponentProperties().isEmpty()) {
                 setProperties(this, config.getComponentProperties());
             }
diff --git a/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/JettyCustomPlatformHttpEngine.java b/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/JettyCustomPlatformHttpEngine.java
index 02adada..c5301f0 100644
--- a/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/JettyCustomPlatformHttpEngine.java
+++ b/components/camel-platform-http/src/test/java/org/apache/camel/component/platform/http/JettyCustomPlatformHttpEngine.java
@@ -21,9 +21,9 @@ import org.apache.camel.Processor;
 import org.apache.camel.component.platform.http.spi.PlatformHttpEngine;
 
 public class JettyCustomPlatformHttpEngine implements PlatformHttpEngine {
+
     @Override
     public Consumer createConsumer(PlatformHttpEndpoint platformHttpEndpoint, Processor processor) {
-
         return new JettyCustomPlatformHttpConsumer(platformHttpEndpoint, processor);
     }
 }

[camel] 02/02: CAMEL-17299: camel-jbang - Add --port option to enable embedded http server

Posted by da...@apache.org.
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

commit 24dd1a926319dfa68fe83a3acbc0ceb09a836bed
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Dec 8 10:43:30 2021 +0100

    CAMEL-17299: camel-jbang - Add --port option to enable embedded http server
---
 .../VertxPlatformHttpServerConfiguration.java      | 19 ++++++++++++++++++
 dsl/camel-jbang/camel-jbang-core/pom.xml           |  4 ++++
 .../apache/camel/dsl/jbang/core/commands/Run.java  |  6 ++++++
 .../DependencyDownloaderComponentResolver.java     |  6 +++---
 .../java/org/apache/camel/main/KameletMain.java    |  6 ++++++
 .../org/apache/camel/main/VertxHttpServer.java     | 23 ++++++++++++++++++++--
 6 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServerConfiguration.java b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServerConfiguration.java
index a17e594..9bb4806 100644
--- a/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServerConfiguration.java
+++ b/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpServerConfiguration.java
@@ -22,6 +22,9 @@ import java.util.List;
 
 import org.apache.camel.support.jsse.SSLContextParameters;
 
+/**
+ * HTTP server configuration
+ */
 public class VertxPlatformHttpServerConfiguration {
     public static final String DEFAULT_BIND_HOST = "0.0.0.0";
     public static final int DEFAULT_BIND_PORT = 8080;
@@ -38,6 +41,22 @@ public class VertxPlatformHttpServerConfiguration {
     private BodyHandler bodyHandler = new BodyHandler();
     private Cors cors = new Cors();
 
+    public int getPort() {
+        return getBindPort();
+    }
+
+    public void setPort(int port) {
+        setBindPort(port);
+    }
+
+    public void setHost(String host) {
+        setBindHost(host);
+    }
+
+    public String getHost() {
+        return getBindHost();
+    }
+
     public String getBindHost() {
         return bindHost;
     }
diff --git a/dsl/camel-jbang/camel-jbang-core/pom.xml b/dsl/camel-jbang/camel-jbang-core/pom.xml
index a33b6eb..b6bc866 100644
--- a/dsl/camel-jbang/camel-jbang-core/pom.xml
+++ b/dsl/camel-jbang/camel-jbang-core/pom.xml
@@ -68,6 +68,10 @@
             <artifactId>camel-file-watch</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-platform-http-vertx</artifactId>
+        </dependency>
+        <dependency>
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
         </dependency>
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index 0c808ee..42d037e 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -82,6 +82,9 @@ class Run implements Callable<Integer> {
             description = "Local directory to load Kamelets from (take precedence))")
     private String localKameletDir;
 
+    @Option(names = { "--port" }, description = "Embeds a local HTTP server on this port")
+    private int port;
+
     @Override
     public Integer call() throws Exception {
         if (stopRequested) {
@@ -135,6 +138,9 @@ class Run implements Callable<Integer> {
         if (maxIdleSeconds > 0) {
             main.addInitialProperty("camel.main.durationMaxIdleSeconds", String.valueOf(maxIdleSeconds));
         }
+        if (port > 0) {
+            main.addInitialProperty("camel.jbang.platform-http.port", String.valueOf(port));
+        }
 
         if (fileLock) {
             lockFile = createLockFile();
diff --git a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/DependencyDownloaderComponentResolver.java b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/DependencyDownloaderComponentResolver.java
index af6f6bd..ec05475 100644
--- a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/DependencyDownloaderComponentResolver.java
+++ b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/DependencyDownloaderComponentResolver.java
@@ -57,11 +57,11 @@ final class DependencyDownloaderComponentResolver extends DefaultComponentResolv
         if ("platform-http".equals(name) && !DownloaderHelper.alreadyOnClasspath(camelContext, "camel-platform-http-vertx")) {
             DownloaderHelper.downloadDependency(camelContext, model.getGroupId(), "camel-platform-http-vertx",
                     model.getVersion());
-
-            // setup a default http server on port 8080
-            VertxHttpServer.registerServer(camelContext);
         }
 
+        // setup a default http server on port 8080 if not already done when using platform-http
+        VertxHttpServer.registerServer(camelContext);
+
         return super.resolveComponent(name, context);
     }
 
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 356fad4..9ade32a 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
@@ -161,6 +161,12 @@ public class KameletMain extends MainCommandLineSupport {
         answer.setApplicationContextClassLoader(kameletClassLoader);
         answer.setRegistry(registry);
 
+        // embed HTTP server if port is specified
+        Object port = getInitialProperties().get("camel.jbang.platform-http.port");
+        if (port != null) {
+            VertxHttpServer.registerServer(answer, Integer.parseInt(port.toString()));
+        }
+
         if (download) {
             try {
                 // use resolver that can auto downloaded
diff --git a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
index b443a7c..2014be2 100644
--- a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
+++ b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/VertxHttpServer.java
@@ -16,27 +16,46 @@
  */
 package org.apache.camel.main;
 
+import java.util.concurrent.atomic.AtomicBoolean;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.support.IntrospectionSupport;
 
 /**
  * To setup vertx http server in the running Camel application
  */
 public final class VertxHttpServer {
 
+    private static final AtomicBoolean REGISTERED = new AtomicBoolean();
+
     private VertxHttpServer() {
     }
 
     public static void registerServer(CamelContext camelContext) {
+        if (REGISTERED.compareAndSet(false, true)) {
+            doRegisterServer(camelContext, 8080);
+        }
+    }
+
+    public static void registerServer(CamelContext camelContext, int port) {
+        if (REGISTERED.compareAndSet(false, true)) {
+            doRegisterServer(camelContext, port);
+        }
+    }
+
+    private static void doRegisterServer(CamelContext camelContext, int port) {
         try {
             // must load via the classloader set on camel context that will have the classes on its classpath
-            Class clazz = camelContext.getClassResolver()
+            Class<?> clazz = camelContext.getClassResolver()
                     .resolveMandatoryClass(
                             "org.apache.camel.component.platform.http.vertx.VertxPlatformHttpServerConfiguration");
             Object config = clazz.getConstructors()[0].newInstance();
+            IntrospectionSupport.setProperty(camelContext, config, "port", port);
 
             clazz = camelContext.getClassResolver()
-                    .resolveMandatoryClass("org.apache.camel.component.platform.http.vertx.VertxPlatformHttpServer");
+                    .resolveMandatoryClass(
+                            "org.apache.camel.component.platform.http.vertx.VertxPlatformHttpServer");
             Object server = clazz.getConstructors()[0].newInstance(config);
 
             camelContext.addService(server);