Search in sources :

Example 91 with HttpGet

use of org.apache.http.client.methods.HttpGet in project custom-cert-https by nelenkov.

the class MainActivity method httpClientConnect.

private void httpClientConnect() {
    new GetHtmlTask() {

        @Override
        protected String doInBackground(Void... arg0) {
            try {
                boolean useClientAuth = useClientAuthCb.isChecked();
                SSLContext sslContext = createSslContext(useClientAuth);
                MySSLSocketFactory socketFactory = new MySSLSocketFactory(sslContext, new BrowserCompatHostnameVerifier());
                HttpClient client = createHttpClient(socketFactory);
                HttpGet get = new HttpGet(useClientAuth ? CLIENT_AUTH_URL : SERVER_AUTH_URL);
                HttpResponse response = client.execute(get);
                if (response.getStatusLine().getStatusCode() != 200) {
                    return "Error: " + response.getStatusLine();
                } else {
                    return EntityUtils.toString(response.getEntity());
                }
            } catch (Exception e) {
                Log.d(TAG, "Error: " + e.getMessage(), e);
                error = e;
                return null;
            }
        }
    }.execute();
}
Also used : DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) BrowserCompatHostnameVerifier(org.apache.http.conn.ssl.BrowserCompatHostnameVerifier) HttpResponse(org.apache.http.HttpResponse) SSLContext(javax.net.ssl.SSLContext) GeneralSecurityException(java.security.GeneralSecurityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

Example 92 with HttpGet

use of org.apache.http.client.methods.HttpGet 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 93 with HttpGet

use of org.apache.http.client.methods.HttpGet 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 94 with HttpGet

use of org.apache.http.client.methods.HttpGet 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 95 with HttpGet

use of org.apache.http.client.methods.HttpGet 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

HttpGet (org.apache.http.client.methods.HttpGet)1143 HttpResponse (org.apache.http.HttpResponse)717 Test (org.junit.Test)504 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)242 TestHttpClient (io.undertow.testutils.TestHttpClient)239 IOException (java.io.IOException)200 HttpClient (org.apache.http.client.HttpClient)185 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)179 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)176 HttpEntity (org.apache.http.HttpEntity)152 Header (org.apache.http.Header)133 InputStream (java.io.InputStream)103 URI (java.net.URI)83 JsonNode (com.fasterxml.jackson.databind.JsonNode)68 ArrayList (java.util.ArrayList)60 MockResponse (com.google.mockwebserver.MockResponse)54 HttpPost (org.apache.http.client.methods.HttpPost)54 Deployment (org.activiti.engine.test.Deployment)49 ClientProtocolException (org.apache.http.client.ClientProtocolException)46 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)45