use of org.apache.http.impl.client.HttpClientBuilder in project YCSB by brianfrankcooper.
the class RestClient method setupClient.
private void setupClient() {
RequestConfig.Builder requestBuilder = RequestConfig.custom();
requestBuilder = requestBuilder.setConnectTimeout(conTimeout);
requestBuilder = requestBuilder.setConnectionRequestTimeout(readTimeout);
requestBuilder = requestBuilder.setSocketTimeout(readTimeout);
HttpClientBuilder clientBuilder = HttpClientBuilder.create().setDefaultRequestConfig(requestBuilder.build());
this.client = clientBuilder.setConnectionManagerShared(true).build();
}
use of org.apache.http.impl.client.HttpClientBuilder in project gocd by gocd.
the class GoAgentServerHttpClientBuilder method build.
public CloseableHttpClient build() throws Exception {
HttpClientBuilder builder = HttpClients.custom();
builder.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).build()).setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE);
HostnameVerifier hostnameVerifier = sslVerificationMode.verifier();
TrustStrategy trustStrategy = sslVerificationMode.trustStrategy();
KeyStore trustStore = agentTruststore();
SSLContextBuilder sslContextBuilder = SSLContextBuilder.create().useProtocol(systemEnvironment.get(SystemEnvironment.GO_SSL_TRANSPORT_PROTOCOL_TO_BE_USED_BY_AGENT));
if (trustStore != null || trustStrategy != null) {
sslContextBuilder.loadTrustMaterial(trustStore, trustStrategy);
}
sslContextBuilder.loadKeyMaterial(agentKeystore(), keystorePassword().toCharArray());
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContextBuilder.build(), hostnameVerifier);
builder.setSSLSocketFactory(sslConnectionSocketFactory);
return builder.build();
}
use of org.apache.http.impl.client.HttpClientBuilder in project gradle by gradle.
the class HttpClientHelper method getClient.
private synchronized CloseableHttpClient getClient() {
if (client == null) {
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setRedirectStrategy(new AlwaysRedirectRedirectStrategy());
new HttpClientConfigurer(settings).configure(builder);
this.client = builder.build();
}
return client;
}
use of org.apache.http.impl.client.HttpClientBuilder in project openhab1-addons by openhab.
the class Util method getConnection.
public static Sardine getConnection(CalDavConfig config) {
if (config.isDisableCertificateVerification()) {
if (config.getUrl().startsWith(HTTP_URL_PREFIX)) {
log.error("do not use '{}' if no ssl is used", CalDavLoaderImpl.PROP_DISABLE_CERTIFICATE_VERIFICATION);
}
log.trace("connecting to caldav '{}' with disabled certificate verification (url={}, username={}, password={})", config.getKey(), config.getUrl(), config.getUsername(), config.getPassword());
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setHostnameVerifier(new AllowAllHostnameVerifier());
try {
httpClientBuilder.setSslcontext(new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
}).build());
} catch (KeyManagementException e) {
log.error("error verifying certificate", e);
} catch (NoSuchAlgorithmException e) {
log.error("error verifying certificate", e);
} catch (KeyStoreException e) {
log.error("error verifying certificate", e);
}
if (StringUtils.isEmpty(config.getUsername()) && StringUtils.isEmpty(config.getPassword())) {
log.trace("connecting without credentials for '{}'", config.getKey());
return new SardineImpl(httpClientBuilder);
} else {
return new SardineImpl(httpClientBuilder, config.getUsername(), config.getPassword());
}
} else {
log.trace("connecting to caldav '{}' (url={}, username={}, password={})", config.getKey(), config.getUrl(), config.getUsername(), config.getPassword());
if (StringUtils.isEmpty(config.getUsername()) && StringUtils.isEmpty(config.getPassword())) {
log.trace("connecting without credentials for '{}'", config.getKey());
return new SardineImpl();
} else {
return new SardineImpl(config.getUsername(), config.getPassword());
}
}
}
use of org.apache.http.impl.client.HttpClientBuilder in project camel by apache.
the class HttpComponent method createHttpClientBuilder.
protected HttpClientBuilder createHttpClientBuilder(final String uri, final Map<String, Object> parameters, final Map<String, Object> httpClientOptions) throws Exception {
// http client can be configured from URI options
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
// allow the builder pattern
httpClientOptions.putAll(IntrospectionSupport.extractProperties(parameters, "httpClient."));
IntrospectionSupport.setProperties(clientBuilder, httpClientOptions);
// set the Request configure this way and allow the builder pattern
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
IntrospectionSupport.setProperties(requestConfigBuilder, httpClientOptions);
clientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
// validate that we could resolve all httpClient. parameters as this component is lenient
validateParameters(uri, httpClientOptions, null);
return clientBuilder;
}
Aggregations