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

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

Introduction

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

Prototype

public CloseableHttpClient build() 

Source Link

Usage

From source file:ch.cyberduck.core.hubic.HubicSession.java

@Override
public Client connect(final HostKeyCallback key) throws BackgroundException {
    final HttpClientBuilder configuration = builder.build(this);
    configuration.addInterceptorLast(authorizationService);
    configuration.setServiceUnavailableRetryStrategy(retryHandler);
    return new Client(configuration.build());
}

From source file:de.micromata.genome.tpsb.httpClient.HttpClientTestBuilder.java

public HttpClientTestBuilder createHttpClient() {
    PoolingHttpClientConnectionManager conManager = new PoolingHttpClientConnectionManager();

    conManager.setMaxTotal(maxTotalConnection);
    conManager.setDefaultMaxPerRoute(maxPerHostConnection);

    final RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(connectionTimeout)
            .setSocketTimeout(readTimeout).build();
    final HttpClientBuilder httpClientBuilder = HttpClients.custom().setConnectionManager(conManager) //
            .setDefaultRequestConfig(requestConfig);

    httpClient = httpClientBuilder.build();

    return getBuilder();

}

From source file:com.jivesoftware.os.routing.bird.http.client.HttpClientFactoryProvider.java

public HttpClientFactory createHttpClientFactory(Collection<HttpClientConfiguration> configurations,
        boolean latentClient) {

    HttpClientConfig httpClientConfig = locateConfig(configurations, HttpClientConfig.class,
            HttpClientConfig.newBuilder().build());
    HttpClientSSLConfig sslConfig = locateConfig(configurations, HttpClientSSLConfig.class, null);

    String scheme;/*from w w w. ja va  2s  . com*/
    PoolingHttpClientConnectionManager poolingHttpClientConnectionManager;
    if (sslConfig != null && sslConfig.isUseSsl()) {
        LayeredConnectionSocketFactory sslSocketFactory;
        if (sslConfig.getCustomSSLSocketFactory() != null) {
            sslSocketFactory = sslConfig.getCustomSSLSocketFactory();
        } else {
            sslSocketFactory = SSLConnectionSocketFactory.getSocketFactory();
        }

        scheme = "https";
        poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager(
                RegistryBuilder.<ConnectionSocketFactory>create()
                        .register("http", PlainConnectionSocketFactory.getSocketFactory())
                        .register("https", sslSocketFactory).build());
    } else {
        scheme = "http";
        poolingHttpClientConnectionManager = new PoolingHttpClientConnectionManager();
    }

    if (httpClientConfig.getMaxConnections() > 0) {
        poolingHttpClientConnectionManager.setMaxTotal(httpClientConfig.getMaxConnections());
    } else {
        poolingHttpClientConnectionManager.setMaxTotal(Integer.MAX_VALUE);
    }

    if (httpClientConfig.getMaxConnectionsPerHost() > 0) {
        poolingHttpClientConnectionManager.setDefaultMaxPerRoute(httpClientConfig.getMaxConnectionsPerHost());
    } else {
        poolingHttpClientConnectionManager.setDefaultMaxPerRoute(Integer.MAX_VALUE);
    }

    poolingHttpClientConnectionManager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(
            httpClientConfig.getSocketTimeoutInMillis() > 0 ? httpClientConfig.getSocketTimeoutInMillis() : 0)
            .build());

    Closeable closeable;
    HttpClientConnectionManager clientConnectionManager;
    clientConnectionManager = poolingHttpClientConnectionManager;
    closeable = poolingHttpClientConnectionManager;

    return (OAuthSigner signer, String host, int port) -> {
        HttpClientBuilder httpClientBuilder = HttpClients.custom()
                .setConnectionManager(clientConnectionManager);

        CloseableHttpClient client = httpClientBuilder.build();
        HttpClient httpClient = new ApacheHttpClient441BackedHttpClient(scheme, host, port, signer, client,
                closeable, httpClientConfig.getCopyOfHeadersForEveryRequest());

        if (latentClient) {
            httpClient = new LatentHttpClient(httpClient);
        }
        return httpClient;
    };
}

