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);
+ } else if (logger.isDebugEnabled()) {
+ logger.debug("Hayward Connection thing: {}", getCallingMethod());
+ }
- 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);
+ 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);
+ }
}
- } 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 "";
}
+ return "";
}
private String getCallingMethod() {