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,
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();