/**
* Execute request and retry in case of a recoverable I/O failure
*/
private HttpResponse tryExecute(
final RoutedRequest req, final HttpContext context) throws HttpException, IOException {
RequestWrapper wrapper = req.getRequest();
HttpRoute route = req.getRoute();
HttpResponse response = null;
Exception retryReason = null;
for (;;) {
// Increment total exec count (with redirects)
execCount++;
// Increment exec count for this particular request
wrapper.incrementExecCount();
if (!wrapper.isRepeatable()) {
if (retryReason != null) {
throw new NonRepeatableRequestException("Cannot retry request " +
"with a non-repeatable request entity. The cause lists the " +
"reason the original request failed." + retryReason);
} else {
throw new NonRepeatableRequestException("Cannot retry request " +
"with a non-repeatable request entity.");
}
}
try {
if (!managedConn.isOpen()) {
// If we have a direct route to the target host
// just re-open connection and re-try the request
if (!route.isTunnelled()) {
if (DEBUG) {
Logger.debug("Reopening the direct connection.");
}
managedConn.open(route, context, params);
} else {
// otherwise give up
if (DEBUG) {
Logger.debug("Proxied connection. Need to start over.");
}
break;
}
}
response = requestExec.execute(wrapper, managedConn, context);
break;
} catch (IOException ex) {
try {
managedConn.close();
} catch (IOException ignore) {
}
if (retryHandler.retryRequest(ex, wrapper.getExecCount(), context)) {
retryReason = ex;
} else {
throw ex;
}
}
}
return response;
}
LibRequestDirector.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:YiBo
作者:
评论列表
文章目录