[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:
parent
67006de606
commit
1181a104f9
|
@ -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<String> 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<String> 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() {
|
||||
|
|
Loading…
Reference in New Issue