diff --git a/bundles/org.openhab.binding.haywardomnilogic/src/main/java/org/openhab/binding/haywardomnilogic/internal/handler/HaywardBridgeHandler.java b/bundles/org.openhab.binding.haywardomnilogic/src/main/java/org/openhab/binding/haywardomnilogic/internal/handler/HaywardBridgeHandler.java index 038c2c8ab..6440d6911 100644 --- a/bundles/org.openhab.binding.haywardomnilogic/src/main/java/org/openhab/binding/haywardomnilogic/internal/handler/HaywardBridgeHandler.java +++ b/bundles/org.openhab.binding.haywardomnilogic/src/main/java/org/openhab/binding/haywardomnilogic/internal/handler/HaywardBridgeHandler.java @@ -437,48 +437,59 @@ public class HaywardBridgeHandler extends BaseBridgeHandler { String urlParameterslength = Integer.toString(urlParameters.length()); String statusMessage; - try { - ContentResponse httpResponse = sendRequestBuilder(config.endpointUrl, HttpMethod.POST) - .content(new StringContentProvider(urlParameters), "text/xml; charset=utf-8") - .header(HttpHeader.CONTENT_LENGTH, urlParameterslength).send(); - - int status = httpResponse.getStatus(); - String xmlResponse = httpResponse.getContentAsString(); - - if (status == 200) { - List statusMessages = evaluateXPath( - "/Response/Parameters//Parameter[@name='StatusMessage']/text()", xmlResponse); - if (!(statusMessages.isEmpty())) { - statusMessage = statusMessages.get(0); - } else { - statusMessage = httpResponse.getReason(); - } - - if (logger.isTraceEnabled()) { - logger.trace("Hayward Connection thing: {} Hayward http command: {}", getCallingMethod(), - urlParameters); - logger.trace("Hayward Connection thing: {} Hayward http response: {} {}", getCallingMethod(), - statusMessage, xmlResponse); - } - return xmlResponse; - } else { - if (logger.isDebugEnabled()) { - logger.debug("Hayward Connection thing: {} Hayward http command: {}", getCallingMethod(), - urlParameters); - logger.debug("Hayward Connection thing: {} Hayward http response: {} {}", getCallingMethod(), - status, xmlResponse); - } - return ""; - } - } catch (ExecutionException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Unable to resolve host. Check Hayward hostname and your internet connection. " + e); - return ""; - } catch (TimeoutException e) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Connection Timeout. Check Hayward hostname and your internet connection. " + e); - return ""; + if (logger.isTraceEnabled()) { + logger.trace("Hayward Connection thing: {} Hayward http command: {}", getCallingMethod(), urlParameters); + } else if (logger.isDebugEnabled()) { + logger.debug("Hayward Connection thing: {}", getCallingMethod()); } + + for (int retry = 0; retry <= 2; retry++) { + try { + ContentResponse httpResponse = sendRequestBuilder(config.endpointUrl, HttpMethod.POST) + .content(new StringContentProvider(urlParameters), "text/xml; charset=utf-8") + .header(HttpHeader.CONTENT_LENGTH, urlParameterslength).send(); + + int status = httpResponse.getStatus(); + String xmlResponse = httpResponse.getContentAsString(); + + if (status == 200) { + List statusMessages = evaluateXPath( + "/Response/Parameters//Parameter[@name='StatusMessage']/text()", xmlResponse); + if (!(statusMessages.isEmpty())) { + statusMessage = statusMessages.get(0); + } else { + statusMessage = httpResponse.getReason(); + } + + if (logger.isTraceEnabled()) { + logger.trace("Hayward Connection thing: {} Hayward http response: {} {}", getCallingMethod(), + statusMessage, xmlResponse); + } + return xmlResponse; + } else { + if (logger.isDebugEnabled()) { + logger.debug("Hayward Connection thing: {} Hayward http response: {} {}", getCallingMethod(), + status, xmlResponse); + } + return ""; + } + } catch (ExecutionException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Unable to resolve host. Check Hayward hostname and your internet connection. " + + e.getMessage()); + return ""; + } catch (TimeoutException e) { + if (retry >= 2) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Connection Timeout. Check Hayward hostname and your internet connection. " + + e.getMessage()); + return ""; + } else { + logger.warn("Hayward Connection thing Timeout: {} Try: {} ", getCallingMethod(), retry + 1); + } + } + } + return ""; } private String getCallingMethod() {