Search in sources :

Example 21 with HttpClient

use of org.apache.http.client.HttpClient 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 22 with HttpClient

use of org.apache.http.client.HttpClient 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 23 with HttpClient

use of org.apache.http.client.HttpClient in project neo4j by neo4j.

the class DisableWADLIT method should404OnAnyUriEndinginWADL.

@Test
public void should404OnAnyUriEndinginWADL() throws Exception {
    URI nodeUri = new URI("http://localhost:7474/db/data/application.wadl");
    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet(nodeUri);
        httpget.setHeader("Accept", "*/*");
        HttpResponse response = httpclient.execute(httpget);
        assertEquals(404, response.getStatusLine().getStatusCode());
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}
Also used : 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) URI(java.net.URI) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Test(org.junit.Test)

Example 24 with HttpClient

use of org.apache.http.client.HttpClient in project neo4j by neo4j.

the class ConfigureBaseUriIT method shouldForwardHttpAndFirstHost.

@Test
public void shouldForwardHttpAndFirstHost() throws Exception {
    URI rootUri = functionalTestHelper.baseUri();
    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet(rootUri);
        httpget.setHeader("Accept", "application/json");
        httpget.setHeader("X-Forwarded-Host", "foobar.com, bazbar.com");
        httpget.setHeader("X-Forwarded-Proto", "http");
        HttpResponse response = httpclient.execute(httpget);
        String length = response.getHeaders("CONTENT-LENGTH")[0].getValue();
        byte[] data = new byte[Integer.valueOf(length)];
        response.getEntity().getContent().read(data);
        String responseEntityBody = new String(data);
        assertTrue(responseEntityBody.contains("http://foobar.com"));
        assertFalse(responseEntityBody.contains("http://localhost"));
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}
Also used : 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) URI(java.net.URI) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Test(org.junit.Test)

Example 25 with HttpClient

use of org.apache.http.client.HttpClient in project neo4j by neo4j.

the class ConfigureBaseUriIT method shouldForwardHttpAndHost.

@Test
public void shouldForwardHttpAndHost() throws Exception {
    URI rootUri = functionalTestHelper.baseUri();
    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet(rootUri);
        httpget.setHeader("Accept", "application/json");
        httpget.setHeader("X-Forwarded-Host", "foobar.com");
        httpget.setHeader("X-Forwarded-Proto", "http");
        HttpResponse response = httpclient.execute(httpget);
        String length = response.getHeaders("CONTENT-LENGTH")[0].getValue();
        byte[] data = new byte[Integer.valueOf(length)];
        response.getEntity().getContent().read(data);
        String responseEntityBody = new String(data);
        assertTrue(responseEntityBody.contains("http://foobar.com"));
        assertFalse(responseEntityBody.contains("http://localhost"));
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}
Also used : 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) URI(java.net.URI) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Test(org.junit.Test)

Aggregations

HttpClient (org.apache.http.client.HttpClient)941 HttpResponse (org.apache.http.HttpResponse)584 HttpGet (org.apache.http.client.methods.HttpGet)429 IOException (java.io.IOException)308 Test (org.junit.Test)275 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)272 HttpPost (org.apache.http.client.methods.HttpPost)212 HttpEntity (org.apache.http.HttpEntity)128 URI (java.net.URI)92 InputStream (java.io.InputStream)81 StringEntity (org.apache.http.entity.StringEntity)74 ArrayList (java.util.ArrayList)69 ClientProtocolException (org.apache.http.client.ClientProtocolException)66 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)61 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)61 InputStreamReader (java.io.InputStreamReader)59 URL (java.net.URL)57 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)53 URISyntaxException (java.net.URISyntaxException)50 MockResponse (com.google.mockwebserver.MockResponse)48