use of org.apache.http.impl.client.CloseableHttpClient in project dropwizard by dropwizard.
the class DropwizardApacheConnectorTest method multiple_headers_with_the_same_name_are_processed_successfully.
@Test
public void multiple_headers_with_the_same_name_are_processed_successfully() throws Exception {
final CloseableHttpClient client = mock(CloseableHttpClient.class);
final DropwizardApacheConnector dropwizardApacheConnector = new DropwizardApacheConnector(client, null, false);
final Header[] apacheHeaders = { new BasicHeader("Set-Cookie", "test1"), new BasicHeader("Set-Cookie", "test2") };
final CloseableHttpResponse apacheResponse = mock(CloseableHttpResponse.class);
when(apacheResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(apacheResponse.getAllHeaders()).thenReturn(apacheHeaders);
when(client.execute(Mockito.any())).thenReturn(apacheResponse);
final ClientRequest jerseyRequest = mock(ClientRequest.class);
when(jerseyRequest.getUri()).thenReturn(URI.create("http://localhost"));
when(jerseyRequest.getMethod()).thenReturn("GET");
when(jerseyRequest.getHeaders()).thenReturn(new MultivaluedHashMap<>());
final ClientResponse jerseyResponse = dropwizardApacheConnector.apply(jerseyRequest);
assertThat(jerseyResponse.getStatus()).isEqualTo(apacheResponse.getStatusLine().getStatusCode());
}
use of org.apache.http.impl.client.CloseableHttpClient in project dropwizard by dropwizard.
the class HttpClientBuilderTest method usesTheDefaultRoutePlanner.
@Test
public void usesTheDefaultRoutePlanner() throws Exception {
final CloseableHttpClient httpClient = builder.using(configuration).createClient(apacheBuilder, connectionManager, "test").getClient();
assertThat(httpClient).isNotNull();
assertThat(spyHttpClientBuilderField("routePlanner", apacheBuilder)).isNull();
assertThat(spyHttpClientField("routePlanner", httpClient)).isInstanceOf(DefaultRoutePlanner.class);
}
use of org.apache.http.impl.client.CloseableHttpClient in project dropwizard by dropwizard.
the class HttpClientBuilderTest method usesProxyWithAuth.
@Test
public void usesProxyWithAuth() throws Exception {
HttpClientConfiguration config = new HttpClientConfiguration();
AuthConfiguration auth = new AuthConfiguration("secret", "stuff");
ProxyConfiguration proxy = new ProxyConfiguration("192.168.52.11", 8080, "http", auth);
config.setProxyConfiguration(proxy);
CloseableHttpClient httpClient = checkProxy(config, new HttpHost("dropwizard.io", 80), new HttpHost("192.168.52.11", 8080, "http"));
CredentialsProvider credentialsProvider = (CredentialsProvider) FieldUtils.getField(httpClient.getClass(), "credentialsProvider", true).get(httpClient);
assertThat(credentialsProvider.getCredentials(new AuthScope("192.168.52.11", 8080))).isEqualTo(new UsernamePasswordCredentials("secret", "stuff"));
}
use of org.apache.http.impl.client.CloseableHttpClient in project dropwizard by dropwizard.
the class HttpClientBuilderTest method checkProxy.
private CloseableHttpClient checkProxy(HttpClientConfiguration config, HttpHost target, HttpHost expectedProxy) throws Exception {
CloseableHttpClient httpClient = builder.using(config).build("test");
HttpRoutePlanner routePlanner = (HttpRoutePlanner) FieldUtils.getField(httpClient.getClass(), "routePlanner", true).get(httpClient);
HttpRoute route = routePlanner.determineRoute(target, new HttpGet(target.toURI()), new BasicHttpContext());
assertThat(route.getProxyHost()).isEqualTo(expectedProxy);
assertThat(route.getTargetHost()).isEqualTo(target);
assertThat(route.getHopCount()).isEqualTo(expectedProxy != null ? 2 : 1);
return httpClient;
}
use of org.apache.http.impl.client.CloseableHttpClient in project nanohttpd by NanoHttpd.
the class TestNanoFileUpLoad method testPostWithMultipartFormUpload3.
@Test
public void testPostWithMultipartFormUpload3() throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
String textFileName = UPLOAD_JAVA_FILE;
HttpPost post = new HttpPost("http://localhost:8192/uploadFile3");
executeUpload(httpclient, textFileName, post);
FileItem file = this.testServer.files.get("upfile").get(0);
Assert.assertEquals(file.getSize(), new File(textFileName).length());
}
Aggregations