org.apache.http.client.NonRepeatableRequestException Java Examples

The following examples show how to use org.apache.http.client.NonRepeatableRequestException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LibRequestDirector.java    From YiBo with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}