From 78178efdae546c319fb018636b2d317ae638e765 Mon Sep 17 00:00:00 2001 From: lolodomo Date: Sat, 22 Jun 2024 12:01:30 +0200 Subject: [PATCH] [hue] API v1: retry once on timeout for GET requests to the bridge (#16902) Fix #16723 Signed-off-by: Laurent Garnier Signed-off-by: Patrik Gfeller --- .../hue/internal/connection/HueBridge.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/connection/HueBridge.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/connection/HueBridge.java index 70a7eca096aab..2f6acf0fac915 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/connection/HueBridge.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/connection/HueBridge.java @@ -1096,6 +1096,11 @@ private HueResult doNetwork(String address, HttpMethod requestMethod) private HueResult doNetwork(String address, HttpMethod requestMethod, @Nullable String body) throws ConfigurationException, CommunicationException { + return doNetwork(address, requestMethod, body, requestMethod == HttpMethod.GET); + } + + private HueResult doNetwork(String address, HttpMethod requestMethod, @Nullable String body, boolean retryOnTimeout) + throws ConfigurationException, CommunicationException { logger.trace("Hue request: {} - URL = '{}'", requestMethod, address); try { final Request request = httpClient.newRequest(address).method(requestMethod).timeout(timeout, @@ -1123,9 +1128,14 @@ private HueResult doNetwork(String address, HttpMethod requestMethod, @Nullable e.getCause()); } } catch (TimeoutException e) { - String message = e.getMessage(); - logger.debug("TimeoutException occurred during execution: {}", message, e); - throw new CommunicationException(message == null ? TEXT_OFFLINE_COMMUNICATION_ERROR : message); + if (retryOnTimeout) { + logger.debug("TimeoutException occurred during execution, retry"); + return doNetwork(address, requestMethod, body, false); + } else { + String message = e.getMessage(); + logger.debug("TimeoutException occurred during execution: {}", message, e); + throw new CommunicationException(message == null ? TEXT_OFFLINE_COMMUNICATION_ERROR : message); + } } catch (InterruptedException e) { Thread.currentThread().interrupt(); String message = e.getMessage();