use of org.apache.http.impl.client.SystemDefaultCredentialsProvider in project connect-sdk-java by Ingenico-ePayments.
the class DefaultConnection method createHttpClient.
private CloseableHttpClient createHttpClient(ProxyConfiguration proxyConfiguration) {
HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager);
HttpRoutePlanner routePlanner;
CredentialsProvider credentialsProvider;
if (proxyConfiguration != null) {
HttpHost proxy = new HttpHost(proxyConfiguration.getHost(), proxyConfiguration.getPort(), proxyConfiguration.getScheme());
routePlanner = new DefaultProxyRoutePlanner(proxy, DefaultSchemePortResolver.INSTANCE);
credentialsProvider = new BasicCredentialsProvider();
if (proxyConfiguration.getUsername() != null) {
AuthScope authscope = new AuthScope(proxyConfiguration.getHost(), proxyConfiguration.getPort());
final Credentials credentials = new UsernamePasswordCredentials(proxyConfiguration.getUsername(), proxyConfiguration.getPassword());
credentialsProvider.setCredentials(authscope, credentials);
// enable preemptive authentication
HttpRequestInterceptor proxyAuthenticationInterceptor = new HttpRequestInterceptor() {
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
Header header = request.getFirstHeader(AUTH.PROXY_AUTH_RESP);
if (header == null) {
header = new BasicScheme((Charset) null).authenticate(credentials, request, context);
if (!AUTH.PROXY_AUTH_RESP.equals(header.getName())) {
header = new BasicHeader(AUTH.PROXY_AUTH_RESP, header.getValue());
}
request.setHeader(header);
}
}
};
builder = builder.addInterceptorLast(proxyAuthenticationInterceptor);
}
} else {
// add support for system properties
routePlanner = new SystemDefaultRoutePlanner(DefaultSchemePortResolver.INSTANCE, ProxySelector.getDefault());
credentialsProvider = new SystemDefaultCredentialsProvider();
}
// add logging - last for requests, first for responses
LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
builder = builder.addInterceptorLast((HttpRequestInterceptor) loggingInterceptor);
builder = builder.addInterceptorFirst((HttpResponseInterceptor) loggingInterceptor);
return builder.setRoutePlanner(routePlanner).setDefaultCredentialsProvider(credentialsProvider).build();
}
use of org.apache.http.impl.client.SystemDefaultCredentialsProvider in project dropwizard by dropwizard.
the class JerseyClientBuilderTest method usesACustomCredentialsProvider.
@Test
void usesACustomCredentialsProvider() {
CredentialsProvider customCredentialsProvider = new SystemDefaultCredentialsProvider();
builder.using(customCredentialsProvider);
verify(apacheHttpClientBuilder).using(customCredentialsProvider);
}
use of org.apache.http.impl.client.SystemDefaultCredentialsProvider in project gradle by gradle.
the class HttpClientConfigurer method configure.
public void configure(HttpClientBuilder builder) {
SystemDefaultCredentialsProvider credentialsProvider = new SystemDefaultCredentialsProvider();
configureSslSocketConnectionFactory(builder, httpSettings.getSslContextFactory(), httpSettings.getHostnameVerifier());
configureAuthSchemeRegistry(builder);
configureCredentials(builder, credentialsProvider, httpSettings.getAuthenticationSettings());
configureProxy(builder, credentialsProvider, httpSettings);
configureUserAgent(builder);
configureCookieSpecRegistry(builder);
configureRequestConfig(builder);
configureSocketConfig(builder);
configureRedirectStrategy(builder);
builder.setDefaultCredentialsProvider(credentialsProvider);
builder.setMaxConnTotal(MAX_HTTP_CONNECTIONS);
builder.setMaxConnPerRoute(MAX_HTTP_CONNECTIONS);
builder.setConnectionTimeToLive(httpSettings.getTimeoutSettings().getIdleConnectionTimeoutMs(), TimeUnit.MILLISECONDS);
}
Aggregations