com.ning.http.client
Class SimpleAsyncHttpClient

java.lang.Object
  extended by com.ning.http.client.SimpleAsyncHttpClient

public class SimpleAsyncHttpClient
extends Object

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()
 .setIdleConnectionInPoolTimeoutInMs(100)
 .setMaximumConnectionsTotal(50)
 .setRequestTimeoutInMs(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));
 


Nested Class Summary
static class SimpleAsyncHttpClient.Builder
           
static interface SimpleAsyncHttpClient.DerivedBuilder
          This interface contains possible configuration changes for a derived SimpleAsyncHttpClient.
static class SimpleAsyncHttpClient.ErrorDocumentBehaviour
           
 
Method Summary
 void close()
          Close the underlying AsyncHttpClient for this instance.
 Future<Response> delete()
           
 Future<Response> delete(BodyConsumer bodyConsumer)
           
 Future<Response> delete(BodyConsumer bodyConsumer, ThrowableHandler throwableHandler)
           
 Future<Response> delete(ThrowableHandler throwableHandler)
           
 SimpleAsyncHttpClient.DerivedBuilder derive()
          Returns a Builder for a derived SimpleAsyncHttpClient that uses the same instance of AsyncHttpClient to execute requests.
 Future<Response> get()
           
 Future<Response> get(BodyConsumer bodyConsumer)
           
 Future<Response> get(BodyConsumer bodyConsumer, ThrowableHandler throwableHandler)
           
 Future<Response> get(ThrowableHandler throwableHandler)
           
 Future<Response> head()
           
 Future<Response> head(ThrowableHandler throwableHandler)
           
 Future<Response> options()
           
 Future<Response> options(BodyConsumer bodyConsumer)
           
 Future<Response> options(BodyConsumer bodyConsumer, ThrowableHandler throwableHandler)
           
 Future<Response> options(ThrowableHandler throwableHandler)
           
 Future<Response> post(BodyConsumer consumer, Part... parts)
           
 Future<Response> post(BodyGenerator bodyGenerator)
           
 Future<Response> post(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer)
           
 Future<Response> post(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer, ThrowableHandler throwableHandler)
           
 Future<Response> post(BodyGenerator bodyGenerator, ThrowableHandler throwableHandler)
           
 Future<Response> post(Part... parts)
           
 Future<Response> put(BodyConsumer consumer, Part... parts)
           
 Future<Response> put(BodyGenerator bodyGenerator)
           
 Future<Response> put(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer)
           
 Future<Response> put(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer, ThrowableHandler throwableHandler)
           
 Future<Response> put(BodyGenerator bodyGenerator, ThrowableHandler throwableHandler)
           
 Future<Response> put(Part... parts)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

post

public Future<Response> post(Part... parts)
                      throws IOException
Throws:
IOException

post

public Future<Response> post(BodyConsumer consumer,
                             Part... parts)
                      throws IOException
Throws:
IOException

post

public Future<Response> post(BodyGenerator bodyGenerator)
                      throws IOException
Throws:
IOException

post

public Future<Response> post(BodyGenerator bodyGenerator,
                             ThrowableHandler throwableHandler)
                      throws IOException
Throws:
IOException

post

public Future<Response> post(BodyGenerator bodyGenerator,
                             BodyConsumer bodyConsumer)
                      throws IOException
Throws:
IOException

post

public Future<Response> post(BodyGenerator bodyGenerator,
                             BodyConsumer bodyConsumer,
                             ThrowableHandler throwableHandler)
                      throws IOException
Throws:
IOException

put

public Future<Response> put(Part... parts)
                     throws IOException
Throws:
IOException

put

public Future<Response> put(BodyConsumer consumer,
                            Part... parts)
                     throws IOException
Throws:
IOException

put

public Future<Response> put(BodyGenerator bodyGenerator,
                            BodyConsumer bodyConsumer)
                     throws IOException
Throws:
IOException

put

public Future<Response> put(BodyGenerator bodyGenerator,
                            BodyConsumer bodyConsumer,
                            ThrowableHandler throwableHandler)
                     throws IOException
Throws:
IOException

put

public Future<Response> put(BodyGenerator bodyGenerator)
                     throws IOException
Throws:
IOException

put

public Future<Response> put(BodyGenerator bodyGenerator,
                            ThrowableHandler throwableHandler)
                     throws IOException
Throws:
IOException

get

public Future<Response> get()
                     throws IOException
Throws:
IOException

get

public Future<Response> get(ThrowableHandler throwableHandler)
                     throws IOException
Throws:
IOException

get

public Future<Response> get(BodyConsumer bodyConsumer)
                     throws IOException
Throws:
IOException

get

public Future<Response> get(BodyConsumer bodyConsumer,
                            ThrowableHandler throwableHandler)
                     throws IOException
Throws:
IOException

delete

public Future<Response> delete()
                        throws IOException
Throws:
IOException

delete

public Future<Response> delete(ThrowableHandler throwableHandler)
                        throws IOException
Throws:
IOException

delete

public Future<Response> delete(BodyConsumer bodyConsumer)
                        throws IOException
Throws:
IOException

delete

public Future<Response> delete(BodyConsumer bodyConsumer,
                               ThrowableHandler throwableHandler)
                        throws IOException
Throws:
IOException

head

public Future<Response> head()
                      throws IOException
Throws:
IOException

head

public Future<Response> head(ThrowableHandler throwableHandler)
                      throws IOException
Throws:
IOException

options

public Future<Response> options()
                         throws IOException
Throws:
IOException

options

public Future<Response> options(ThrowableHandler throwableHandler)
                         throws IOException
Throws:
IOException

options

public Future<Response> options(BodyConsumer bodyConsumer)
                         throws IOException
Throws:
IOException

options

public Future<Response> options(BodyConsumer bodyConsumer,
                                ThrowableHandler throwableHandler)
                         throws IOException
Throws:
IOException

close

public void close()
Close the underlying AsyncHttpClient for this instance.

If this instance is derived from another instance, this method does nothing as the client instance is managed by the original SimpleAsyncHttpClient.

See Also:
derive(), AsyncHttpClient.close()

derive

public SimpleAsyncHttpClient.DerivedBuilder derive()
Returns a Builder for a derived SimpleAsyncHttpClient that uses the same instance of AsyncHttpClient to execute requests.

The original SimpleAsyncHttpClient is responsible for managing the underlying AsyncHttpClient. For the derived instance, close() is a NOOP. If the original SimpleAsyncHttpClient is closed, all derived instances become invalid.

Returns:
a Builder for a derived SimpleAsyncHttpClient that uses the same instance of AsyncHttpClient to execute requests, never null.


Copyright © 2011. All Rights Reserved.