AsyncHttpClient client = getAsyncHttpClient(null);
try {
final AtomicBoolean headerSent = new AtomicBoolean(false);
final AtomicBoolean operationCompleted = new AtomicBoolean(false);
Response resp = client.preparePost("http://127.0.0.1:" + port1 + "/").setBody(SIMPLE_TEXT_FILE).execute(new AsyncCompletionHandler<Response>() {
public STATE onHeaderWriteCompleted() {
headerSent.set(true);
return STATE.CONTINUE;
}
public STATE onContentWriteCompleted() {
operationCompleted.set(true);
return STATE.CONTINUE;
}
@Override
public Response onCompleted(Response response) throws Exception {
return response;
}
}).get();
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING);
assertTrue(operationCompleted.get());
assertTrue(headerSent.get());
} finally {
client.close();
}