Search in sources :

Example 1 with Route

use of com.squareup.okhttp.Route in project phonegap-facebook-plugin by Wizcorp.

the class RouteSelector method next.

/**
   * Returns the next route address to attempt.
   *
   * @throws NoSuchElementException if there are no more routes to attempt.
   */
public Connection next() throws IOException {
    // Always prefer pooled connections over new connections.
    Connection pooled = pool.get(address);
    if (pooled != null) {
        return pooled;
    }
    // Compute the next route to attempt.
    if (!hasNextTlsMode()) {
        if (!hasNextInetSocketAddress()) {
            if (!hasNextProxy()) {
                if (!hasNextPostponed()) {
                    throw new NoSuchElementException();
                }
                return new Connection(nextPostponed());
            }
            lastProxy = nextProxy();
            resetNextInetSocketAddress(lastProxy);
        }
        lastInetSocketAddress = nextInetSocketAddress();
        resetNextTlsMode();
    }
    boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
    Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
    if (failedRoutes.contains(route)) {
        postponedRoutes.add(route);
        // tried last.
        return next();
    }
    return new Connection(route);
}
Also used : Connection(com.squareup.okhttp.Connection) NoSuchElementException(java.util.NoSuchElementException) Route(com.squareup.okhttp.Route)

Example 2 with Route

use of com.squareup.okhttp.Route in project robovm by robovm.

the class RouteSelector method connectFailed.

/**
   * Clients should invoke this method when they encounter a connectivity
   * failure on a connection returned by this route selector.
   */
public void connectFailed(Connection connection, IOException failure) {
    Route failedRoute = connection.getRoute();
    if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
        // Tell the proxy selector when we fail to connect on a fresh connection.
        proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
    }
    routeDatabase.failed(failedRoute, failure);
}
Also used : Route(com.squareup.okhttp.Route)

Example 3 with Route

use of com.squareup.okhttp.Route in project cordova-android-chromeview by thedracle.

the class RouteSelector method connectFailed.

/**
   * Clients should invoke this method when they encounter a connectivity
   * failure on a connection returned by this route selector.
   */
public void connectFailed(Connection connection, IOException failure) {
    Route failedRoute = connection.getRoute();
    if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
        // Tell the proxy selector when we fail to connect on a fresh connection.
        proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
    }
    failedRoutes.add(failedRoute);
    if (!(failure instanceof SSLHandshakeException)) {
        // If the problem was not related to SSL then it will also fail with
        // a different Tls mode therefore we can be proactive about it.
        failedRoutes.add(failedRoute.flipTlsMode());
    }
}
Also used : Route(com.squareup.okhttp.Route) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 4 with Route

use of com.squareup.okhttp.Route in project robovm by robovm.

the class RouteSelector method next.

/**
   * Returns the next route address to attempt.
   *
   * @throws NoSuchElementException if there are no more routes to attempt.
   */
public Connection next(String method) throws IOException {
    // Always prefer pooled connections over new connections.
    for (Connection pooled; (pooled = pool.get(address)) != null; ) {
        if (method.equals("GET") || pooled.isReadable())
            return pooled;
        pooled.close();
    }
    // Compute the next route to attempt.
    if (!hasNextTlsMode()) {
        if (!hasNextInetSocketAddress()) {
            if (!hasNextProxy()) {
                if (!hasNextPostponed()) {
                    throw new NoSuchElementException();
                }
                return new Connection(nextPostponed());
            }
            lastProxy = nextProxy();
            resetNextInetSocketAddress(lastProxy);
        }
        lastInetSocketAddress = nextInetSocketAddress();
        resetNextTlsMode();
    }
    boolean modernTls = nextTlsMode() == TLS_MODE_MODERN;
    Route route = new Route(address, lastProxy, lastInetSocketAddress, modernTls);
    if (routeDatabase.shouldPostpone(route)) {
        postponedRoutes.add(route);
        // tried last.
        return next(method);
    }
    return new Connection(route);
}
Also used : Connection(com.squareup.okhttp.Connection) NoSuchElementException(java.util.NoSuchElementException) Route(com.squareup.okhttp.Route)

Example 5 with Route

use of com.squareup.okhttp.Route in project phonegap-facebook-plugin by Wizcorp.

the class RouteSelector method connectFailed.

/**
   * Clients should invoke this method when they encounter a connectivity
   * failure on a connection returned by this route selector.
   */
public void connectFailed(Connection connection, IOException failure) {
    Route failedRoute = connection.getRoute();
    if (failedRoute.getProxy().type() != Proxy.Type.DIRECT && proxySelector != null) {
        // Tell the proxy selector when we fail to connect on a fresh connection.
        proxySelector.connectFailed(uri, failedRoute.getProxy().address(), failure);
    }
    failedRoutes.add(failedRoute);
    if (!(failure instanceof SSLHandshakeException)) {
        // If the problem was not related to SSL then it will also fail with
        // a different Tls mode therefore we can be proactive about it.
        failedRoutes.add(failedRoute.flipTlsMode());
    }
}
Also used : Route(com.squareup.okhttp.Route) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Aggregations

Route (com.squareup.okhttp.Route)6 Connection (com.squareup.okhttp.Connection)3 NoSuchElementException (java.util.NoSuchElementException)3 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2