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:application.Crawler.java

/**
 *
 * call webpages from url link for each product
 * @return @throws IOException/*from  w  ww.ja  v a  2  s. c  om*/
 */
private String crawlDescriptionPage() throws IOException {

    String htmlRes = null;

    if (this.link != null) {

        HttpGet getRequest = new HttpGet(link);
        HttpClientBuilder create = HttpClientBuilder.create();
        CloseableHttpClient build = create.build();
        CloseableHttpResponse response = build.execute(getRequest);
        InputStream content = response.getEntity().getContent();
        htmlRes = IOUtils.toString(content);
        // render the file siez in kB
        size = (long) htmlRes.length() / 1014;

    }

    return htmlRes;
}

From source file:application.Crawler.java

/**
 * call was from url // ww w .  j a  va  2s  .  com
 * @return json String
 * @throws CrawlerException 
 */
private String callWs() throws CrawlerException {

    String jsonResult = null;

    try {

        HttpGet getRequest = new HttpGet(URL);
        getRequest.addHeader("accept", "application/json");
        HttpClientBuilder create = HttpClientBuilder.create();
        CloseableHttpClient build = create.build();
        CloseableHttpResponse response = build.execute(getRequest);
        InputStream content = response.getEntity().getContent();
        jsonResult = IOUtils.toString(content);

    } catch (IOException ex) {
        LOG.error(ex.getMessage());
        throw new CrawlerException("no answer from server");

    }
    return jsonResult;
}

From source file:com.yahoo.sql4d.sql4ddriver.DruidNodeAccessor.java

public CloseableHttpClient getClient() {
    HttpClientBuilder builder = HttpClients.custom().setConnectionManager(pool);
    return (customRouterPlanner != null) ? builder.setRoutePlanner(customRouterPlanner).build()
            : builder.build();
}

From source file:org.ambraproject.wombat.service.remote.AbstractRemoteService.java

private CloseableHttpClient createClient() {
    HttpClientBuilder clientBuilder = HttpClientBuilder.create();
    if (connectionManager.isPresent()) {
        clientBuilder = clientBuilder.setConnectionManager(connectionManager.get());
    }// ww w  . ja v a2s. c  o m
    return clientBuilder.build();
}

From source file:org.commonjava.indy.httprox.AbstractHttproxFunctionalTest.java

protected CloseableHttpClient proxiedHttp(final String user, final String pass, SSLSocketFactory socketFactory)
        throws Exception {
    CredentialsProvider creds = null;//from  w ww . java 2s.com

    if (user != null) {
        creds = new BasicCredentialsProvider();
        creds.setCredentials(new AuthScope(HOST, proxyPort), new UsernamePasswordCredentials(user, pass));
    }

    HttpHost proxy = new HttpHost(HOST, proxyPort);

    final HttpRoutePlanner planner = new DefaultProxyRoutePlanner(proxy);
    HttpClientBuilder builder = HttpClients.custom().setRoutePlanner(planner)
            .setDefaultCredentialsProvider(creds).setProxy(proxy).setSSLSocketFactory(socketFactory);

    return builder.build();
}

From source file:co.tuzza.clicksend4j.http.HttpClientUtils.java

public HttpClient getHttpClient() {

    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    httpClientBuilder.setUserAgent("ClickSend4J 0.0.1");
    httpClientBuilder.setConnectionManager(clientConnectionManager);
    httpClientBuilder.setDefaultRequestConfig(buildRequestConfig());

    return httpClientBuilder.build();

}

From source file:com.graphaware.test.util.TestHttpClient.java

/**
 * Create a client from the provided builder.
 *
 * @param builder builder./*from   ww  w .  j  av  a2 s.com*/
 */
public TestHttpClient(HttpClientBuilder builder) {
    this.client = builder.build();
}

From source file:com.liferay.sync.engine.BaseTestCase.java

protected void mockHttpClientBuilder(String fileName) throws Exception {
    PowerMockito.mockStatic(HttpClientBuilder.class);

    HttpClientBuilder httpClientbuilder = Mockito.mock(HttpClientBuilder.class);

    CloseableHttpClient closeableHttpClient = mockCloseableHttpClient(fileName);

    Mockito.when(httpClientbuilder.build()).thenReturn(closeableHttpClient);

    Mockito.when(HttpClientBuilder.create()).thenReturn(httpClientbuilder);
}

From source file:ch.cyberduck.core.b2.B2Session.java

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