Package com.ning.http.client
Class SimpleAsyncHttpClient
java.lang.Object
com.ning.http.client.SimpleAsyncHttpClient
- All Implemented Interfaces:
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));
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic interfaceThis interface contains possible configuration changes for a derived SimpleAsyncHttpClient.static enum -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the underlying AsyncHttpClient for this instance.delete()delete(BodyConsumer bodyConsumer) delete(BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) delete(ThrowableHandler throwableHandler) derive()Returns a Builder for a derived SimpleAsyncHttpClient that uses the same instance ofAsyncHttpClientto execute requests.get()get(BodyConsumer bodyConsumer) get(BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) get(ThrowableHandler throwableHandler) head()head(ThrowableHandler throwableHandler) options()options(BodyConsumer bodyConsumer) options(BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) options(ThrowableHandler throwableHandler) post(BodyConsumer consumer, Part... parts) post(BodyGenerator bodyGenerator) post(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer) post(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) post(BodyGenerator bodyGenerator, ThrowableHandler throwableHandler) put(BodyConsumer consumer, Part... parts) put(BodyGenerator bodyGenerator) put(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer) put(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) put(BodyGenerator bodyGenerator, ThrowableHandler throwableHandler)
-
Method Details
-
post
- Throws:
IOException
-
post
- Throws:
IOException
-
post
- 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
- Throws:
IOException
-
put
- 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
- Throws:
IOException
-
put
public Future<Response> put(BodyGenerator bodyGenerator, ThrowableHandler throwableHandler) throws IOException - Throws:
IOException
-
get
- Throws:
IOException
-
get
- Throws:
IOException
-
get
- Throws:
IOException
-
get
public Future<Response> get(BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) throws IOException - Throws:
IOException
-
delete
- Throws:
IOException
-
delete
- Throws:
IOException
-
delete
- Throws:
IOException
-
delete
public Future<Response> delete(BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) throws IOException - Throws:
IOException
-
head
- Throws:
IOException
-
head
- Throws:
IOException
-
options
- Throws:
IOException
-
options
- Throws:
IOException
-
options
- 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.- Specified by:
closein interfaceAutoCloseable- See Also:
-
derive
Returns a Builder for a derived SimpleAsyncHttpClient that uses the same instance ofAsyncHttpClientto 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
AsyncHttpClientto execute requests, nevernull.
-