use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class ProxyTest method testWildcardNonProxyHosts.
// @Test(groups = "standalone")
public void testWildcardNonProxyHosts() throws IOException, ExecutionException, TimeoutException, InterruptedException {
// FIXME not threadsafe!
Properties originalProps = new Properties();
originalProps.putAll(System.getProperties());
System.setProperty(ProxyUtils.PROXY_HOST, "127.0.0.1");
System.setProperty(ProxyUtils.PROXY_PORT, String.valueOf(port1));
System.setProperty(ProxyUtils.PROXY_NONPROXYHOSTS, "127.*");
AsyncHttpClientConfigHelper.reloadProperties();
try (AsyncHttpClient client = asyncHttpClient(config().setUseProxyProperties(true))) {
String nonProxifiedTarget = "http://127.0.0.1:1234/";
Future<Response> f = client.prepareGet(nonProxifiedTarget).execute();
try {
f.get(3, TimeUnit.SECONDS);
fail("should not be able to connect");
} catch (ExecutionException e) {
// ok, no proxy used
}
} finally {
System.setProperties(originalProps);
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class ReactiveStreamsDownLoadTest method streamedResponseSmallFileTest.
@Test(groups = "standalone")
public void streamedResponseSmallFileTest() throws Throwable {
try (AsyncHttpClient c = asyncHttpClient()) {
String smallFileName = "http://localhost:" + serverPort + "/" + smallFile.getName();
ListenableFuture<SimpleStreamedAsyncHandler> future = c.prepareGet(smallFileName).execute(new SimpleStreamedAsyncHandler());
byte[] result = future.get().getBytes();
LOGGER.debug("Result file size: " + result.length);
assertEquals(result.length, smallFile.length());
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class ReactiveStreamsTest method streamedResponseTest.
@Test(groups = "standalone")
public void streamedResponseTest() throws Throwable {
try (AsyncHttpClient c = asyncHttpClient()) {
ListenableFuture<SimpleStreamedAsyncHandler> future = c.preparePost(getTargetUrl()).setBody(LARGE_IMAGE_BYTES).execute(new SimpleStreamedAsyncHandler());
assertEquals(future.get().getBytes(), LARGE_IMAGE_BYTES);
// Run it again to check that the pipeline is in a good state
future = c.preparePost(getTargetUrl()).setBody(LARGE_IMAGE_BYTES).execute(new SimpleStreamedAsyncHandler());
assertEquals(future.get().getBytes(), LARGE_IMAGE_BYTES);
// Make sure a regular request still works
assertEquals(c.preparePost(getTargetUrl()).setBody("Hello").execute().get().getResponseBody(), "Hello");
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class ReactiveStreamsTest method testFailingStream.
@Test(groups = "standalone", expectedExceptions = ExecutionException.class)
public void testFailingStream() throws Exception {
try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
Observable<ByteBuffer> failingObservable = Observable.error(new FailedStream());
Publisher<ByteBuffer> failingPublisher = RxReactiveStreams.toPublisher(failingObservable);
client.preparePut(getTargetUrl()).setBody(failingPublisher).execute().get();
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class ReactiveStreamsTest method testStreamingPutImage.
@Test(groups = "standalone")
public void testStreamingPutImage() throws Exception {
try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
Response response = client.preparePut(getTargetUrl()).setBody(LARGE_IMAGE_PUBLISHER).execute().get();
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getResponseBodyAsBytes(), LARGE_IMAGE_BYTES);
}
}
Aggregations