Example usage for org.apache.http.impl.nio.client HttpAsyncClientBuilder setProxyAuthenticationStrategy

List of usage examples for org.apache.http.impl.nio.client HttpAsyncClientBuilder setProxyAuthenticationStrategy

Introduction

In this page you can find the example usage for org.apache.http.impl.nio.client HttpAsyncClientBuilder setProxyAuthenticationStrategy.

Prototype

public final HttpAsyncClientBuilder setProxyAuthenticationStrategy(
        final AuthenticationStrategy proxyAuthStrategy) 

Source Link

Document

Assigns AuthenticationStrategy instance for target host authentication.

Usage

From source file:io.wcm.caravan.commons.httpasyncclient.impl.HttpAsyncClientItem.java

private static CloseableHttpAsyncClient buildHttpAsyncClient(HttpClientConfig config,
        PoolingNHttpClientConnectionManager connectionManager, CredentialsProvider credentialsProvider) {

    // prepare HTTPClient builder
    HttpAsyncClientBuilder httpClientAsyncBuilder = HttpAsyncClientBuilder.create()
            .setConnectionManager(connectionManager);

    // timeout settings
    httpClientAsyncBuilder.setDefaultRequestConfig(RequestConfig.custom()
            .setConnectTimeout(config.getConnectTimeout()).setSocketTimeout(config.getSocketTimeout()).build());

    httpClientAsyncBuilder.setDefaultCredentialsProvider(credentialsProvider);

    // optional proxy support
    if (StringUtils.isNotEmpty(config.getProxyHost())) {
        httpClientAsyncBuilder.setProxy(new HttpHost(config.getProxyHost(), config.getProxyPort()));

        // optional proxy authentication
        if (StringUtils.isNotEmpty(config.getProxyUser())) {
            httpClientAsyncBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
        }//ww w .  j  a va2  s. c  o  m
    }

    return httpClientAsyncBuilder.build();
}

From source file:io.getlime.push.service.fcm.FcmClient.java

/**
 * Set information about proxy.//  w w  w  .  jav  a2  s  . com
 * @param host Proxy host URL.
 * @param port Proxy port.
 * @param username Proxy username, use 'null' for proxy without authentication.
 * @param password Proxy user password, ignored in case username is 'null'
 */
public void setProxy(String host, int port, String username, String password) {

    HttpAsyncClientBuilder clientBuilder = HttpAsyncClientBuilder.create();
    clientBuilder.useSystemProperties();
    clientBuilder.setProxy(new HttpHost(host, port));

    if (username != null) {
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        UsernamePasswordCredentials user = new UsernamePasswordCredentials(username, password);
        credsProvider.setCredentials(new AuthScope(host, port), user);
        clientBuilder.setDefaultCredentialsProvider(credsProvider);
        clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
    }

    CloseableHttpAsyncClient client = clientBuilder.build();

    HttpComponentsAsyncClientHttpRequestFactory factory = new HttpComponentsAsyncClientHttpRequestFactory();
    factory.setAsyncClient(client);

    restTemplate.setAsyncRequestFactory(factory);
}

From source file:com.liferay.petra.json.web.service.client.BaseJSONWebServiceClientImpl.java

protected void setProxyHost(HttpAsyncClientBuilder httpClientBuilder) {
    if ((_proxyHostName == null) || _proxyHostName.equals("")) {
        return;/*from  w  w  w  .  j  a  va 2  s .  co m*/
    }

    httpClientBuilder.setProxy(new HttpHost(_proxyHostName, _proxyHostPort));
    httpClientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
}