Class SimpleAsyncHttpClient

java.lang.Object
com.ning.http.client.SimpleAsyncHttpClient
All Implemented Interfaces:
AutoCloseable

public class SimpleAsyncHttpClient extends Object implements AutoCloseable
Simple implementation of AsyncHttpClient and it's related builders (AsyncHttpClientConfig, Realm, ProxyServer and AsyncHandler. You can build powerful application by just using this class.

This class rely on BodyGenerator and BodyConsumer for handling the request and response body. No AsyncHandler are required. As simple as:

 SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder()
 .setIdleConnectionInPoolTimeout(100)
 .setMaximumConnectionsTotal(50)
 .setRequestTimeout(5 * 60 * 1000)
 .setUrl(getTargetUrl())
 .setHeader("Content-Type", "text/html").build();
 

StringBuilder s = new StringBuilder(); Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new AppendableBodyConsumer(s));

or
 public void ByteArrayOutputStreamBodyConsumerTest() throws Throwable {
 

SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder() .setUrl(getTargetUrl()) .build();

ByteArrayOutputStream o = new ByteArrayOutputStream(10); Future future = client.post(new FileodyGenerator(myFile), new OutputStreamBodyConsumer(o));