[haywardomnilogic] Add http timeout retry (#13164)

* Add HTTP Timeout Retry
* Updated try/catch messaging
* Repositioned some logging to occur before http request

Signed-off-by: Matt Myers <mmyers75@icloud.com>
This commit is contained in:
Matt
2022-07-27 04:31:40 -04:00
committed by GitHub
parent 67006de606
commit 1181a104f9

View File

@@ -437,6 +437,13 @@ public class HaywardBridgeHandler extends BaseBridgeHandler {
String urlParameterslength = Integer.toString(urlParameters.length());
String statusMessage;
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")
@@ -455,16 +462,12 @@ public class HaywardBridgeHandler extends BaseBridgeHandler {
}
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);
}
@@ -472,14 +475,22 @@ public class HaywardBridgeHandler extends BaseBridgeHandler {
}
} catch (ExecutionException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Unable to resolve host. Check Hayward hostname and your internet connection. " + e);
"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);
"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() {
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();