Search in sources :

Example 41 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse 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 42 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse 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 43 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse 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 44 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse 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)

Example 45 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project neo4j by neo4j.

the class ConfigureBaseUriIT method shouldUseRequestUriWhenNoXForwardHeadersPresent.

@Test
public void shouldUseRequestUriWhenNoXForwardHeadersPresent() throws Exception {
    URI rootUri = functionalTestHelper.baseUri();
    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet(rootUri);
        httpget.setHeader("Accept", "application/json");
        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);
        assertFalse(responseEntityBody.contains("https://foobar.com"));
        assertFalse(responseEntityBody.contains(":0"));
        assertTrue(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

HttpResponse (org.apache.http.HttpResponse)4366 Test (org.junit.Test)2158 HttpGet (org.apache.http.client.methods.HttpGet)1833 IOException (java.io.IOException)1110 URI (java.net.URI)834 HttpPost (org.apache.http.client.methods.HttpPost)759 HttpClient (org.apache.http.client.HttpClient)600 HttpEntity (org.apache.http.HttpEntity)541 TestHttpClient (io.undertow.testutils.TestHttpClient)403 InputStream (java.io.InputStream)398 Header (org.apache.http.Header)385 StringEntity (org.apache.http.entity.StringEntity)363 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)344 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)338 HttpPut (org.apache.http.client.methods.HttpPut)320 ArrayList (java.util.ArrayList)316 Identity (org.olat.core.id.Identity)262 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)253 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)209 File (java.io.File)196