Search in sources :

Example 66 with DefaultHttpClient

use of org.apache.http.impl.client.DefaultHttpClient in project neo4j by neo4j.

the class UdcExtensionImplTest method blockUntilServerAvailable.

private void blockUntilServerAvailable(final URL url) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final PointerTo<Boolean> flag = new PointerTo<>(false);
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            while (!flag.getValue()) {
                try {
                    HttpGet httpget = new HttpGet(url.toURI());
                    httpget.addHeader("Accept", "application/json");
                    DefaultHttpClient client = new DefaultHttpClient();
                    client.execute(httpget);
                    // If we get here, the server's ready
                    flag.setValue(true);
                    latch.countDown();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    });
    t.run();
    assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
    t.join();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) IOException(java.io.IOException)

Example 67 with DefaultHttpClient

use of org.apache.http.impl.client.DefaultHttpClient in project neo4j by neo4j.

the class RetrieveNodeIT method shouldParameteriseUrisInNodeRepresentationWithHostHeaderValue.

@Test
public void shouldParameteriseUrisInNodeRepresentationWithHostHeaderValue() throws Exception {
    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet(nodeUri);
        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);
        assertThat(entityBody, containsString("http://dummy.neo4j.org/db/data/node/"));
    } 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) Test(org.junit.Test)

Example 68 with DefaultHttpClient

use of org.apache.http.impl.client.DefaultHttpClient in project neo4j by neo4j.

the class RetrieveNodeIT method shouldParameteriseUrisInNodeRepresentationWithoutHostHeaderUsingRequestUri.

@Test
public void shouldParameteriseUrisInNodeRepresentationWithoutHostHeaderUsingRequestUri() throws Exception {
    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet(nodeUri);
        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(nodeUri.toString()));
    } 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) Test(org.junit.Test)

Example 69 with DefaultHttpClient

use of org.apache.http.impl.client.DefaultHttpClient 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 70 with DefaultHttpClient

use of org.apache.http.impl.client.DefaultHttpClient 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)

Aggregations

DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)342 HttpResponse (org.apache.http.HttpResponse)199 HttpGet (org.apache.http.client.methods.HttpGet)167 HttpClient (org.apache.http.client.HttpClient)139 IOException (java.io.IOException)104 Test (org.junit.Test)65 HttpPost (org.apache.http.client.methods.HttpPost)64 HttpEntity (org.apache.http.HttpEntity)55 BasicHttpParams (org.apache.http.params.BasicHttpParams)49 ClientProtocolException (org.apache.http.client.ClientProtocolException)48 InputStream (java.io.InputStream)47 HttpParams (org.apache.http.params.HttpParams)43 Scheme (org.apache.http.conn.scheme.Scheme)39 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)38 ArrayList (java.util.ArrayList)32 URI (java.net.URI)30 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)30 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)29 InputStreamReader (java.io.InputStreamReader)28 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)27