camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [camel] 02/04: CAMEL-12807 Avoid to use endpoint attribute when MqttConnectOptions is declared once
Date Fri, 14 Sep 2018 13:40:25 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 7c8df4751eaa45716b52cfa5e9da1bf47f1f2221
Author: Fabrizio Spataro <fabrizio.spataro@bizmate.it>
AuthorDate: Thu Sep 13 15:37:45 2018 +0200

    CAMEL-12807 Avoid to use endpoint attribute when MqttConnectOptions is declared once
---
 .../camel-paho/src/main/docs/paho-component.adoc   |  1 +
 .../apache/camel/component/paho/PahoEndpoint.java  | 28 +++++++++++++++-------
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/components/camel-paho/src/main/docs/paho-component.adoc b/components/camel-paho/src/main/docs/paho-component.adoc
index 723f883..0514235 100644
--- a/components/camel-paho/src/main/docs/paho-component.adoc
+++ b/components/camel-paho/src/main/docs/paho-component.adoc
@@ -95,6 +95,7 @@ with the following path and query parameters:
 | *brokerUrl* (common) | The URL of the MQTT broker. | tcp://localhost:1883 | String
 | *clientId* (common) | MQTT client identifier. |  | String
 | *connectOptions* (common) | Client connection options |  | MqttConnectOptions
+| *resolveMqttConnectOptions* (common) | Auto Resolve Client connection options | true |
boolean
 | *filePersistenceDirectory* (common) | Base directory used by the file persistence provider.
|  | String
 | *password* (common) | Password to be used for authentication against the MQTT broker |
 | String
 | *persistence* (common) | Client persistence to be used - memory or file. | MEMORY | PahoPersistence
diff --git a/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoEndpoint.java
b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoEndpoint.java
index 8d858d5..6d58751 100644
--- a/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoEndpoint.java
+++ b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoEndpoint.java
@@ -68,7 +68,8 @@ public class PahoEndpoint extends DefaultEndpoint {
     private String userName; 
     @UriParam @Metadata(secret = true)
     private String password; 
-    
+    @UriParam(defaultValue = "true")
+    private boolean resolveMqttConnectOptions = true; 
 
     // Collaboration members
     @UriParam
@@ -135,13 +136,16 @@ public class PahoEndpoint extends DefaultEndpoint {
         if (connectOptions != null) {
             return connectOptions;
         }
-        Set<MqttConnectOptions> connectOptions = getCamelContext().getRegistry().findByType(MqttConnectOptions.class);
-        if (connectOptions.size() == 1) {
-            LOG.info("Single MqttConnectOptions instance found in the registry. It will be
used by the endpoint.");
-            return connectOptions.iterator().next();
-        } else if (connectOptions.size() > 1) {
-            LOG.warn("Found {} instances of the MqttConnectOptions in the registry. None
of these will be used by the endpoint. "
-                     + "Please use 'connectOptions' endpoint option to select one.", connectOptions.size());
+        
+        if(resolveMqttConnectOptions) {
+            Set<MqttConnectOptions> connectOptions = getCamelContext().getRegistry().findByType(MqttConnectOptions.class);
+            if (connectOptions.size() == 1) {
+                LOG.info("Single MqttConnectOptions instance found in the registry. It will
be used by the endpoint.");
+                return connectOptions.iterator().next();
+            } else if (connectOptions.size() > 1) {
+                LOG.warn("Found {} instances of the MqttConnectOptions in the registry. None
of these will be used by the endpoint. "
+                         + "Please use 'connectOptions' endpoint option to select one.",
connectOptions.size());
+            }
         }
         
         MqttConnectOptions options = new MqttConnectOptions();
@@ -306,4 +310,12 @@ public class PahoEndpoint extends DefaultEndpoint {
         this.password = password;
     }
 
+    public synchronized boolean isResolveMqttConnectOptions() {
+        return resolveMqttConnectOptions;
+    }
+
+    public synchronized void setResolveMqttConnectOptions(boolean resolveMqttConnectOptions)
{
+        this.resolveMqttConnectOptions = resolveMqttConnectOptions;
+    }
+
 }


Mime
View raw message