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:org.hupo.psi.mi.psicquic.ws.SolrBasedPsicquicRestService.java

protected HttpClient createHttpClient() {
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(SolrBasedPsicquicService.maxTotalConnections);
    cm.setDefaultMaxPerRoute(SolrBasedPsicquicService.defaultMaxConnectionsPerHost);

    RequestConfig.Builder requestBuilder = RequestConfig.custom();
    requestBuilder = requestBuilder.setConnectTimeout(SolrBasedPsicquicService.connectionTimeOut);
    requestBuilder = requestBuilder.setSocketTimeout(SolrBasedPsicquicService.soTimeOut);

    HttpClientBuilder builder = HttpClientBuilder.create();
    builder.setDefaultRequestConfig(requestBuilder.build());
    builder.setConnectionManager(cm);//www  . j  a va2 s.  c  o  m

    return builder.build();
}

From source file:net.officefloor.plugin.web.http.template.secure.SecureHttpTemplateTest.java

@Override
protected void setUp() throws Exception {
    // Configure the client (to not redirect)
    HttpClientBuilder builder = HttpClientBuilder.create();
    HttpTestUtil.configureHttps(builder);
    HttpTestUtil.configureNoRedirects(builder);
    this.client = builder.build();
}

From source file:cloudfoundry.norouter.f5.client.HttpClientIControlClient.java

private HttpClientIControlClient(HttpHost host, Builder builder) {
    super(URI.create(host.toURI()));
    this.host = host;

    final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
            Objects.requireNonNull(builder.user, "user is a required argument"),
            Objects.requireNonNull(builder.password, "password is a required argument"));
    credentialsProvider.setCredentials(new AuthScope(host.getHostName(), host.getPort()), credentials);

    final HttpClientBuilder httpClientBuilder = HttpClients.custom().setUserAgent("curl/7.37.1")
            .disableCookieManagement().setDefaultCredentialsProvider(credentialsProvider);
    if (builder.skipVerifyTls) {
        httpClientBuilder.setSSLSocketFactory(NaiveTrustManager.getSocketFactory());
    }/*from  w w w  .  j  ava 2 s . c  om*/
    httpClient = httpClientBuilder.build();
}

From source file:com.offbytwo.jenkins.client.JenkinsHttpClient.java

/**
 * Create an unauthenticated Jenkins HTTP client
 *
 * @param uri/*from   www . ja v a  2 s  . c o m*/
 *            Location of the jenkins server (ex. http://localhost:8080)
 * @param builder
 *            Configured HttpClientBuilder to be used
 */
public JenkinsHttpClient(URI uri, HttpClientBuilder builder) {
    this(uri, builder.build());
}

From source file:sep.gaia.resources.poi.POILoaderWorker.java

/**
 * Performs the partial query and stores the result in <code>result</code>.
 * A XML-document is generated from the key-value-pairs in the sub-query for
 * both nodes and ways and the specific bounding-box. This document is sent to 
 * the Overpass-API via HTTP-POST and the resulting XML-document is sent back.
 * If no error is reported, the result is a XML-document listing all nodes and
 * ways suitable for the request. POIs are generated from the nodes and by
 * picking a node from the ways returned.
 * After the result is stored this thread terminates.
 * <br><br>//from w ww.j a  va2 s . c om
 * For information about the Overpass-API in general confer 
 * <a href="http://wiki.openstreetmap.org/wiki/Overpass_API">this document</a> and 
 * for information about the language to be used read
 * <a href="http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide">this guide</a>.
 */
@Override
public void run() {

    POIQuery query = getSubQuery();
    if (query != null) {

        // Check the cache if there is data already present:
        if (cache != null) {
            Collection<PointOfInterest> pois = cache.get(query);

            // If there was something found, set it as the workers result and quit:
            if (pois != null) {
                setResults(pois);
                return;
            }
        }

        try {
            HttpClientBuilder clientBuilder = HttpClientBuilder.create();
            HttpClient httpclient = clientBuilder.build();
            HttpPost httppost = new HttpPost(INTERPRETER_URI);

            // Add the API-request as POST-data:
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
            String xmlQuery = generateQueryXML(query);
            nameValuePairs.add(new BasicNameValuePair("data", xmlQuery));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Do the request:
            HttpResponse response = httpclient.execute(httppost);

            // Prepare XML:
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document responseDoc = dBuilder.parse(response.getEntity().getContent());

            // Parse the response:
            Collection<PointOfInterest> pois = parseResponse(responseDoc);

            // Set the name of the POIs category:
            for (PointOfInterest poi : pois) {
                poi.setCategory(query.getCategoryName());
            }

            // If a cache exists, add the loaded resources to it:
            if (cache != null) {
                cache.addResources(query, pois);
            }

            // Set the read POIs as the workers result:
            setResults(pois);

        } catch (IOException e) {
            Logger.getInstance().warning("Overpass-Query failed.");
        } catch (ParserConfigurationException e) {
            Logger.getInstance().warning("Configuring XML-parser failed! " + e.getMessage());
        } catch (IllegalStateException | SAXException e) {
            Logger.getInstance().warning("Error parsing XML! " + e.getMessage());
        }

    }
}

From source file:com.hp.autonomy.frontend.find.hod.beanconfiguration.HodConfiguration.java

@Bean
public HttpClient httpClient() {
    final HttpClientBuilder builder = HttpClientBuilder.create();

    final String proxyHost = environment.getProperty("find.https.proxyHost");

    if (proxyHost != null) {
        final Integer proxyPort = Integer.valueOf(environment.getProperty("find.https.proxyPort", "8080"));
        builder.setProxy(new HttpHost(proxyHost, proxyPort));
    }//from www . j  ava 2  s  .c  o m

    builder.disableCookieManagement();

    return builder.build();
}

From source file:org.wildfly.swarm.jaxrs.SimpleHttp.java

protected Response getUrlContents(String theUrl, boolean useAuth, boolean followRedirects) {

    StringBuilder content = new StringBuilder();
    int code;/*from   ww w  .  ja va 2s  . c om*/

    try {

        CredentialsProvider provider = new BasicCredentialsProvider();

        HttpClientBuilder builder = HttpClientBuilder.create();
        if (!followRedirects) {
            builder.disableRedirectHandling();
        }
        if (useAuth) {
            UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("admin", "password");
            provider.setCredentials(AuthScope.ANY, credentials);
            builder.setDefaultCredentialsProvider(provider);
        }
        HttpClient client = builder.build();

        HttpResponse response = client.execute(new HttpGet(theUrl));
        code = response.getStatusLine().getStatusCode();

        if (null == response.getEntity()) {
            throw new RuntimeException("No response content present");
        }

        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent()));

        String line;

        while ((line = bufferedReader.readLine()) != null) {
            content.append(line + "\n");
        }
        bufferedReader.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    return new Response(code, content.toString());
}