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

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

Introduction

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

Prototype

public static HttpClientBuilder create() 

Source Link

Usage

From source file:de.geeksfactory.opacclient.networking.HTTPClient.java

public static HttpClient getNewHttpClient(boolean customssl, boolean disguise_app) {
    HttpClientBuilder builder = HttpClientBuilder.create();
    builder.setRedirectStrategy(new CustomRedirectStrategy());
    if (disguise_app) {
        builder.setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, "
                + "like Gecko) Chrome/43.0.2357.130 Safari/537.36\t");
    } else {//from  www  . j  a  v  a2s  . c o  m
        builder.setUserAgent("OpacApp/" + OpacClient.versionName);
    }
    if (customssl) {
        try {
            if (trustStore == null) {
                trustStore = KeyStore.getInstance("BKS");
                final InputStream in = OpacClient.context.getResources().openRawResource(R.raw.ssl_trust_store);
                try {
                    trustStore.load(in, "ro5eivoijeeGohsh0daequoo5Zeepaen".toCharArray());
                } finally {
                    in.close();
                }
            }

            ConnectionSocketFactory sf = AdditionalKeyStoresSSLSocketFactory.create(trustStore);

            Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                    .register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sf)
                    .build();

            HttpClientConnectionManager ccm = new PoolingHttpClientConnectionManager(registry);
            builder.setConnectionManager(ccm);

            return builder.build();
        } catch (Exception e) {
            e.printStackTrace();
            return builder.build();
        }
    } else {
        return builder.build();
    }
}

From source file:pl.raszkowski.sporttrackersconnector.garminconnect.GarminConnectConnector.java

public GarminConnectConnector() {
    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    httpClient = httpClientBuilder.disableRedirectHandling().build();

    authorizer = new Authorizer(httpClient);
}

From source file:org.nuxeo.docusign.core.test.TestDocuSignCallback.java

@Test
public void testReceiveCallback() throws IOException {
    String url = "http://localhost:18090/docusign";
    HttpClient client = HttpClientBuilder.create().build();
    HttpPost post = new HttpPost(url);
    post.setEntity(new InputStreamEntity(getClass().getResourceAsStream("/files/callback.xml")));
    HttpResponse response = client.execute(post);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
}

From source file:com.zextras.zimbradrive.statustest.ConnectionTestUtils.java

public String assertHttpGetRequestResponse(URL url) throws URISyntaxException, IOException {
    HttpGet httpGet = new HttpGet(url.toURI());

    HttpClient client = HttpClientBuilder.create().build();
    HttpResponse httpResponse;/*from   w  w w  .ja  v  a2 s .co m*/
    httpResponse = client.execute(httpGet);

    BasicResponseHandler basicResponseHandler = new BasicResponseHandler();
    return basicResponseHandler.handleResponse(httpResponse);
}

From source file:com.magnet.plugin.api.requests.abs.BaseRequest.java

@Override
public void doWork() {
    try {/* w w w .  j a  v a 2 s. c o m*/
        HttpClient httpClient = HttpClientBuilder.create().build();
        HttpRequestBase request = getRequest(requestModel);

        List<RequestHeaderModel> requestModelHeaders = requestModel.getHeaders();

        for (RequestHeaderModel header : requestModelHeaders) {
            request.setHeader(header.getName(), header.getValue());
        }

        // If not specified as a header argument, Content-Type is inferred from the request body
        // Add the header here so the request is successful.
        if (request.getHeaders(ContentTypeHelper.CONTENT_TYPE_HEADER) == null
                || request.getHeaders(ContentTypeHelper.CONTENT_TYPE_HEADER).length == 0) {
            RestContentType type = ExampleParser.guessContentType(requestModel.getRequest());
            if (null != type) {
                request.setHeader(ContentTypeHelper.CONTENT_TYPE_HEADER, type.getName());
            }
        }
        // check if content-type is parameterized
        HttpResponse httpResponse = httpClient.execute(request);
        ApiMethodModel methodModel = new ApiMethodModel();
        methodModel.setRequestHeaders(request.getAllHeaders());
        methodModel.setHttpResponse(httpResponse);
        methodModel.setRequestModel(requestModel);
        onSuccess(methodModel);
    } catch (Exception e) {
        e.printStackTrace();
        Logger.info(getClass(), e.toString());
        onError(e);
    }

}

From source file:com.vaushell.superpipes.tools.HTTPhelper.java

/**
 * Create a standard builder, firefox agent and ssl easy support.
 *
 * @return the builder.// w  w w .  jav a2  s  .c om
 */
public static HttpClientBuilder createBuilder() {
    try {
        return HttpClientBuilder.create().setDefaultCookieStore(new BasicCookieStore())
                .setUserAgent("Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20100101 Firefox/15.0.1")
                .setSSLSocketFactory(new SSLConnectionSocketFactory(new SSLContextBuilder()
                        .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build()));
    } catch (final KeyManagementException | KeyStoreException | NoSuchAlgorithmException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.ado.biblio.desktop.BulkBookLoad.java

private static void send(String isbnUrl) throws IOException {
    final String isbn = isbnUrl.split("/")[5];
    HttpClient client = HttpClientBuilder.create().build();
    String url = String.format("%s/books/%s?format=%s&code=%s", "http://localhost:8086",
            "fd9728f8-e611-4e40-8c3d-6b959d265d62", "EAN_13", isbn);

    HttpPost httpPost = new HttpPost(url);
    client.execute(httpPost);//from w ww .  java2 s .  c o m
}

From source file:org.stilavia.service.zalando.RequestContext.java

public RequestContext(String host, ZalandoApi.Domain domain, String clientId) {
    this.host = host;
    this.domain = domain;
    this.clientId = clientId;
    this.httpClient = HttpClientBuilder.create().build();
    this.requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    restTemplate = new RestTemplate(requestFactory);
    restTemplate.setMessageConverters(Arrays
            .<HttpMessageConverter<?>>asList(new MappingJackson2HttpMessageConverter(new ObjectMapper())));

}