List of usage examples for org.apache.http.impl.client StandardHttpRequestRetryHandler StandardHttpRequestRetryHandler
public StandardHttpRequestRetryHandler()
From source file:com.cloud.utils.rest.HttpClientHelper.java
public static CloseableHttpClient createHttpClient(final int maxRedirects) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { final Registry<ConnectionSocketFactory> socketFactoryRegistry = createSocketFactoryConfigration(); final BasicCookieStore cookieStore = new BasicCookieStore(); return HttpClientBuilder.create() .setConnectionManager(new PoolingHttpClientConnectionManager(socketFactoryRegistry)) .setRedirectStrategy(new LaxRedirectStrategy()) .setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT) .setMaxRedirects(maxRedirects).build()) .setDefaultCookieStore(cookieStore).setRetryHandler(new StandardHttpRequestRetryHandler()).build(); }
From source file:org.jboss.pnc.client.ApacheHttpClient43EngineWithRetry.java
@Override protected HttpClient createDefaultHttpClient() { logger.info("Bootstrapping http engine with request retry handler..."); final HttpClientBuilder builder = HttpClientBuilder.create(); RequestConfig.Builder requestBuilder = RequestConfig.custom(); if (defaultProxy != null) { requestBuilder.setProxy(defaultProxy); }//w w w. ja va 2 s .c om builder.disableContentCompression(); builder.setDefaultRequestConfig(requestBuilder.build()); HttpRequestRetryHandler retryHandler = new StandardHttpRequestRetryHandler(); builder.setRetryHandler(retryHandler); return builder.build(); }
From source file:org.brutusin.rpc.client.http.HttpEndpoint.java
public HttpEndpoint(URI endpoint, Config cfg, HttpClientContextFactory clientContextFactory) { if (endpoint == null) { throw new IllegalArgumentException("Endpoint is required"); }/* www.j a va 2s.c o m*/ if (cfg == null) { cfg = new ConfigurationBuilder().build(); } CacheConfig cacheConfig = CacheConfig.custom().setMaxCacheEntries(cfg.getMaxCacheEntries()) .setMaxObjectSize(cfg.getMaxCacheObjectSize()).build(); RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(1000 * cfg.getConnectTimeOutSeconds()) .setSocketTimeout(1000 * cfg.getSocketTimeOutSeconds()).build(); PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(cfg.getMaxConections()); this.endpoint = endpoint; this.httpClient = CachingHttpClients.custom().setCacheConfig(cacheConfig) .setDefaultRequestConfig(requestConfig).setRetryHandler(new StandardHttpRequestRetryHandler()) .setConnectionManager(cm).build(); this.clientContextFactory = clientContextFactory; initPingThread(cfg.getPingSeconds()); }
From source file:com.amazonaws.mws.MarketplaceWebServiceOrdersClient.java
/** * Configure HttpClient with set of defaults as well as configuration from * MarketplaceWebServiceConfig instance// w w w.ja v a 2s.co m * */ private DefaultHttpClient configureHttpClient(String applicationName, String applicationVersion) { /* Set http client parameters */ HttpParams httpClientParams = new SyncBasicHttpParams(); // respect a user-provided User-Agent header as-is, but if none is // provided // then generate one satisfying the MWS User-Agent requirements if (config.getUserAgent() == null) { config.setUserAgent(quoteAppName(applicationName), quoteAppVersion(applicationVersion), quoteAttributeValue("Java/" + System.getProperty("java.version") + "/" + System.getProperty("java.class.version") + "/" + System.getProperty("java.vendor")), quoteAttributeName("Platform"), quoteAttributeValue("" + System.getProperty("os.name") + "/" + System.getProperty("os.arch") + "/" + System.getProperty("os.version")), quoteAttributeName("MWSClientVersion"), quoteAttributeValue(mwsClientLibraryVersion)); } /* Setup connection parameters */ defaultHeaders.add(new BasicHeader("X-Amazon-User-Agent", config.getUserAgent())); httpClientParams.setParameter(CoreProtocolPNames.USER_AGENT, config.getUserAgent()); // HttpConnectionParams.setConnectionTimeout(httpClientParams, // config.getConnectionTimeout()); // HttpConnectionParams.setSoTimeout(httpClientParams, // config.getSoTimeout()); HttpConnectionParams.setStaleCheckingEnabled(httpClientParams, true); HttpConnectionParams.setTcpNoDelay(httpClientParams, true); /* Set connection manager */ PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(); /* try { HttpRoute route = new HttpRoute(new HttpHost(new URL(config.getServiceURL()).getHost())); connectionManager.setMaxPerRoute(route, config.getMaxAsyncQueueSize()); } catch (MalformedURLException e) { log.warn("Service URL is malformed: " + e.getMessage()); } connectionManager.setMaxTotal(config.getMaxAsyncQueueSize()); */ /* Set http client */ httpClient = new DefaultHttpClient(connectionManager, httpClientParams); httpClient.setHttpRequestRetryHandler(new StandardHttpRequestRetryHandler() { @Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { return super.retryRequest(exception, executionCount, context) && !(exception instanceof UnknownHostException) && !(exception instanceof InterruptedIOException); } }); /* Set proxy if configured */ if (config.isSetProxyHost() && config.isSetProxyPort()) { log.info("Configuring Proxy. Proxy Host: " + config.getProxyHost() + "Proxy Port: " + config.getProxyPort()); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(config.getProxyHost(), config.getProxyPort())); if (config.isSetProxyUsername() && config.isSetProxyPassword()) { httpClient.getCredentialsProvider().setCredentials( new AuthScope(config.getProxyHost(), config.getProxyPort()), new UsernamePasswordCredentials(config.getProxyUsername(), config.getProxyPassword())); } } return httpClient; }