Example usage for org.apache.http.client.methods CloseableHttpResponse getEntity

List of usage examples for org.apache.http.client.methods CloseableHttpResponse getEntity

Introduction

In this page you can find the example usage for org.apache.http.client.methods CloseableHttpResponse getEntity.

Prototype

HttpEntity getEntity();

Source Link

Usage

From source file:RGSOplataRu.OplataConnection.java

public Clob POST_RequestDBClob(String p_uri, Object... p_objects) throws IOException, SQLException {
    Clob result = null;/* w w  w. j ava 2  s.c  o  m*/
    HttpPost request = new HttpPost(p_uri);
    request = getRequestConfigurator().Configurate(request);

    if (p_objects.length > 0) {

        HttpEntity reqEntity = EntityBuilder.create().setText((String) p_objects[0])
                //.setContentType(ContentType.create("text/plain", Charset.forName("utf-8")))
                .build();

        request.setEntity(reqEntity);
        //            System.out.println("target: "+target);
        //            System.out.println("httpClient: "+httpClient);
        //            System.out.println("request: "+request);
        CloseableHttpResponse responce = httpClient.execute(target, request);
        result = Stream2Clob(responce.getEntity().getContent());
    }

    return result;
}

From source file:org.commonjava.aprox.folo.ftest.urls.StoreOneAndSourceStoreUrlInHtmlListingTest.java

@Test
public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception {
    final byte[] data = "this is a test".getBytes();
    final ByteArrayInputStream stream = new ByteArrayInputStream(data);
    final String root = "/path/to/";
    final String path = root + "foo.txt";
    final String track = "track";

    content.store(track, hosted, STORE, path, stream);

    final AproxClientHttp http = getHttp();

    final HttpGet request = http.newRawGet(content.contentUrl(track, hosted, STORE, root));

    request.addHeader("Accept", "text/html");

    final CloseableHttpClient hc = http.newClient();
    final CloseableHttpResponse response = hc.execute(request);

    final InputStream listing = response.getEntity().getContent();
    final String html = IOUtils.toString(listing);

    // TODO: Charset!!
    final Document doc = Jsoup.parse(html);
    for (final Element item : doc.select("a.source-link")) {
        final String fname = item.text();
        System.out.printf("Listing contains: '%s'\n", fname);
        final String href = item.attr("href");
        final String expected = client.content().contentUrl(hosted, STORE);

        assertThat(fname + " does not have a href", href, notNullValue());
        assertThat(fname + " has incorrect link: '" + href + "' (" + href.getClass().getName()
                + ")\nshould be: '" + expected + "' (String)", href, equalTo(expected));
    }// w  w  w  . j a  v  a  2  s  . c  o m
}

From source file:org.commonjava.aprox.folo.ftest.urls.StoreOneAndVerifyInHtmlListingTest.java

@Test
public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception {
    final byte[] data = "this is a test".getBytes();
    final ByteArrayInputStream stream = new ByteArrayInputStream(data);
    final String root = "/path/to/";
    final String path = root + "foo.txt";
    final String track = "track";

    content.store(track, hosted, STORE, path, stream);

    final AproxClientHttp http = getHttp();

    final HttpGet request = http.newRawGet(content.contentUrl(track, hosted, STORE, root));

    request.addHeader("Accept", "text/html");

    final CloseableHttpClient hc = http.newClient();
    final CloseableHttpResponse response = hc.execute(request);

    final InputStream listing = response.getEntity().getContent();
    final String html = IOUtils.toString(listing);

    // TODO: Charset!!
    final Document doc = Jsoup.parse(html);
    for (final Element item : doc.select("a.item-link")) {
        final String fname = item.text();
        System.out.printf("Listing contains: '%s'\n", fname);
        final String href = item.attr("href");
        final String expected = client.content().contentUrl(hosted, STORE, root, fname);

        assertThat(fname + " does not have a href", href, notNullValue());
        assertThat(fname + " has incorrect link: '" + href + "' (" + href.getClass().getName()
                + ")\nshould be: '" + expected + "' (String)", href, equalTo(expected));
    }//from  w w  w.ja  v  a2 s  .co m
}

From source file:org.commonjava.indy.folo.ftest.urls.StoreOneAndSourceStoreUrlInHtmlListingTest.java

@Test
public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception {
    final byte[] data = "this is a test".getBytes();
    final ByteArrayInputStream stream = new ByteArrayInputStream(data);
    final String root = "/path/to/";
    final String path = root + "foo.txt";
    final String track = "track";

    content.store(track, hosted, STORE, path, stream);

    final IndyClientHttp http = getHttp();

    final HttpGet request = http.newRawGet(content.contentUrl(track, hosted, STORE, root));

    request.addHeader("Accept", "text/html");

    final CloseableHttpClient hc = http.newClient();
    final CloseableHttpResponse response = hc.execute(request);

    final InputStream listing = response.getEntity().getContent();
    final String html = IOUtils.toString(listing);

    // TODO: Charset!!
    final Document doc = Jsoup.parse(html);
    for (final Element item : doc.select("a.source-link")) {
        final String fname = item.text();
        System.out.printf("Listing contains: '%s'\n", fname);
        final String href = item.attr("href");
        final String expected = client.content().contentUrl(hosted, STORE);

        assertThat(fname + " does not have a href", href, notNullValue());
        assertThat(fname + " has incorrect link: '" + href + "' (" + href.getClass().getName()
                + ")\nshould be: '" + expected + "' (String)", href, equalTo(expected));
    }//from  ww  w .  ja v a 2s  . c o m
}

