如何记录 Apache HttpAsyncClient 回调方法中发生的异常?例如下面的代码抛出 NullPointerException,但它是隐藏的。
CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();
try {
final HttpGet request = new HttpGet("https://google.com");
CountDownLatch sentRequestsCountDown = new CountDownLatch(1);
String nullObject = null;
final FutureCallback<HttpResponse> callback = new FutureCallback<HttpResponse>() {
@Override
public void completed(HttpResponse result) {
sentRequestsCountDown.countDown();
// NPE thrown here:
String itThrowsNPE = nullObject.toString();
System.out.println(itThrowsNPE);
}
@Override
public void failed(Exception ex) {
sentRequestsCountDown.countDown();
System.out.println("failed");
}
@Override
public void cancelled() {
sentRequestsCountDown.countDown();
System.out.println("cancelled");
}
};
client.start();
client.execute(request, callback);
sentRequestsCountDown.await();
} finally {
client.close();
}
当我运行它时,我没有看到任何异常记录。如何为此配置记录器?似乎默认使用NO_OP ExceptionLogger,我找不到更改它的方法。