org.apache.commons.httpclient.NoHttpResponseException Java Examples
The following examples show how to use
org.apache.commons.httpclient.NoHttpResponseException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpTemplateDownloader.java From cloudstack with Apache License 2.0 | 6 votes |
private HttpMethodRetryHandler createRetryTwiceHandler() { return new HttpMethodRetryHandler() { @Override public boolean retryMethod(final HttpMethod method, final IOException exception, int executionCount) { if (executionCount >= 2) { // Do not retry if over max retry count return false; } if (exception instanceof NoHttpResponseException) { // Retry if the server dropped connection on us return true; } if (!method.isRequestSent()) { // Retry if the request has not been sent fully or // if it's OK to retry methods that have been sent return true; } // otherwise do not retry return false; } }; }
Example #2
Source File: MetalinkTemplateDownloader.java From cloudstack with Apache License 2.0 | 6 votes |
protected HttpMethodRetryHandler createRetryTwiceHandler() { return new HttpMethodRetryHandler() { @Override public boolean retryMethod(final HttpMethod method, final IOException exception, int executionCount) { if (executionCount >= 2) { // Do not retry if over max retry count return false; } if (exception instanceof NoHttpResponseException) { // Retry if the server dropped connection on us return true; } if (!method.isRequestSent()) { // Retry if the request has not been sent fully or // if it's OK to retry methods that have been sent return true; } // otherwise do not retry return false; } }; }
Example #3
Source File: HTTPUtils.java From cosmic with Apache License 2.0 | 5 votes |
/** * @return A HttpMethodRetryHandler with given number of retries. */ public static HttpMethodRetryHandler getHttpMethodRetryHandler(final int retryCount) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Initializing new HttpMethodRetryHandler with retry count " + retryCount); } return new HttpMethodRetryHandler() { @Override public boolean retryMethod(final HttpMethod method, final IOException exception, final int executionCount) { if (executionCount >= retryCount) { // Do not retry if over max retry count return false; } if (exception instanceof NoHttpResponseException) { // Retry if the server dropped connection on us return true; } if (!method.isRequestSent()) { // Retry if the request has not been sent fully or // if it's OK to retry methods that have been sent return true; } // otherwise do not retry return false; } }; }
Example #4
Source File: HTTPUtils.java From cloudstack with Apache License 2.0 | 5 votes |
/** * @return A HttpMethodRetryHandler with given number of retries. */ public static HttpMethodRetryHandler getHttpMethodRetryHandler(final int retryCount) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Initializing new HttpMethodRetryHandler with retry count " + retryCount); } return new HttpMethodRetryHandler() { @Override public boolean retryMethod(final HttpMethod method, final IOException exception, int executionCount) { if (executionCount >= retryCount) { // Do not retry if over max retry count return false; } if (exception instanceof NoHttpResponseException) { // Retry if the server dropped connection on us return true; } if (!method.isRequestSent()) { // Retry if the request has not been sent fully or // if it's OK to retry methods that have been sent return true; } // otherwise do not retry return false; } }; }
Example #5
Source File: HttpTemplateDownloader.java From cosmic with Apache License 2.0 | 4 votes |
public HttpTemplateDownloader(final StorageLayer storageLayer, final String downloadUrl, final String toDir, final DownloadCompleteCallback callback, final long maxTemplateSizeInBytes, final String user, final String password, final Proxy proxy, final ResourceType resourceType) { this._storage = storageLayer; this.downloadUrl = downloadUrl; setToDir(toDir); this.status = TemplateDownloadStatus.NOT_STARTED; this.resourceType = resourceType; this.maxTemplateSizeInBytes = maxTemplateSizeInBytes; this.totalBytes = 0; this.client = new HttpClient(s_httpClientManager); this.myretryhandler = (method, exception, executionCount) -> { if (executionCount >= 2) { // Do not retry if over max retry count return false; } if (exception instanceof NoHttpResponseException) { // Retry if the server dropped connection on us return true; } if (!method.isRequestSent()) { // Retry if the request has not been sent fully or // if it's OK to retry methods that have been sent return true; } // otherwise do not retry return false; }; try { this.request = new GetMethod(downloadUrl); this.request.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, this.myretryhandler); this.completionCallback = callback; this.request.setFollowRedirects(true); final File f = File.createTempFile("dnld", "tmp_", new File(toDir)); if (this._storage != null) { this._storage.setWorldReadableAndWriteable(f); } this.toFile = f.getAbsolutePath(); final Pair<String, Integer> hostAndPort = UriUtils.validateUrl(downloadUrl); if (proxy != null) { this.client.getHostConfiguration().setProxy(proxy.getHost(), proxy.getPort()); if (proxy.getUserName() != null) { final Credentials proxyCreds = new UsernamePasswordCredentials(proxy.getUserName(), proxy.getPassword()); this.client.getState().setProxyCredentials(AuthScope.ANY, proxyCreds); } } if (user != null && password != null) { this.client.getParams().setAuthenticationPreemptive(true); final Credentials defaultcreds = new UsernamePasswordCredentials(user, password); this.client.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds); s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second()); } else { s_logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second()); } } catch (final IllegalArgumentException iae) { this.errorString = iae.getMessage(); this.status = TemplateDownloadStatus.UNRECOVERABLE_ERROR; this.inited = false; } catch (final Exception ex) { this.errorString = "Unable to start download -- check url? "; this.status = TemplateDownloadStatus.UNRECOVERABLE_ERROR; s_logger.warn("Exception in constructor -- " + ex.toString()); } }