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

项目:YiBo    文件:LibRequestDirector.java   
/**
 * 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;
            }
        }
    }
}
项目:yibo-library    文件:YiBoRequestDirector.java   
/**
 * 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;
            }
        }
    }
}
项目:BigSemanticsJava    文件:RedirectRequestDirector.java   
@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;
}
项目:YiBo    文件:LibRequestDirector.java   
/**
 * 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;
}
项目:yibo-library    文件:YiBoRequestDirector.java   
/**
 * 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;
}