Search in sources :

Example 91 with HttpResponse

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

the class DefaultHttpClientTest method testServerClosesOutput.

private void testServerClosesOutput(SocketPolicy socketPolicy) throws Exception {
    server.enqueue(new MockResponse().setBody("This connection won't pool properly").setSocketPolicy(socketPolicy));
    server.enqueue(new MockResponse().setBody("This comes after a busted connection"));
    server.play();
    DefaultHttpClient client = new DefaultHttpClient();
    HttpResponse a = client.execute(new HttpGet(server.getUrl("/a").toURI()));
    assertEquals("This connection won't pool properly", contentToString(a));
    assertEquals(0, server.takeRequest().getSequenceNumber());
    HttpResponse b = client.execute(new HttpGet(server.getUrl("/b").toURI()));
    assertEquals("This comes after a busted connection", contentToString(b));
    // sequence number 0 means the HTTP socket connection was not reused
    assertEquals(0, server.takeRequest().getSequenceNumber());
}
Also used : MockResponse(com.google.mockwebserver.MockResponse) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 92 with HttpResponse

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

the class AbstractProxyTest method testParamPreferredOverSystemProperty.

private void testParamPreferredOverSystemProperty(ProxyConfig proxyConfig) throws Exception {
    server.enqueue(new MockResponse().setBody("Via request parameter proxy!"));
    server.play();
    System.setProperty("http.proxyHost", "proxy.foo");
    System.setProperty("http.proxyPort", "8080");
    HttpClient client = newHttpClient();
    HttpGet request = new HttpGet("http://origin.foo/bar");
    proxyConfig.configure(server, client, request);
    HttpResponse response = client.execute(request);
    assertEquals("Via request parameter proxy!", contentToString(response));
    RecordedRequest recordedRequest = server.takeRequest();
    assertEquals("GET http://origin.foo/bar HTTP/1.1", recordedRequest.getRequestLine());
}
Also used : RecordedRequest(com.google.mockwebserver.RecordedRequest) MockResponse(com.google.mockwebserver.MockResponse) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse)

Example 93 with HttpResponse

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

the class AbstractProxyTest method testConnectToHttps.

public void testConnectToHttps() throws Exception {
    TestSSLContext testSSLContext = TestSSLContext.create();
    server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
    server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via HTTPS"));
    server.play();
    HttpClient httpClient = newHttpClient();
    SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
    sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
    httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", sslSocketFactory, server.getPort()));
    HttpResponse response = httpClient.execute(new HttpGet("https://localhost:" + server.getPort() + "/foo"));
    assertEquals("this response comes via HTTPS", contentToString(response));
    RecordedRequest request = server.takeRequest();
    assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
}
Also used : RecordedRequest(com.google.mockwebserver.RecordedRequest) MockResponse(com.google.mockwebserver.MockResponse) Scheme(org.apache.http.conn.scheme.Scheme) AllowAllHostnameVerifier(org.apache.http.conn.ssl.AllowAllHostnameVerifier) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) TestSSLContext(libcore.javax.net.ssl.TestSSLContext) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory)

Example 94 with HttpResponse

use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project azure-tools-for-java by Microsoft.

the class SparkRestUtil method getEntity.

//    @Nullable
//    public static List<Application> getApplications(@NotNull ClusterDetail clusterDetail) throws HDIException, IOException {
//        HttpEntity entity = getEntity(clusterDetail, "applications");
//        String entityType = entity.getContentType().getValue();
//        if( entityType.equals("application/json")){
//            String json = EntityUtils.toString(entity);
//            List<Application> apps = objectMapper.readValue(json, TypeFactory.defaultInstance().constructType(List.class, Application.class));
//            return apps;
//        }
//        return null;
//    }
public static HttpEntity getEntity(@NotNull IClusterDetail clusterDetail, @NotNull String restUrl) throws HDIException, IOException {
    provider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(clusterDetail.getHttpUserName(), clusterDetail.getHttpPassword()));
    HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(provider).build();
    String url = String.format(SPARK_REST_API_ENDPOINT, clusterDetail.getName(), restUrl);
    HttpGet get = new HttpGet(url);
    HttpResponse response = client.execute(get);
    int code = response.getStatusLine().getStatusCode();
    if (code == HttpStatus.SC_OK || code == HttpStatus.SC_CREATED) {
        return response.getEntity();
    } else {
        throw new HDIException(response.getStatusLine().getReasonPhrase(), response.getStatusLine().getStatusCode());
    }
}
Also used : HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 95 with HttpResponse

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

the class WebSecurityExternalAuthTestCase method makeCall.

protected void makeCall(String user, int expectedStatusCode) throws Exception {
    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        HttpGet httpget = new HttpGet(url.toExternalForm() + "secured/");
        httpget.addHeader("User", user);
        HttpResponse response = httpClient.execute(httpget);
        HttpEntity entity = response.getEntity();
        StatusLine statusLine = response.getStatusLine();
        assertEquals(expectedStatusCode, statusLine.getStatusCode());
        EntityUtils.consume(entity);
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse)

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