/**
* 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 (Constants.DEBUG) {
logger.debug("Cannot retry non-repeatable request");
}
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 (Constants.DEBUG) {
logger.debug("Reopening the direct connection.");
}
managedConn.open(route, context, params);
} else {
// otherwise give up
if (Constants.DEBUG) {
logger.debug("Proxied connection. Need to start over.");
}
break;
}
}
if (Constants.DEBUG) {
logger.debug("Attempt {} to execute request", execCount);
}
response = requestExec.execute(wrapper, managedConn, context);
break;
} catch (IOException ex) {
if (Constants.DEBUG) {
logger.debug("Closing the connection.");
}
try {
managedConn.close();
} catch (IOException ignore) {
}
if (retryHandler.retryRequest(ex, wrapper.getExecCount(), context)) {
if (Constants.DEBUG) {
logger.debug("I/O exception ({}) caught when processing request: {}",
ex.getClass().getName(), ex.getMessage());
logger.debug(ex.getMessage(), ex);
logger.debug("Retrying request");
}
retryReason = ex;
} else {
throw ex;
}
}
}
return response;
}
YiBoRequestDirector.java 文件源码
java
阅读 25
收藏 0
点赞 0
评论 0
项目:yibo-library
作者:
评论列表
文章目录