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 2024/03/28 14:40:45 UTC

(camel) 31/38: CAMEL-20557: Rest DSL to use openapi spec directly

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

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

commit 4d00975a471709b0e3a63d7520c0d0fae697b054
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 27 10:19:51 2024 +0100

    CAMEL-20557: Rest DSL to use openapi spec directly
---
 .../platform/http/PlatformHttpComponent.java          | 12 +++++++-----
 .../component/platform/http/PlatformHttpConsumer.java | 19 ++++++++++++++++---
 2 files changed, 23 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 7dfa58a4d02..5e8b15740ef 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
@@ -90,7 +90,7 @@ public class PlatformHttpComponent extends DefaultComponent
         // reuse the createConsumer method we already have. The api need to use GET and match on uri prefix
         return doCreateConsumer(camelContext, processor, "GET", contextPath, null, null, "application/json,text/yaml",
                 configuration,
-                parameters, true);
+                parameters, true, true);
     }
 
     @Override
@@ -100,7 +100,7 @@ public class PlatformHttpComponent extends DefaultComponent
             String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters)
             throws Exception {
         return doCreateConsumer(camelContext, processor, verb, basePath, uriTemplate, consumes, produces, configuration,
-                parameters, false);
+                parameters, false, true);
     }
 
     @Override
@@ -109,7 +109,7 @@ public class PlatformHttpComponent extends DefaultComponent
             Map<String, Object> parameters)
             throws Exception {
         return doCreateConsumer(camelContext, processor, null, contextPath, null, null, null, configuration,
-                parameters, true);
+                parameters, true, false);
     }
 
     /**
@@ -196,7 +196,8 @@ public class PlatformHttpComponent extends DefaultComponent
     private Consumer doCreateConsumer(
             CamelContext camelContext, Processor processor, String verb, String basePath,
             String uriTemplate,
-            String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters, boolean api)
+            String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters,
+            boolean api, boolean register)
             throws Exception {
 
         String path = basePath;
@@ -246,7 +247,8 @@ public class PlatformHttpComponent extends DefaultComponent
         endpoint.setProduces(produces);
 
         // configure consumer properties
-        Consumer consumer = endpoint.createConsumer(processor);
+        PlatformHttpConsumer consumer = (PlatformHttpConsumer) endpoint.createConsumer(processor);
+        consumer.setRegister(register);
         if (config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) {
             setProperties(camelContext, consumer, config.getConsumerProperties());
         }
diff --git a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConsumer.java b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConsumer.java
index 5fb01bf62f1..c2020081876 100644
--- a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConsumer.java
+++ b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpConsumer.java
@@ -27,6 +27,7 @@ import org.apache.camel.support.service.ServiceHelper;
 public class PlatformHttpConsumer extends DefaultConsumer implements Suspendable, SuspendableService {
 
     private Consumer delegatedConsumer;
+    private boolean register = true;
 
     public PlatformHttpConsumer(Endpoint endpoint, Processor processor) {
         super(endpoint, processor);
@@ -41,6 +42,14 @@ public class PlatformHttpConsumer extends DefaultConsumer implements Suspendable
         return getEndpoint().getComponent();
     }
 
+    public boolean isRegister() {
+        return register;
+    }
+
+    public void setRegister(boolean register) {
+        this.register = register;
+    }
+
     @Override
     protected void doInit() throws Exception {
         super.doInit();
@@ -51,14 +60,18 @@ public class PlatformHttpConsumer extends DefaultConsumer implements Suspendable
     protected void doStart() throws Exception {
         super.doStart();
         ServiceHelper.startService(delegatedConsumer);
-        getComponent().addHttpEndpoint(getEndpoint().getPath(), getEndpoint().getHttpMethodRestrict(),
-                getEndpoint().getConsumes(), getEndpoint().getProduces(), delegatedConsumer);
+        if (register) {
+            getComponent().addHttpEndpoint(getEndpoint().getPath(), getEndpoint().getHttpMethodRestrict(),
+                    getEndpoint().getConsumes(), getEndpoint().getProduces(), delegatedConsumer);
+        }
     }
 
     @Override
     protected void doStop() throws Exception {
         super.doStop();
-        getComponent().removeHttpEndpoint(getEndpoint().getPath());
+        if (register) {
+            getComponent().removeHttpEndpoint(getEndpoint().getPath());
+        }
         ServiceHelper.stopAndShutdownServices(delegatedConsumer);
     }