]> git.basschouten.com Git - openhab-addons.git/commitdiff
[gardena] Improve GardenaSmartImpl initialization order (#14722)
authormaniac103 <dannybaumann@web.de>
Fri, 7 Apr 2023 12:25:20 +0000 (14:25 +0200)
committerGitHub <noreply@github.com>
Fri, 7 Apr 2023 12:25:20 +0000 (14:25 +0200)
If an exception occurs during httpClient.start(), webSocketClient
remained null, which led to another (then unhandled) exception being thrown
by dispose(), called in the exception handler.
With the new initialization order it's ensured webSocketClient is not
null at dispose() time, thus allowing proper propagation of the
exception thrown at HTTP startup.

Signed-off-by: Danny Baumann <dannybaumann@web.de>
bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/GardenaSmartImpl.java

index 1f2e3d6ea503e7ad59b0581ecc9a2731ce1002f2..12dd5d8ab8f575b2f704e291579836495d5a5c0f 100644 (file)
@@ -111,19 +111,20 @@ public class GardenaSmartImpl implements GardenaSmart, GardenaSmartWebSocketList
         this.eventListener = eventListener;
         this.scheduler = scheduler;
 
+        String name = ThingWebClientUtil.buildWebClientConsumerName(uid, null);
+        httpClient = httpClientFactory.createHttpClient(name);
+        httpClient.setConnectTimeout(config.getConnectionTimeout() * 1000L);
+        httpClient.setIdleTimeout(httpClient.getConnectTimeout());
+
+        name = ThingWebClientUtil.buildWebClientConsumerName(uid, "ws-");
+        webSocketClient = webSocketFactory.createWebSocketClient(name);
+        webSocketClient.setConnectTimeout(config.getConnectionTimeout() * 1000L);
+        webSocketClient.setStopTimeout(3000);
+        webSocketClient.setMaxIdleTimeout(150000);
+
         logger.debug("Starting GardenaSmart");
         try {
-            String name = ThingWebClientUtil.buildWebClientConsumerName(uid, null);
-            httpClient = httpClientFactory.createHttpClient(name);
-            httpClient.setConnectTimeout(config.getConnectionTimeout() * 1000L);
-            httpClient.setIdleTimeout(httpClient.getConnectTimeout());
             httpClient.start();
-
-            name = ThingWebClientUtil.buildWebClientConsumerName(uid, "ws-");
-            webSocketClient = webSocketFactory.createWebSocketClient(name);
-            webSocketClient.setConnectTimeout(config.getConnectionTimeout() * 1000L);
-            webSocketClient.setStopTimeout(3000);
-            webSocketClient.setMaxIdleTimeout(150000);
             webSocketClient.start();
 
             // initially load access token