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 2019/12/11 10:42:41 UTC

[camel] branch master updated: CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - webhook

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 9d16fee  CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - webhook
9d16fee is described below

commit 9d16fee7bb583aadce2682010b7f8d3876f8307d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Dec 11 11:42:06 2019 +0100

    CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - webhook
---
 .../camel/component/webhook/WebhookComponent.java  | 26 ++++++++--------------
 .../camel/component/webhook/WebhookEndpoint.java   | 19 ++++++++--------
 2 files changed, 19 insertions(+), 26 deletions(-)

diff --git a/components/camel-webhook/src/main/java/org/apache/camel/component/webhook/WebhookComponent.java b/components/camel-webhook/src/main/java/org/apache/camel/component/webhook/WebhookComponent.java
index 681fef4..ab22405 100644
--- a/components/camel-webhook/src/main/java/org/apache/camel/component/webhook/WebhookComponent.java
+++ b/components/camel-webhook/src/main/java/org/apache/camel/component/webhook/WebhookComponent.java
@@ -33,7 +33,7 @@ import org.apache.camel.util.URISupport;
 public class WebhookComponent extends DefaultComponent {
 
     @Metadata(label = "advanced")
-    private WebhookConfiguration configuration;
+    private WebhookConfiguration configuration = new WebhookConfiguration();
 
     public WebhookComponent() {
     }
@@ -45,31 +45,23 @@ public class WebhookComponent extends DefaultComponent {
             throw new IllegalArgumentException("Wrong uri syntax : webhook:uri, got " + remaining);
         }
 
-        WebhookConfiguration configuration = getConfiguration().copy();
-        setProperties(configuration, parameters);
-
-        RestConfiguration restConfig = getCamelContext().getRestConfiguration(configuration.getWebhookComponentName(), true);
-        configuration.setRestConfiguration(restConfig);
-
+        WebhookConfiguration config =  configuration != null ? configuration.copy() : new WebhookConfiguration();
+        WebhookEndpoint endpoint = new WebhookEndpoint(uri, this, config);
+        setProperties(endpoint, parameters);
         // we need to apply the params here
         if (parameters != null && !parameters.isEmpty()) {
             delegateUri = delegateUri + "?" + URISupport.createQueryString(parameters);
         }
-        configuration.setEndpointUri(delegateUri);
+        endpoint.getConfiguration().setEndpointUri(delegateUri);
 
-        return new WebhookEndpoint(
-                uri,
-                this,
-                configuration,
-                delegateUri
-        );
+        RestConfiguration restConfig = getCamelContext().getRestConfiguration(config.getWebhookComponentName(), true);
+        config.setRestConfiguration(restConfig);
+
+        return endpoint;
     }
 
 
     public WebhookConfiguration getConfiguration() {
-        if (this.configuration == null) {
-            this.configuration = new WebhookConfiguration();
-        }
         return this.configuration;
     }
 
diff --git a/components/camel-webhook/src/main/java/org/apache/camel/component/webhook/WebhookEndpoint.java b/components/camel-webhook/src/main/java/org/apache/camel/component/webhook/WebhookEndpoint.java
index a8fa0c0..9011658 100644
--- a/components/camel-webhook/src/main/java/org/apache/camel/component/webhook/WebhookEndpoint.java
+++ b/components/camel-webhook/src/main/java/org/apache/camel/component/webhook/WebhookEndpoint.java
@@ -25,6 +25,7 @@ import org.apache.camel.spi.RestConsumerFactory;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.support.ObjectHelper;
 
 /**
  * The webhook component allows other Camel components that can receive push notifications to expose
@@ -38,16 +39,9 @@ public class WebhookEndpoint extends DefaultEndpoint implements DelegateEndpoint
     @UriParam(label = "advanced")
     private WebhookConfiguration configuration;
 
-    public WebhookEndpoint(String uri, WebhookComponent component, WebhookConfiguration configuration, String delegateUri) {
+    public WebhookEndpoint(String uri, WebhookComponent component, WebhookConfiguration configuration) {
         super(uri, component);
         this.configuration = configuration;
-
-        Endpoint delegate = getCamelContext().getEndpoint(delegateUri);
-        if (!(delegate instanceof WebhookCapableEndpoint)) {
-            throw new IllegalArgumentException("The provided endpoint is not capable of being used in webhook mode: " + delegateUri);
-        }
-        delegateEndpoint = (WebhookCapableEndpoint) delegate;
-        delegateEndpoint.setWebhookConfiguration(configuration);
     }
 
     @Override
@@ -73,6 +67,13 @@ public class WebhookEndpoint extends DefaultEndpoint implements DelegateEndpoint
     protected void doStart() throws Exception {
         super.doStart();
 
+        Endpoint delegate = getCamelContext().getEndpoint(configuration.getEndpointUri());
+        if (!(delegate instanceof WebhookCapableEndpoint)) {
+            throw new IllegalArgumentException("The provided endpoint is not capable of being used in webhook mode: " + configuration.getEndpointUri());
+        }
+        delegateEndpoint = (WebhookCapableEndpoint) delegate;
+        delegateEndpoint.setWebhookConfiguration(configuration);
+
         if (configuration.isWebhookAutoRegister()) {
             log.info("Registering webhook for endpoint {}", delegateEndpoint);
             delegateEndpoint.registerWebhook();
@@ -83,7 +84,7 @@ public class WebhookEndpoint extends DefaultEndpoint implements DelegateEndpoint
     protected void doStop() throws Exception {
         super.doStop();
 
-        if (configuration.isWebhookAutoRegister()) {
+        if (configuration.isWebhookAutoRegister() && delegateEndpoint != null) {
             log.info("Unregistering webhook for endpoint {}", delegateEndpoint);
             delegateEndpoint.unregisterWebhook();
         }