Example usage for org.apache.http.impl.client HttpClients createDefault

List of usage examples for org.apache.http.impl.client HttpClients createDefault

Introduction

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

Prototype

public static CloseableHttpClient createDefault() 

Source Link

Document

Creates CloseableHttpClient instance with default configuration.

Usage

From source file:goofyhts.torrentkinesis.http.client.DefaultHttpClient.java

@Override
public void open() {
    client = HttpClients.createDefault();
    context = new HttpClientContext();
    CredentialsProvider credProv = new BasicCredentialsProvider();
    credProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
    context.setCredentialsProvider(credProv);
}

From source file:org.wuspba.ctams.ws.ITBandRegistrationController.java

@Test
public void testListAll() throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();

    URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build();

    LOG.info("Connecting to " + uri.toString());

    HttpGet httpGet = new HttpGet(uri);

    try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
        assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING);

        HttpEntity entity = response.getEntity();

        CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity);

        assertEquals(doc.getBandRegistrations().size(), 1);
        testEquality(doc.getBandRegistrations().get(0), TestFixture.INSTANCE.bandRegistration);

        EntityUtils.consume(entity);/*from   w w w.  j  av  a 2 s.c om*/
    }
}

From source file:org.wuspba.ctams.ws.ITSoloRegistrationController.java

@Test
public void testListAll() throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();

    URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build();

    LOG.info("Connecting to " + uri.toString());

    HttpGet httpGet = new HttpGet(uri);

    try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
        assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING);

        HttpEntity entity = response.getEntity();

        CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity);

        assertEquals(doc.getSoloRegistrations().size(), 1);
        testEquality(doc.getSoloRegistrations().get(0), TestFixture.INSTANCE.soloRegistration);

        EntityUtils.consume(entity);/*www  .j  ava  2 s  .c  o  m*/
    }
}

From source file:com.networknt.traceability.TraceabilityHandlerTest.java

@Test
public void testGetWithTid() throws Exception {
    String url = "http://localhost:8080/get";
    CloseableHttpClient client = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet(url);
    httpGet.setHeader(Constants.TRACEABILITY_ID, "12345");
    try {/*ww w .java2s .c o  m*/
        CloseableHttpResponse response = client.execute(httpGet);
        int statusCode = response.getStatusLine().getStatusCode();
        Assert.assertEquals(200, statusCode);
        if (statusCode == 200) {
            String s = IOUtils.toString(response.getEntity().getContent(), "utf8");
            Assert.assertNotNull(s);
            Assert.assertEquals("get", s);
            Header tid = response.getFirstHeader(Constants.TRACEABILITY_ID);
            Assert.assertEquals("12345", tid.getValue());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:retsys.client.http.HttpHelper.java

public HttpClient getHttpClient(CredentialsProvider credsProvider) {
    HttpClient client = null;/*  ww  w  . j  a  va2  s .  c o  m*/

    if (credsProvider == null) {
        client = HttpClients.createDefault();
    } else {
        client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
    }

    return client;
}

From source file:Vdisk.java

public JSONObject vdisk_get_operation(URI uri) throws IOException {
    CloseableHttpClient getClient = HttpClients.createDefault();
    if (access_token == null)
        this.get_access_token();
    HttpGet httpGet = new HttpGet(uri);
    JSONObject res = null;//  w w w.j  a v a  2  s .  co  m
    try (CloseableHttpResponse response = getClient.execute(httpGet)) {
        HttpEntity entity = response.getEntity();
        String info = EntityUtils.toString(entity);
        res = JSONObject.fromObject(info);
    } finally {
        getClient.close();
    }
    return res;
}

From source file:com.networknt.correlation.CorrelationHandlerTest.java

@Test
public void testWithCid() throws Exception {
    String url = "http://localhost:8080/with";
    CloseableHttpClient client = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet(url);
    httpGet.setHeader(Constants.CORRELATION_ID, "cid");
    try {//from  w w w. ja  v  a 2  s  .c  o  m
        CloseableHttpResponse response = client.execute(httpGet);
        int statusCode = response.getStatusLine().getStatusCode();
        Assert.assertEquals(200, statusCode);
        if (statusCode == 200) {
            String s = IOUtils.toString(response.getEntity().getContent(), "utf8");
            Assert.assertNotNull(s);
            Assert.assertEquals("cid", s);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.elasticsearch.bwcompat.StaticIndexBackwardCompatibilityTest.java

protected static HttpRequestBuilder httpClient() {
    NodeInfo info = nodeInfo(client());/*w w w  .  j a  v a2  s. com*/
    info.getHttp().address().boundAddress();
    TransportAddress publishAddress = info.getHttp().address().publishAddress();
    assertEquals(1, publishAddress.uniqueAddressTypeId());
    InetSocketAddress address = ((InetSocketTransportAddress) publishAddress).address();
    return new HttpRequestBuilder(HttpClients.createDefault()).host(address.getHostName())
            .port(address.getPort());
}

From source file:org.wuspba.ctams.ws.ITBandResultController.java

@Test
public void testListAll() throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();

    URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build();

    LOG.info("Connecting to " + uri.toString());

    HttpGet httpGet = new HttpGet(uri);

    try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
        assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING);

        HttpEntity entity = response.getEntity();

        CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity);

        assertEquals(doc.getBandContestResults().size(), 1);
        testEquality(doc.getBandContestResults().get(0), TestFixture.INSTANCE.bandResult);

        EntityUtils.consume(entity);//from   w w w .  j a va 2s.c o  m
    }
}