Search in sources :

Example 86 with AsyncHttpClient

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);
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.asynchttpclient.Response) Properties(java.util.Properties) ExecutionException(java.util.concurrent.ExecutionException) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient)

Example 87 with AsyncHttpClient

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());
    }
}
Also used : AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test)

Example 88 with AsyncHttpClient

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");
    }
}
Also used : AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 89 with AsyncHttpClient

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();
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 90 with AsyncHttpClient

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);
    }
}
Also used : Response(org.asynchttpclient.Response) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Aggregations

AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)146 Test (org.testng.annotations.Test)119 Response (org.asynchttpclient.Response)71 AbstractBasicTest (org.asynchttpclient.AbstractBasicTest)66 HttpServletResponse (javax.servlet.http.HttpServletResponse)40 CountDownLatch (java.util.concurrent.CountDownLatch)31 DefaultAsyncHttpClient (org.asynchttpclient.DefaultAsyncHttpClient)26 AtomicReference (java.util.concurrent.atomic.AtomicReference)23 RequestBuilder (org.asynchttpclient.RequestBuilder)16 IOException (java.io.IOException)14 RouteBuilder (org.apache.camel.builder.RouteBuilder)14 ExecutionException (java.util.concurrent.ExecutionException)13 Request (org.asynchttpclient.Request)13 WebSocket (org.asynchttpclient.ws.WebSocket)12 Test (org.junit.Test)11 AsyncHttpClientConfig (org.asynchttpclient.AsyncHttpClientConfig)10 File (java.io.File)9 WebSocketTextListener (org.asynchttpclient.ws.WebSocketTextListener)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7