Example usage for com.squareup.okhttp.internal.http RequestException getCause

List of usage examples for com.squareup.okhttp.internal.http RequestException getCause

Introduction

In this page you can find the example usage for com.squareup.okhttp.internal.http RequestException getCause.

Prototype

@Override
    public IOException getCause() 

Source Link

Usage

From source file:io.apiman.gateway.platforms.servlet.connectors.ok.HttpURLConnectionImpl.java

License:Apache License

/**
 * Sends a request and optionally reads a response. Returns true if the
 * request was successfully executed, and false if the request can be
 * retried. Throws an exception if the request failed permanently.
 *///from   w  ww . java2  s  . com
private boolean execute(boolean readResponse) throws IOException {
    try {
        httpEngine.sendRequest();
        route = httpEngine.getRoute();
        handshake = httpEngine.getConnection() != null ? httpEngine.getConnection().getHandshake() : null;
        if (readResponse) {
            httpEngine.readResponse();
        }

        return true;
    } catch (RequestException e) {
        // An attempt to interpret a request failed.
        IOException toThrow = e.getCause();
        httpEngineFailure = toThrow;
        throw toThrow;
    } catch (RouteException e) {
        // The attempt to connect via a route failed. The request will not have been sent.
        HttpEngine retryEngine = httpEngine.recover(e);
        if (retryEngine != null) {
            httpEngine = retryEngine;
            return false;
        }

        // Give up; recovery is not possible.
        IOException toThrow = e.getLastConnectException();
        httpEngineFailure = toThrow;
        throw toThrow;
    } catch (IOException e) {
        // An attempt to communicate with a server failed. The request may have been sent.
        HttpEngine retryEngine = httpEngine.recover(e);
        if (retryEngine != null) {
            httpEngine = retryEngine;
            return false;
        }

        // Give up; recovery is not possible.
        httpEngineFailure = e;
        throw e;
    }
}