From source file:HCEngine.java

private CloseableHttpClient createCloseableHttpClient() throws Exception {
    HttpClientBuilder builder = HttpClientBuilder.create();
    builder.useSystemProperties();/* w w  w . j  a v  a 2  s. c  o m*/
    builder.setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE);
    builder.setSSLContext(SSLContext.getDefault());
    CloseableHttpClient hc = builder.build();
    return hc;
}

From source file:org.meteogroup.jbrotli.httpclient.apache.HttpClientExample.java

public String downloadFileAsString(String url) throws IOException {
    BrotliLibraryLoader.loadBrotli();// ww  w.  ja va 2s .  c o m
    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    httpClientBuilder.addInterceptorFirst(httpRequestInterceptor);
    httpClientBuilder.addInterceptorFirst(httpResponseInterceptor);
    try (CloseableHttpClient httpClient = httpClientBuilder.build()) {
        String entity = downloadFileAsString(httpClient, url);
        if (entity != null)
            return entity;
    }
    return null;
}

From source file:com.cognifide.qa.bb.provider.http.HttpClientProvider.java

/**
 * Produces http client and configures it with provided credentials.
 *//*from  www.ja  v a  2s .  c  o m*/
@Override
public CloseableHttpClient get() {
    HttpClientBuilder builder = HttpClientBuilder.create();
    if (StringUtils.isNotBlank(login) && StringUtils.isNotBlank(password)) {
        builder.setDefaultCredentialsProvider(createCredentialsProvider(url, login, password));
    }
    return builder.build();
}

From source file:com.qdeve.oilprice.configuration.HttpConfiguration.java

private HttpClient httpclient() {
    HttpClientBuilder builder = HttpClientBuilder.create().useSystemProperties();
    if (appPropertries.getProxyHost() != null && appPropertries.getProxyPort() != null) {
        builder.setProxy(new HttpHost(appPropertries.getProxyHost(), appPropertries.getProxyPort()));
    }/*from w ww .  j  ava2s  . c  o m*/
    return builder.build();
}

From source file:synapticloop.getcookie.api.GetCookieApiClient.java

public GetCookieApiClient() {
    HttpClientBuilder httpBuilder = HttpClients.custom();
    httpBuilder.setUserAgent(Constants.USER_AGENT);
    this.httpclient = httpBuilder.build();
}

From source file:org.metaeffekt.dcc.shell.RemoteAgentTest.java

private HttpClient newHttpClient() throws GeneralSecurityException, IOException {
    final char[] password = "DYKK8T8m9nKqBRPZ".toCharArray();

    final KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(getClass().getResourceAsStream("/dcc-shell.keystore"), password);

    final KeyStore trustStore = KeyStore.getInstance("JKS");
    trustStore.load(getClass().getResourceAsStream("/dcc-shell.truststore"), password);

    final SSLContextBuilder sslContextBuilder = SSLContexts.custom();
    sslContextBuilder.loadKeyMaterial(keyStore, password);
    sslContextBuilder.loadTrustMaterial(trustStore);

    final HttpClientBuilder builder = HttpClientBuilder.create();
    builder.setSslcontext(sslContextBuilder.build());
    builder.setHostnameVerifier(new AllowAllHostnameVerifier());

    final HttpClient client = builder.build();
    return client;
}

From source file:org.scassandra.http.client.CurrentClient.java

private CurrentClient(String host, int port, int socketTimeout) {
    RequestConfig.Builder requestBuilder = RequestConfig.custom();
    requestBuilder = requestBuilder.setConnectTimeout(socketTimeout);
    requestBuilder = requestBuilder.setConnectionRequestTimeout(socketTimeout);
    requestBuilder = requestBuilder.setSocketTimeout(socketTimeout);
    HttpClientBuilder builder = HttpClientBuilder.create();
    builder.setDefaultRequestConfig(requestBuilder.build());
    httpClient = builder.build();
    this.currentUrl = "http://" + host + ":" + port + "/current";
    this.connectionsUrl = this.currentUrl + "/connections";
    this.listenerUrl = this.currentUrl + "/listener";
}