use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class HttpsProxyTest method testConfigProxy.
@Test(groups = "standalone")
public void testConfigProxy() throws Exception {
AsyncHttpClientConfig config = //
config().setFollowRedirect(//
true).setProxyServer(//
proxyServer("localhost", port1).build()).setUseInsecureTrustManager(//
true).build();
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config)) {
Response r = asyncHttpClient.executeRequest(get(getTargetUrl2())).get();
assertEquals(r.getStatusCode(), 200);
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class NTLMProxyTest method ntlmProxyTest.
@Test(groups = "standalone")
public void ntlmProxyTest() throws IOException, InterruptedException, ExecutionException {
try (AsyncHttpClient client = asyncHttpClient()) {
Request request = get("http://localhost").setProxyServer(ntlmProxy()).build();
Future<Response> responseFuture = client.executeRequest(request);
int status = responseFuture.get().getStatusCode();
Assert.assertEquals(status, 200);
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class ProxyTest method testRequestNonProxyHost.
@Test(groups = "standalone")
public void testRequestNonProxyHost() throws IOException, ExecutionException, TimeoutException, InterruptedException {
ProxyServer proxy = proxyServer("localhost", port1 - 1).setNonProxyHost("localhost").build();
try (AsyncHttpClient client = asyncHttpClient()) {
String target = "http://localhost:" + port1 + "/";
Future<Response> f = client.prepareGet(target).setProxyServer(proxy).execute();
Response resp = f.get(3, TimeUnit.SECONDS);
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader("target"), "/");
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class ProxyTest method testRequestLevelProxy.
// @Test
// public void asyncDoPostProxyTest() throws Throwable {
// try (AsyncHttpClient client = asyncHttpClient(config().setProxyServer(proxyServer("localhost", port2).build()))) {
// HttpHeaders h = new DefaultHttpHeaders();
// h.add(CONTENT_TYPE, APPLICATION_X_WWW_FORM_URLENCODED);
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < 5; i++) {
// sb.append("param_").append(i).append("=value_").append(i).append("&");
// }
// sb.setLength(sb.length() - 1);
//
// Response response = client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandler<Response>() {
// @Override
// public Response onCompleted(Response response) throws Throwable {
// return response;
// }
//
// @Override
// public void onThrowable(Throwable t) {
// }
// }).get();
//
// assertEquals(response.getStatusCode(), 200);
// assertEquals(response.getHeader("X-" + CONTENT_TYPE), APPLICATION_X_WWW_FORM_URLENCODED);
// }
// }
@Test(groups = "standalone")
public void testRequestLevelProxy() throws IOException, ExecutionException, TimeoutException, InterruptedException {
try (AsyncHttpClient client = asyncHttpClient()) {
String target = "http://localhost:1234/";
Future<Response> f = client.prepareGet(target).setProxyServer(proxyServer("localhost", port1)).execute();
Response resp = f.get(3, TimeUnit.SECONDS);
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader("target"), "/");
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class ProxyTest method testBothProxies.
@Test(groups = "standalone")
public void testBothProxies() throws IOException, ExecutionException, TimeoutException, InterruptedException {
try (AsyncHttpClient client = asyncHttpClient(config().setProxyServer(proxyServer("localhost", port1 - 1)))) {
String target = "http://localhost:1234/";
Future<Response> f = client.prepareGet(target).setProxyServer(proxyServer("localhost", port1)).execute();
Response resp = f.get(3, TimeUnit.SECONDS);
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader("target"), "/");
}
}
Aggregations