com.ning.http.client
public class SimpleAsyncHttpClient extends java.lang.Object
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();
<p/>
StringBuilder s = new StringBuilder();
Future<Response> future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new AppendableBodyConsumer(s));
or
public void ByteArrayOutputStreamBodyConsumerTest() throws Throwable {
<p/>
SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder()
.setUrl(getTargetUrl())
.build();
<p/>
ByteArrayOutputStream o = new ByteArrayOutputStream(10);
Future<Response> future = client.post(new FileodyGenerator(myFile), new OutputStreamBodyConsumer(o));
}
Modifier and Type | Class and Description |
---|---|
static class |
SimpleAsyncHttpClient.Builder |
static interface |
SimpleAsyncHttpClient.DerivedBuilder
This interface contains possible configuration changes for a derived SimpleAsyncHttpClient.
|
static class |
SimpleAsyncHttpClient.ErrorDocumentBehaviour |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the underlying AsyncHttpClient for this instance.
|
java.util.concurrent.Future<Response> |
delete() |
java.util.concurrent.Future<Response> |
delete(BodyConsumer bodyConsumer) |
java.util.concurrent.Future<Response> |
delete(BodyConsumer bodyConsumer,
ThrowableHandler throwableHandler) |
java.util.concurrent.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. |
java.util.concurrent.Future<Response> |
get() |
java.util.concurrent.Future<Response> |
get(BodyConsumer bodyConsumer) |
java.util.concurrent.Future<Response> |
get(BodyConsumer bodyConsumer,
ThrowableHandler throwableHandler) |
java.util.concurrent.Future<Response> |
get(ThrowableHandler throwableHandler) |
java.util.concurrent.Future<Response> |
head() |
java.util.concurrent.Future<Response> |
head(ThrowableHandler throwableHandler) |
java.util.concurrent.Future<Response> |
options() |
java.util.concurrent.Future<Response> |
options(BodyConsumer bodyConsumer) |
java.util.concurrent.Future<Response> |
options(BodyConsumer bodyConsumer,
ThrowableHandler throwableHandler) |
java.util.concurrent.Future<Response> |
options(ThrowableHandler throwableHandler) |
java.util.concurrent.Future<Response> |
post(BodyConsumer consumer,
Part... parts) |
java.util.concurrent.Future<Response> |
post(BodyGenerator bodyGenerator) |
java.util.concurrent.Future<Response> |
post(BodyGenerator bodyGenerator,
BodyConsumer bodyConsumer) |
java.util.concurrent.Future<Response> |
post(BodyGenerator bodyGenerator,
BodyConsumer bodyConsumer,
ThrowableHandler throwableHandler) |
java.util.concurrent.Future<Response> |
post(BodyGenerator bodyGenerator,
ThrowableHandler throwableHandler) |
java.util.concurrent.Future<Response> |
post(Part... parts) |
java.util.concurrent.Future<Response> |
put(BodyConsumer consumer,
Part... parts) |
java.util.concurrent.Future<Response> |
put(BodyGenerator bodyGenerator) |
java.util.concurrent.Future<Response> |
put(BodyGenerator bodyGenerator,
BodyConsumer bodyConsumer) |
java.util.concurrent.Future<Response> |
put(BodyGenerator bodyGenerator,
BodyConsumer bodyConsumer,
ThrowableHandler throwableHandler) |
java.util.concurrent.Future<Response> |
put(BodyGenerator bodyGenerator,
ThrowableHandler throwableHandler) |
java.util.concurrent.Future<Response> |
put(Part... parts) |
public java.util.concurrent.Future<Response> post(Part... parts) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> post(BodyConsumer consumer, Part... parts) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> post(BodyGenerator bodyGenerator) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> post(BodyGenerator bodyGenerator, ThrowableHandler throwableHandler) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> post(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> post(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> put(Part... parts) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> put(BodyConsumer consumer, Part... parts) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> put(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> put(BodyGenerator bodyGenerator, BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> put(BodyGenerator bodyGenerator) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> put(BodyGenerator bodyGenerator, ThrowableHandler throwableHandler) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> get() throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> get(ThrowableHandler throwableHandler) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> get(BodyConsumer bodyConsumer) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> get(BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> delete() throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> delete(ThrowableHandler throwableHandler) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> delete(BodyConsumer bodyConsumer) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> delete(BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> head() throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> head(ThrowableHandler throwableHandler) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> options() throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> options(ThrowableHandler throwableHandler) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> options(BodyConsumer bodyConsumer) throws java.io.IOException
java.io.IOException
public java.util.concurrent.Future<Response> options(BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) throws java.io.IOException
java.io.IOException
public void close()
derive()
,
AsyncHttpClient.close()
public SimpleAsyncHttpClient.DerivedBuilder derive()
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.AsyncHttpClient
to execute requests, never
null
.Copyright © 2014. All Rights Reserved.