From source file:org.commonjava.indy.folo.ftest.urls.StoreOneAndVerifyInHtmlListingTest.java

@Test
public void storeOneFileAndVerifyItInParentDirectoryListing() throws Exception {
    final byte[] data = "this is a test".getBytes();
    final ByteArrayInputStream stream = new ByteArrayInputStream(data);
    final String root = "/path/to/";
    final String path = root + "foo.txt";
    final String track = "track";

    content.store(track, hosted, STORE, path, stream);

    final IndyClientHttp http = getHttp();

    final HttpGet request = http.newRawGet(content.contentUrl(track, hosted, STORE, root));

    request.addHeader("Accept", "text/html");

    final CloseableHttpClient hc = http.newClient();
    final CloseableHttpResponse response = hc.execute(request);

    final InputStream listing = response.getEntity().getContent();
    final String html = IOUtils.toString(listing);

    // TODO: Charset!!
    final Document doc = Jsoup.parse(html);
    for (final Element item : doc.select("a.item-link")) {
        final String fname = item.text();
        System.out.printf("Listing contains: '%s'\n", fname);
        final String href = item.attr("href");
        final String expected = client.content().contentUrl(hosted, STORE, root, fname);

        assertThat(fname + " does not have a href", href, notNullValue());
        assertThat(fname + " has incorrect link: '" + href + "' (" + href.getClass().getName()
                + ")\nshould be: '" + expected + "' (String)", href, equalTo(expected));
    }/*ww  w.j av a 2 s.co m*/
}

From source file:io.crate.integrationtests.BlobSslEnabledITest.java

@Test
public void testGetBlob() throws Exception {
    // this test verifies that the non-zero-copy code path in the HttpBlobHandler works
    String digest = uploadSmallBlob();
    String blobUri = blobUri(digest);

    // can't follow redirects because ssl isn't really enabled
    // -> figure out the node that really has the blob

    CloseableHttpClient client = HttpClients.custom().disableRedirectHandling().build();
    List<String> redirectLocations = getRedirectLocations(client, blobUri, address);
    InetSocketAddress correctAddress;
    if (redirectLocations.isEmpty()) {
        correctAddress = address;/*from   w  ww. j a va 2s  .c o m*/
    } else {
        correctAddress = address2;
    }

    HttpGet httpGet = new HttpGet(String.format(Locale.ENGLISH, "http://%s:%s/_blobs/%s",
            correctAddress.getHostName(), correctAddress.getPort(), blobUri));

    CloseableHttpResponse response = client.execute(httpGet);
    assertEquals(1500, response.getEntity().getContentLength());
}

From source file:io.crate.integrationtests.RestSQLActionIntegrationTest.java

@Test
public void testExecutionErrorContainsStackTrace() throws Exception {
    CloseableHttpResponse resp = post("{\"stmt\": \"select 1 / 0\"}");
    String bodyAsString = EntityUtils.toString(resp.getEntity());
    assertThat(bodyAsString, containsString("DivideFunction.java"));
}

From source file:org.wso2.carbon.dynamic.client.web.proxy.OAuthEndpointProxy.java

@POST
@Consumes("application/x-www-form-urlencoded")
@Produces("application/json")
public Response issueAccessToken(MultivaluedMap<String, String> paramMap) {
    DefaultHttpClient httpClient = DCRProxyUtils.getHttpsClient();
    String host = DCRProxyUtils.getKeyManagerHost();
    Response response;/*from   w  w  w  .j  av  a 2  s .  c o  m*/
    try {
        URI uri = new URIBuilder().setScheme(Constants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_PROTOCOL)
                .setHost(host).setPath(Constants.RemoteServiceProperties.OAUTH2_TOKEN_ENDPOINT).build();
        HttpHost httpHost = new HttpHost(uri.toString());
        CloseableHttpResponse serverResponse = httpClient.execute(httpHost, null);
        HttpEntity responseData = serverResponse.getEntity();
        int status = serverResponse.getStatusLine().getStatusCode();
        String resp = EntityUtils.toString(responseData, Constants.CharSets.CHARSET_UTF_8);
        response = Response.status(DCRProxyUtils.getResponseStatus(status)).entity(resp).build();
    } catch (URISyntaxException | IOException e) {
        String msg = "Service invoke error occurred while registering client";
        log.error(msg, e);
        response = Response.status(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
    } finally {
        httpClient.close();
    }
    return response;
}

From source file:org.assertdevelopments.promise.poc.client.StreamResponse.java

StreamResponse(CloseableHttpResponse response) throws IOException {
    this.response = response;
    this.streamInputStream = new StreamInputStream(response.getEntity().getContent());
}

From source file:synapticloop.b2.request.B2AuthorizeAccountRequest.java

/**
 * Execute the call and return the authorize response
 * /*w  ww  .jav  a 2  s. c o  m*/
 * @return the authorize response
 * 
 * @throws B2ApiException if there was an error with the call
 * @throws IOException if there was an error communicating with the API service
 */
public B2AuthorizeAccountResponse getResponse() throws B2ApiException, IOException {
    final CloseableHttpResponse httpResponse = executeGet();
    return new B2AuthorizeAccountResponse(EntityUtils.toString(httpResponse.getEntity()));
}