From 49e407d028f64ae0c646823f0b65a5fbd47941a0 Mon Sep 17 00:00:00 2001 From: maniac103 Date: Fri, 7 Apr 2023 14:25:20 +0200 Subject: [PATCH] [gardena] Improve GardenaSmartImpl initialization order (#14722) 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 --- .../gardena/internal/GardenaSmartImpl.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/GardenaSmartImpl.java b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/GardenaSmartImpl.java index 1f2e3d6ea50..12dd5d8ab8f 100644 --- a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/GardenaSmartImpl.java +++ b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/GardenaSmartImpl.java @@ -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