use of org.apache.http.impl.client.DefaultHttpRequestRetryHandler in project coprhd-controller by CoprHD.
the class BaseHttpClientFactory method createRawHTTPClient.
/**
* Create a HTTPClient using the factories configuration without Credentials
*
* @param useConnectionTimeout - allows override of the the default connectionTimeout
* @param useConnectionReadTimeout - allows override of the default connectionReadTimeout
* @throws AuthenticationException, GeneralSecurityException, RuntimeException
*/
protected AbstractHttpClient createRawHTTPClient(int useConnectionTimeout, int useConnectionReadTimeout) throws AuthenticationException, GeneralSecurityException, RuntimeException {
// select the appropriate connection manager and set options as appropriate
ClientConnectionManager cm = null;
if (threadSafeClients) {
ThreadSafeClientConnManager tscm = new ThreadSafeClientConnManager();
tscm.setMaxTotal(maxConnections);
tscm.setDefaultMaxPerRoute(maxConnectionsPerHost);
cm = tscm;
} else {
cm = new SingleClientConnManager();
}
// construct a client instance with the connection manager embedded
AbstractHttpClient httpClient = new DefaultHttpClient(cm);
if (relaxSSL) {
// !!!WARNING: This effectively turns off the authentication component of SSL, leaving only encryption
// can throw GeneralSecurityException
SSLHelper.configurePermissiveSSL(httpClient);
} else if (isSecureSSL()) {
SSLHelper.configureSSLWithTrustManger(httpClient, coordinator);
}
// see org.apache.http.client.params.AllClientPNames for a collected
// list of the available client parameters
HttpParams clientParams = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(clientParams, useConnectionTimeout);
HttpConnectionParams.setSoTimeout(clientParams, useConnectionReadTimeout);
// consider turning off the use of the Expect: 100-Continue response if
// your posts/puts tend to be relatively small
HttpProtocolParams.setUseExpectContinue(clientParams, false);
// TODO: reconsider this setting
// by default the client auto-retries on failures - turn that off so we can handle it manually
httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
return httpClient;
}
use of org.apache.http.impl.client.DefaultHttpRequestRetryHandler in project gateway-dubbox by zhuzhong.
the class OpenApiHttpClientServiceImpl method initHttpClient.
private void initHttpClient() {
// 注册访问协议相关的socket工厂
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE).register("https", SSLConnectionSocketFactory.getSystemSocketFactory()).build();
// httpclient 工厂
HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory = new ManagedHttpClientConnectionFactory(DefaultHttpRequestWriterFactory.INSTANCE, DefaultHttpResponseParserFactory.INSTANCE);
// dns解析器
DnsResolver dnsResolver = SystemDefaultDnsResolver.INSTANCE;
// 创建池化连接管理器
manager = new PoolingHttpClientConnectionManager(socketFactoryRegistry, connFactory, dnsResolver);
// 默认socket配置
SocketConfig defaultSocketConfig = SocketConfig.custom().setTcpNoDelay(true).build();
manager.setDefaultSocketConfig(defaultSocketConfig);
// 设置整个连接池的最大连接数
manager.setMaxTotal(this.maxTotal);
// 每个路由最大连接数
manager.setDefaultMaxPerRoute(this.defaultMaxPerRoute);
manager.setValidateAfterInactivity(this.validateAfterInactivity);
RequestConfig defaultRequestConfig = RequestConfig.custom().setConnectTimeout(this.connectionTimeout).setSocketTimeout(this.socketTimeout).setConnectionRequestTimeout(this.connectionRequestTimeout).build();
httpClient = HttpClients.custom().setConnectionManager(manager).setConnectionManagerShared(false).evictIdleConnections(60, TimeUnit.SECONDS).evictExpiredConnections().setConnectionTimeToLive(60, TimeUnit.SECONDS).setDefaultRequestConfig(defaultRequestConfig).setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE).setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE).setRetryHandler(new DefaultHttpRequestRetryHandler(0, false)).build();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
httpClient.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
use of org.apache.http.impl.client.DefaultHttpRequestRetryHandler in project dropwizard by dropwizard.
the class JerseyClientBuilderTest method usesACustomHttpRequestRetryHandler.
@Test
void usesACustomHttpRequestRetryHandler() {
final DefaultHttpRequestRetryHandler customRetryHandler = new DefaultHttpRequestRetryHandler(2, true);
builder.using(customRetryHandler);
verify(apacheHttpClientBuilder).using(customRetryHandler);
}
use of org.apache.http.impl.client.DefaultHttpRequestRetryHandler in project beam by apache.
the class HttpHealthcareApiClient method initClient.
private void initClient() throws IOException {
credentials = GoogleCredentials.getApplicationDefault();
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
HttpRequestInitializer requestInitializer = new AuthenticatedRetryInitializer(credentials.createScoped(CloudHealthcareScopes.CLOUD_PLATFORM, StorageScopes.CLOUD_PLATFORM_READ_ONLY));
client = new CloudHealthcare.Builder(new NetHttpTransport(), new JacksonFactory(), requestInitializer).setApplicationName("apache-beam-hl7v2-io").build();
httpClient = HttpClients.custom().setRetryHandler(new DefaultHttpRequestRetryHandler(10, false)).build();
}
use of org.apache.http.impl.client.DefaultHttpRequestRetryHandler in project voldemort by voldemort.
the class HttpClientBench method createClient.
private static HttpClient createClient() {
ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(), DEFAULT_CONNECTION_MANAGER_TIMEOUT, TimeUnit.MILLISECONDS);
DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
HttpParams clientParams = httpClient.getParams();
HttpConnectionParams.setSocketBufferSize(clientParams, 60000);
HttpConnectionParams.setTcpNoDelay(clientParams, false);
HttpProtocolParams.setUserAgent(clientParams, VOLDEMORT_USER_AGENT);
HttpProtocolParams.setVersion(clientParams, HttpVersion.HTTP_1_1);
// HostConfiguration hostConfig = new HostConfiguration();
// hostConfig.setHost("localhost");
HttpConnectionParams.setConnectionTimeout(clientParams, DEFAULT_CONNECTION_MANAGER_TIMEOUT);
HttpConnectionParams.setSoTimeout(clientParams, 500);
httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);
connectionManager.setMaxTotal(DEFAULT_MAX_CONNECTIONS);
connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_HOST_CONNECTIONS);
HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);
return httpClient;
}
Aggregations