Example usage for java.net SocketException initCause

List of usage examples for java.net SocketException initCause

Introduction

In this page you can find the example usage for java.net SocketException initCause.

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:org.lockss.plugin.silverchair.PostHttpClientUrlConnection.java

private int executeOnce(HttpMethod method) throws IOException {
    try {/*from w  ww  .  j  a  v  a2s .c om*/
        return client.executeMethod(method);
    } catch (ConnectTimeoutException /*| java.net.SocketTimeoutException*/ e) {
        // Thrown by HttpClient if the connect timeout elapses before
        // socket.connect() returns.
        // Turn this into a non HttpClient-specific exception
        throw new ConnectionTimeoutException("Host did not respond", e);
        // XXX If socket.connect() returns an error because the underlying
        // socket connect times out, the behavior is platform dependent.  On
        // Linux, java.net.ConnectException is thrown (same as for connection
        // refused, and distunguishable only by the exception message).  On
        // OpenBSD, java.net.SocketException is thrown with a message like
        // "errno: 22, error: Invalid argument for fd: 3".  In lieu of a way
        // to reliably determine when to turn these into a
        // ConnectionTimeoutException, the solution for now is to use
        // java-level connect timeouts that are shorter than the underlying
        // socket connect timeout.
    } catch (NoHttpResponseException e) {
        // Thrown by HttpClient if the server closes the connection before
        // sending a response.
        // Turn this into a non HttpClient-specific exception
        java.net.SocketException se = new java.net.SocketException("Connection reset by peer");
        se.initCause(e);
        throw se;
    }
}

From source file:org.lockss.util.urlconn.HttpClientUrlConnection.java

private int executeOnce(HttpMethod method) throws IOException {
    try {/*from www .j a v  a 2  s. co m*/
        return client.executeMethod(method);
    } catch (ConnectTimeoutException e) {
        // Thrown by HttpClient if the connect timeout elapses before
        // socket.connect() returns.
        // Turn this into a non HttpClient-specific exception
        throw new ConnectionTimeoutException("Host did not respond", e);
        // XXX If socket.connect() returns an error because the underlying
        // socket connect times out, the behavior is platform dependent.  On
        // Linux, java.net.ConnectException is thrown (same as for connection
        // refused, and distunguishable only by the exception message).  On
        // OpenBSD, java.net.SocketException is thrown with a message like
        // "errno: 22, error: Invalid argument for fd: 3".  In lieu of a way
        // to reliably determine when to turn these into a
        // ConnectionTimeoutException, the solution for now is to use
        // java-level connect timeouts that are shorter than the underlying
        // socket connect timeout.
    } catch (NoHttpResponseException e) {
        // Thrown by HttpClient if the server closes the connection before
        // sending a response.
        // Turn this into a non HttpClient-specific exception
        java.net.SocketException se = new java.net.SocketException("Connection reset by peer");
        se.initCause(e);
        throw se;
    }
}