@Override public void fetchSegmentToLocal(final String uri, final File tempFile) throws Exception { RetryPolicies.exponentialBackoffRetryPolicy(_retryCount, _retryWaitMs, 5).attempt(() -> { try { int statusCode = _httpClient.downloadFile(new URI(uri), tempFile); _logger.info("Downloaded file from: {} to: {}; Length of downloaded file: {}; Response status code: {}", uri, tempFile, tempFile.length(), statusCode); return true; } catch (HttpErrorStatusException e) { int statusCode = e.getStatusCode(); if (statusCode >= 500) { // Temporary exception _logger.warn("Caught temporary exception while downloading file from: {}, will retry", uri, e); return false; } else { // Permanent exception _logger.error("Caught permanent exception while downloading file from: {}, won't retry", uri, e); throw e; } } catch (Exception e) { _logger.warn("Caught temporary exception while downloading file from: {}, will retry", uri, e); return false; } }); }
int statusCode = statusLine.getStatusCode(); if (statusCode >= 300) { throw new HttpErrorStatusException(getErrorMessage(request, response), statusCode);
return true; } catch (HttpErrorStatusException e) { int statusCode = e.getStatusCode(); if (statusCode == HttpStatus.SC_CONFLICT || statusCode >= 500) {
private SimpleHttpResponse sendRequest(HttpUriRequest request) throws IOException, HttpErrorStatusException { try (CloseableHttpResponse response = _httpClient.execute(request)) { String controllerHost = null; String controllerVersion = null; if (response.containsHeader(CommonConstants.Controller.HOST_HTTP_HEADER)) { controllerHost = response.getFirstHeader(CommonConstants.Controller.HOST_HTTP_HEADER).getValue(); controllerVersion = response.getFirstHeader(CommonConstants.Controller.VERSION_HTTP_HEADER).getValue(); } if (controllerHost != null) { LOGGER.info(String .format("Sending request: %s to controller: %s, version: %s", request.getURI(), controllerHost, controllerVersion)); } int statusCode = response.getStatusLine().getStatusCode(); if (statusCode >= 300) { throw new HttpErrorStatusException(getErrorMessage(request, response), statusCode); } return new SimpleHttpResponse(statusCode, EntityUtils.toString(response.getEntity())); } }