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


The following commit(s) were added to refs/heads/main by this push:
     new d515cd9  (chores) camel-paho cleanup (#5690)
d515cd9 is described below

commit d515cd98bb05ccd6bef46bd37226255eb1222437
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Thu Jun 17 12:46:27 2021 +0200

    (chores) camel-paho cleanup (#5690)
    
    - ensure the client is closed to avoid leaking resources during credentials 
verification
    - avoid shadowing the configuration object when duplicating it at endpoint 
creation
---
 .../java/org/apache/camel/component/paho/PahoComponent.java    |  4 ++--
 .../camel/component/paho/PahoComponentVerifierExtension.java   | 10 ++++------
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git 
a/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoComponent.java
 
b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoComponent.java
index 493e2e6..b08e472 100644
--- 
a/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoComponent.java
+++ 
b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoComponent.java
@@ -51,9 +51,9 @@ public class PahoComponent extends DefaultComponent {
     protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
         // Each endpoint can have its own configuration so make
         // a copy of the configuration
-        PahoConfiguration configuration = getConfiguration().copy();
+        PahoConfiguration pahoConfiguration = getConfiguration().copy();
 
-        PahoEndpoint answer = new PahoEndpoint(uri, remaining, this, 
configuration);
+        PahoEndpoint answer = new PahoEndpoint(uri, remaining, this, 
pahoConfiguration);
         answer.setClient(client);
 
         setProperties(answer, parameters);
diff --git 
a/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoComponentVerifierExtension.java
 
b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoComponentVerifierExtension.java
index fc0c121..3e7c54a 100644
--- 
a/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoComponentVerifierExtension.java
+++ 
b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoComponentVerifierExtension.java
@@ -65,20 +65,18 @@ public class PahoComponentVerifierExtension extends 
DefaultComponentVerifierExte
         String password = (String) parameters.get("password");
 
         if (ObjectHelper.isNotEmpty(brokerUrl)) {
-            try {
-                // Create MQTT client
+            // Create MQTT client
+            try (MqttClient client = new MqttClient(brokerUrl, 
MqttClient.generateClientId())) {
                 if (ObjectHelper.isEmpty(username) && 
ObjectHelper.isEmpty(password)) {
-                    MqttClient client = new MqttClient(brokerUrl, 
MqttClient.generateClientId());
                     client.connect();
-                    client.disconnect();
                 } else {
-                    MqttClient client = new MqttClient(brokerUrl, 
MqttClient.generateClientId());
                     MqttConnectOptions connOpts = new MqttConnectOptions();
                     connOpts.setUserName(username);
                     connOpts.setPassword(password.toCharArray());
                     client.connect(connOpts);
-                    client.disconnect();
                 }
+
+                client.disconnect();
             } catch (MqttException e) {
                 builder.error(
                         ResultErrorBuilder

Reply via email to