org.apache.http.impl.client.SystemDefaultCredentialsProvider Java Examples

The following examples show how to use org.apache.http.impl.client.SystemDefaultCredentialsProvider. 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: HttpClientSupport.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
public static HttpClientBuilder builder(
		HttpEnvironmentRepositoryProperties environmentProperties)
		throws GeneralSecurityException {
	SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
	HttpClientBuilder httpClientBuilder = HttpClients.custom();

	if (environmentProperties.isSkipSslValidation()) {
		sslContextBuilder.loadTrustMaterial(null, (certificate, authType) -> true);
		httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier());
	}

	if (!CollectionUtils.isEmpty(environmentProperties.getProxy())) {
		ProxyHostProperties httpsProxy = environmentProperties.getProxy()
				.get(ProxyHostProperties.ProxyForScheme.HTTPS);
		ProxyHostProperties httpProxy = environmentProperties.getProxy()
				.get(ProxyHostProperties.ProxyForScheme.HTTP);

		httpClientBuilder
				.setRoutePlanner(new SchemeBasedRoutePlanner(httpsProxy, httpProxy));
		httpClientBuilder.setDefaultCredentialsProvider(
				new ProxyHostCredentialsProvider(httpProxy, httpsProxy));
	}
	else {
		httpClientBuilder.setRoutePlanner(
				new SystemDefaultRoutePlanner(ProxySelector.getDefault()));
		httpClientBuilder.setDefaultCredentialsProvider(
				new SystemDefaultCredentialsProvider());
	}

	int timeout = environmentProperties.getTimeout() * 1000;
	return httpClientBuilder.setSSLContext(sslContextBuilder.build())
			.setDefaultRequestConfig(RequestConfig.custom().setSocketTimeout(timeout)
					.setConnectTimeout(timeout).build());
}
 
Example #2
Source File: HttpClientFactory.java    From hsac-fitnesse-fixtures with Apache License 2.0 4 votes vote down vote up
protected SystemDefaultCredentialsProvider createCredentialsProvider() {
    return new SystemDefaultCredentialsProvider();
}