Example usage for org.apache.http.impl.client HttpClientBuilder setDefaultCredentialsProvider

List of usage examples for org.apache.http.impl.client HttpClientBuilder setDefaultCredentialsProvider

Introduction

In this page you can find the example usage for org.apache.http.impl.client HttpClientBuilder setDefaultCredentialsProvider.

Prototype

public final HttpClientBuilder setDefaultCredentialsProvider(final CredentialsProvider credentialsProvider) 

Source Link

Document

Assigns default CredentialsProvider instance which will be used for request execution if not explicitly set in the client execution context.

Usage

From source file:org.xwiki.extension.repository.http.internal.DefaultHttpClientFactory.java

@Override
public HttpClientBuilder createHttpClientBuilder(String user, String password) {
    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();

    // Pre-configure with everything configured at JVM level
    httpClientBuilder.useSystemProperties();

    // Setup user agent
    httpClientBuilder.setUserAgent(this.configuration.getUserAgent());

    // Setup authentication
    if (user != null) {
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();

        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
        httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
    }/*from ww w . j av a 2s. c  o  m*/

    return httpClientBuilder;
}