[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 <dannybaumann@web.de>
This commit is contained in:
maniac103 2023-04-07 14:25:20 +02:00 committed by GitHub
parent 86f829fa21
commit 49e407d028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View 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