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());
}
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());
}
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());
}
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());
}
}
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);
}
}
Aggregations