java类org.apache.http.impl.client.RoutedRequest的实例源码

LibRequestDirector.java 文件源码 项目:YiBo 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Establish connection either directly or through a tunnel and retry in case of
 * a recoverable I/O failure
 */
private void tryConnect(
        final RoutedRequest req, final HttpContext context) throws HttpException, IOException {
    HttpRoute route = req.getRoute();

    int connectCount = 0;
    for (;;) {
        // Increment connect count
        connectCount++;
        try {
            if (!managedConn.isOpen()) {
                managedConn.open(route, context, params);
            } else {
                managedConn.setSocketTimeout(HttpConnectionParams.getSoTimeout(params));
            }
            establishRoute(route, context);
            break;
        } catch (IOException ex) {
            try {
                managedConn.close();
            } catch (IOException ignore) {
            }
            if (retryHandler.retryRequest(ex, connectCount, context)) {
                if (DEBUG) {
                    Logger.debug("I/O exception ({}) caught when connecting to the target host: {}",
                            ex.getClass().getName(), ex.getMessage());
                    Logger.debug(ex.getMessage(), ex);
                    Logger.debug("Retrying connect");
                }
            } else {
                throw ex;
            }
        }
    }
}
YiBoRequestDirector.java 文件源码 项目:yibo-library 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Establish connection either directly or through a tunnel and retry in case of
 * a recoverable I/O failure
 */
private void tryConnect(
        final RoutedRequest req, final HttpContext context) throws HttpException, IOException {
    HttpRoute route = req.getRoute();

    int connectCount = 0;
    for (;;) {
        // Increment connect count
        connectCount++;
        try {
            if (!managedConn.isOpen()) {
                managedConn.open(route, context, params);
            } else {
                managedConn.setSocketTimeout(HttpConnectionParams.getSoTimeout(params));
            }
            establishRoute(route, context);
            break;
        } catch (IOException ex) {
            try {
                managedConn.close();
            } catch (IOException ignore) {
            }
            if (retryHandler.retryRequest(ex, connectCount, context)) {
                if (Constants.DEBUG) {
                    logger.debug("I/O exception ({}) caught when connecting to the target host: {}",
                            ex.getClass().getName(), ex.getMessage());
                    logger.debug(ex.getMessage(), ex);
                    logger.debug("Retrying connect");
                }
            } else {
                throw ex;
            }
        }
    }
}
RedirectRequestDirector.java 文件源码 项目:BigSemanticsJava 阅读 28 收藏 0 点赞 0 评论 0
@Override
protected RoutedRequest handleResponse(RoutedRequest roureq,
                                       HttpResponse response,
                                       HttpContext context) throws HttpException, IOException
{
  RoutedRequest req = super.handleResponse(roureq, response, context);
  if (req != null)
  {
    String redirectTarget = req.getRoute().getTargetHost().getHostName();
    req.getRequest().getOriginal().setHeader("Host", redirectTarget);
  }
  return req;
}
LibRequestDirector.java 文件源码 项目:YiBo 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 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;
}
YiBoRequestDirector.java 文件源码 项目:yibo-library 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}


问题


面经


文章

微信
公众号

扫码关注公众号