checkNotNull(request, "request is null");
checkNotNull(responseHandler, "responseHandler is null");
request = applyRequestFilters(request);
HttpRequest jettyRequest = buildJettyRequest(request);
final JettyResponseFuture<T, E> future = new JettyResponseFuture<>(request, jettyRequest, responseHandler, stats);
BufferingResponseListener listener = new BufferingResponseListener(Ints.checkedCast(new DataSize(10, Unit.MEGABYTE).toBytes()))
{
@Override
public void onComplete(Result result)
{
Throwable throwable = result.getFailure();
if (throwable != null) {
future.failed(throwable);
}
else {
future.completed(result.getResponse(), getContent());
}
}
};
try {
jettyRequest.send(listener);
}
catch (RuntimeException e) {
// normally this is a rejected execution exception because the client has been closed
future.failed(e);
}