Search in sources :

Example 11 with InputStreamBodyGenerator

use of org.asynchttpclient.request.body.generator.InputStreamBodyGenerator in project async-http-client by AsyncHttpClient.

the class SimpleAsyncHttpClientTest method byteArrayOutputStreamBodyConsumerTest.

@Test(groups = "standalone")
public void byteArrayOutputStreamBodyConsumerTest() throws Exception {
    try (SimpleAsyncHttpClient client = //
    new SimpleAsyncHttpClient.Builder().setPooledConnectionIdleTimeout(100).setMaxConnections(//
    50).setRequestTimeout(//
    5 * 60 * 1000).setUrl(//
    getTargetUrl()).setHeader("Content-Type", "text/html").build()) {
        ByteArrayOutputStream o = new ByteArrayOutputStream(10);
        Future<Response> future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new OutputStreamBodyConsumer(o));
        Response response = future.get();
        assertEquals(response.getStatusCode(), 200);
        assertEquals(o.toString(), MY_MESSAGE);
    }
}
Also used : Response(org.asynchttpclient.Response) InputStreamBodyGenerator(org.asynchttpclient.request.body.generator.InputStreamBodyGenerator) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Aggregations

InputStreamBodyGenerator (org.asynchttpclient.request.body.generator.InputStreamBodyGenerator)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 Response (org.asynchttpclient.Response)8 Test (org.testng.annotations.Test)8 AbstractBasicTest (org.asynchttpclient.AbstractBasicTest)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)2 RequestBuilder (org.asynchttpclient.RequestBuilder)2 FileBodyGenerator (org.asynchttpclient.request.body.generator.FileBodyGenerator)2 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)1 File (java.io.File)1 Serializable (java.io.Serializable)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Charset (java.nio.charset.Charset)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1