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

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

Introduction

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

Prototype

public final HttpAsyncClientBuilder useSystemProperties() 

Source Link

Document

Use system properties when creating and configuring default implementations.

Usage

From source file:HCNIOEngine.java

private CloseableHttpAsyncClient createCloseableHttpAsyncClient() throws Exception {
    HttpAsyncClientBuilder builder = HttpAsyncClientBuilder.create();
    builder.useSystemProperties();
    builder.setSSLContext(SSLContext.getDefault());
    builder.setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE);
    builder.setMaxConnPerRoute(2);/*from w ww  . ja v  a  2  s.  c o  m*/
    builder.setMaxConnTotal(2);
    builder.setDefaultRequestConfig(RequestConfig.custom().setConnectionRequestTimeout(1000)
            .setConnectTimeout(2000).setSocketTimeout(2000).build());
    //        builder.setHttpProcessor()
    CloseableHttpAsyncClient hc = builder.build();
    hc.start();
    return hc;
}

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

/**
 * Set information about proxy.//from   w  w  w .j  a va  2 s .  c  o  m
 * @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

public void afterPropertiesSet() throws IOReactorException {
    HttpAsyncClientBuilder httpAsyncClientBuilder = HttpAsyncClients.custom();

    httpAsyncClientBuilder = httpAsyncClientBuilder.useSystemProperties();

    NHttpClientConnectionManager nHttpClientConnectionManager = getPoolingNHttpClientConnectionManager();

    httpAsyncClientBuilder.setConnectionManager(nHttpClientConnectionManager);

    httpAsyncClientBuilder.setDefaultCredentialsProvider(_getCredentialsProvider());

    setProxyHost(httpAsyncClientBuilder);

    try {//from w ww  . j av  a 2s.  co m
        _closeableHttpAsyncClient = httpAsyncClientBuilder.build();

        _closeableHttpAsyncClient.start();

        _idleConnectionMonitorThread = new IdleConnectionMonitorThread(nHttpClientConnectionManager);

        _idleConnectionMonitorThread.start();

        if (_logger.isDebugEnabled()) {
            StringBuilder sb = new StringBuilder();

            sb.append("Configured client for ");
            sb.append(_protocol);
            sb.append("://");
            sb.append(_hostName);
            sb.append(":");
            sb.append(_hostPort);

            _logger.debug(sb.toString());
        }
    } catch (Exception e) {
        _logger.error("Unable to configure client", e);
    }
}