use of org.apache.http.client.config.RequestConfig.Builder in project cloudbreak by hortonworks.
the class ConsulUtils method createHttpClient.
private static HttpClient createHttpClient(String clientCert, String clientKey, String serverCert) throws Exception {
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(KeyStoreUtil.createTrustStore(serverCert), null).loadKeyMaterial(KeyStoreUtil.createKeyStore(clientCert, clientKey), "consul".toCharArray()).build();
try (PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(setupSchemeRegistry(sslContext))) {
connectionManager.setMaxTotal(MAX_CONNECTION);
connectionManager.setDefaultMaxPerRoute(MAX_ROUTE);
Builder requestBuilder = RequestConfig.custom().setConnectTimeout(DEFAULT_TIMEOUT_MS).setConnectionRequestTimeout(DEFAULT_TIMEOUT_MS).setSocketTimeout(DEFAULT_TIMEOUT_MS);
return HttpClientBuilder.create().setConnectionManager(connectionManager).setDefaultRequestConfig(requestBuilder.build()).build();
}
}
use of org.apache.http.client.config.RequestConfig.Builder in project webtools.sourceediting by eclipse.
the class HttpClientProvider method download.
private static File download(File file, URL url) {
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = null;
OutputStream out = null;
file.getParentFile().mkdirs();
try {
HttpHost target = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
Builder builder = RequestConfig.custom();
HttpHost proxy = getProxy(target);
if (proxy != null) {
builder = builder.setProxy(proxy);
}
RequestConfig config = builder.build();
HttpGet request = new HttpGet(url.toURI());
request.setConfig(config);
response = httpclient.execute(target, request);
InputStream in = response.getEntity().getContent();
out = new BufferedOutputStream(new FileOutputStream(file));
copy(in, out);
return file;
} catch (Exception e) {
logWarning(e);
;
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
if (response != null) {
try {
response.close();
} catch (IOException e) {
}
}
try {
httpclient.close();
} catch (IOException e) {
}
}
return null;
}
use of org.apache.http.client.config.RequestConfig.Builder in project spring-security-oauth by spring-projects.
the class ServerRunning method createRestTemplate.
public RestOperations createRestTemplate() {
RestTemplate client = new RestTemplate();
client.setRequestFactory(new HttpComponentsClientHttpRequestFactory() {
@Override
protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
HttpClientContext context = HttpClientContext.create();
Builder builder = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).setAuthenticationEnabled(false).setRedirectsEnabled(false);
context.setRequestConfig(builder.build());
return context;
}
});
client.setErrorHandler(new DefaultResponseErrorHandler() {
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return false;
}
});
return client;
}
use of org.apache.http.client.config.RequestConfig.Builder in project lucene-solr by apache.
the class HttpClientUtil method setupBuilder.
private static HttpClientBuilder setupBuilder(HttpClientBuilder builder, SolrParams config) {
Builder requestConfigBuilder = RequestConfig.custom().setRedirectsEnabled(config.getBool(HttpClientUtil.PROP_FOLLOW_REDIRECTS, false)).setDecompressionEnabled(false).setConnectTimeout(config.getInt(HttpClientUtil.PROP_CONNECTION_TIMEOUT, DEFAULT_CONNECT_TIMEOUT)).setSocketTimeout(config.getInt(HttpClientUtil.PROP_SO_TIMEOUT, DEFAULT_SO_TIMEOUT));
String cpolicy = cookiePolicy;
if (cpolicy != null) {
requestConfigBuilder.setCookieSpec(cpolicy);
}
RequestConfig requestConfig = requestConfigBuilder.build();
HttpClientBuilder retBuilder = builder.setDefaultRequestConfig(requestConfig);
if (config.getBool(HttpClientUtil.PROP_USE_RETRY, true)) {
retBuilder = retBuilder.setRetryHandler(new SolrHttpRequestRetryHandler(3));
} else {
retBuilder = retBuilder.setRetryHandler(NO_RETRY);
}
final String basicAuthUser = config.get(HttpClientUtil.PROP_BASIC_AUTH_USER);
final String basicAuthPass = config.get(HttpClientUtil.PROP_BASIC_AUTH_PASS);
if (basicAuthUser != null && basicAuthPass != null) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(basicAuthUser, basicAuthPass));
retBuilder.setDefaultCredentialsProvider(credsProvider);
}
if (config.getBool(HttpClientUtil.PROP_ALLOW_COMPRESSION, false)) {
retBuilder.addInterceptorFirst(new UseCompressionRequestInterceptor());
retBuilder.addInterceptorFirst(new UseCompressionResponseInterceptor());
} else {
retBuilder.disableContentCompression();
}
return retBuilder;
}
use of org.apache.http.client.config.RequestConfig.Builder in project lucene-solr by apache.
the class HttpClientUtil method createDefaultRequestConfigBuilder.
public static Builder createDefaultRequestConfigBuilder() {
String cpolicy = cookiePolicy;
Builder builder = RequestConfig.custom();
builder.setSocketTimeout(DEFAULT_SO_TIMEOUT).setConnectTimeout(DEFAULT_CONNECT_TIMEOUT).setRedirectsEnabled(false).setDecompressionEnabled(// we do our own compression / decompression
false);
if (cpolicy != null) {
builder.setCookieSpec(cpolicy);
}
return builder;
}
Aggregations