Search in sources :

Example 81 with HttpEntity

use of org.apache.http.HttpEntity in project neo4j by neo4j.

the class RetrieveRelationshipsFromNodeIT method shouldParameteriseUrisInRelationshipRepresentationWithoutHostHeaderUsingRequestUri.

@Test
public void shouldParameteriseUrisInRelationshipRepresentationWithoutHostHeaderUsingRequestUri() throws Exception {
    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet("http://localhost:7474/db/data/relationship/" + likes);
        httpget.setHeader("Accept", "application/json");
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        String entityBody = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8);
        assertThat(entityBody, containsString("http://localhost:7474/db/data/relationship/" + likes));
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) Test(org.junit.Test)

Example 82 with HttpEntity

use of org.apache.http.HttpEntity in project neo4j by neo4j.

the class RetrieveRelationshipsFromNodeIT method shouldParameteriseUrisInRelationshipRepresentationWithHostHeaderValue.

@Test
public void shouldParameteriseUrisInRelationshipRepresentationWithHostHeaderValue() throws Exception {
    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet("http://localhost:7474/db/data/relationship/" + likes);
        httpget.setHeader("Accept", "application/json");
        httpget.setHeader("Host", "dummy.neo4j.org");
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        String entityBody = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8);
        System.out.println(entityBody);
        assertThat(entityBody, containsString("http://dummy.neo4j.org/db/data/relationship/" + likes));
        assertThat(entityBody, not(containsString("localhost:7474")));
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) Test(org.junit.Test)

Example 83 with HttpEntity

use of org.apache.http.HttpEntity in project graphdb by neo4j-attic.

the class PingerTest method shouldRespondToHttpClientGet.

/**
     * Test that the LocalTestServer actually works.
     *
     * @throws Exception
     */
@Test
public void shouldRespondToHttpClientGet() throws Exception {
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(serverUrl + "/?id=storeId+v=kernelVersion");
    System.out.println("HttpClient: http-get " + httpget.getURI());
    HttpResponse response = httpclient.execute(httpget);
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        InputStream instream = entity.getContent();
        int l;
        byte[] tmp = new byte[2048];
        while ((l = instream.read(tmp)) != -1) {
        }
    }
    assertThat(response, notNullValue());
    assertThat(response.getStatusLine().getStatusCode(), is(HttpStatus.SC_OK));
}
Also used : HttpEntity(org.apache.http.HttpEntity) InputStream(java.io.InputStream) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Test(org.junit.Test)

Example 84 with HttpEntity

use of org.apache.http.HttpEntity in project android-demos by novoda.

the class JsonRequest method retrieveStream.

private InputStream retrieveStream(String url) {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet getRequest = new HttpGet(url);
    try {
        HttpResponse getResponse = client.execute(getRequest);
        final int statusCode = getResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            Log.w(getClass().getSimpleName(), "An error occurred with this URL: " + url + "  Http status code: " + statusCode);
            return null;
        }
        HttpEntity getResponseEntity = getResponse.getEntity();
        return getResponseEntity.getContent();
    } catch (IOException e) {
        getRequest.abort();
        Log.e(TAG, "An error occurred with this URL: " + url, e);
    }
    return null;
}
Also used : HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 85 with HttpEntity

use of org.apache.http.HttpEntity in project Android-Universal-Image-Loader by nostra13.

the class HttpClientImageDownloader method getStreamFromNetwork.

@Override
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
    HttpGet httpRequest = new HttpGet(imageUri);
    HttpResponse response = httpClient.execute(httpRequest);
    HttpEntity entity = response.getEntity();
    BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
    return bufHttpEntity.getContent();
}
Also used : HttpEntity(org.apache.http.HttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse)

Aggregations

HttpEntity (org.apache.http.HttpEntity)518 HttpResponse (org.apache.http.HttpResponse)185 HttpGet (org.apache.http.client.methods.HttpGet)152 IOException (java.io.IOException)144 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)105 Test (org.junit.Test)93 HttpPost (org.apache.http.client.methods.HttpPost)84 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)83 InputStream (java.io.InputStream)71 ArrayList (java.util.ArrayList)69 Header (org.apache.http.Header)64 StatusLine (org.apache.http.StatusLine)61 URI (java.net.URI)58 NameValuePair (org.apache.http.NameValuePair)58 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)58 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)58 HttpClient (org.apache.http.client.HttpClient)55 StringEntity (org.apache.http.entity.StringEntity)51 InputStreamReader (java.io.InputStreamReader)44 BufferedReader (java.io.BufferedReader)41