Search in sources :

Example 41 with SocketTimeoutException

use of java.net.SocketTimeoutException in project hadoop by apache.

the class TestIPC method testIpcTimeout.

@Test(timeout = 60000)
public void testIpcTimeout() throws IOException {
    // start server
    Server server = new TestServer(1, true);
    InetSocketAddress addr = NetUtils.getConnectAddress(server);
    server.start();
    // start client
    Client client = new Client(LongWritable.class, conf);
    // set timeout to be less than MIN_SLEEP_TIME
    try {
        call(client, new LongWritable(RANDOM.nextLong()), addr, MIN_SLEEP_TIME / 2, conf);
        fail("Expected an exception to have been thrown");
    } catch (SocketTimeoutException e) {
        LOG.info("Get a SocketTimeoutException ", e);
    }
    // set timeout to be bigger than 3*ping interval
    call(client, new LongWritable(RANDOM.nextLong()), addr, 3 * PING_INTERVAL + MIN_SLEEP_TIME, conf);
    client.stop();
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) InetSocketAddress(java.net.InetSocketAddress) LongWritable(org.apache.hadoop.io.LongWritable) Test(org.junit.Test)

Example 42 with SocketTimeoutException

use of java.net.SocketTimeoutException in project hadoop by apache.

the class KMSClientProvider method createConnection.

private HttpURLConnection createConnection(final URL url, String method) throws IOException {
    HttpURLConnection conn;
    try {
        final String doAsUser = getDoAsUser();
        conn = getActualUgi().doAs(new PrivilegedExceptionAction<HttpURLConnection>() {

            @Override
            public HttpURLConnection run() throws Exception {
                DelegationTokenAuthenticatedURL authUrl = new DelegationTokenAuthenticatedURL(configurator);
                return authUrl.openConnection(url, authToken, doAsUser);
            }
        });
    } catch (IOException ex) {
        if (ex instanceof SocketTimeoutException) {
            LOG.warn("Failed to connect to {}:{}", url.getHost(), url.getPort());
        }
        throw ex;
    } catch (UndeclaredThrowableException ex) {
        throw new IOException(ex.getUndeclaredThrowable());
    } catch (Exception ex) {
        throw new IOException(ex);
    }
    conn.setUseCaches(false);
    conn.setRequestMethod(method);
    if (method.equals(HTTP_POST) || method.equals(HTTP_PUT)) {
        conn.setDoOutput(true);
    }
    conn = configureConnection(conn);
    return conn;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) SocketTimeoutException(java.net.SocketTimeoutException) DelegationTokenAuthenticatedURL(org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) URISyntaxException(java.net.URISyntaxException) GeneralSecurityException(java.security.GeneralSecurityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SocketTimeoutException(java.net.SocketTimeoutException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ExecutionException(java.util.concurrent.ExecutionException)

Example 43 with SocketTimeoutException

use of java.net.SocketTimeoutException in project camel by apache.

the class CxfTimeoutTest method sendTimeOutMessage.

protected void sendTimeOutMessage(String endpointUri) throws Exception {
    Exchange reply = sendJaxWsMessage(endpointUri);
    Exception e = reply.getException();
    assertNotNull("We should get the exception cause here", e);
    assertTrue("We should get the socket time out exception here", e instanceof SocketTimeoutException);
}
Also used : Exchange(org.apache.camel.Exchange) SocketTimeoutException(java.net.SocketTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException)

Example 44 with SocketTimeoutException

use of java.net.SocketTimeoutException in project camel by apache.

the class CxfMessageHeaderTimeoutTest method sendTimeOutMessage.

protected void sendTimeOutMessage(String endpointUri) throws Exception {
    Exchange reply = sendJaxWsMessage(endpointUri);
    Exception e = reply.getException();
    assertNotNull("We should get the exception cause here", e);
    assertTrue("We should get the socket time out exception here", e instanceof SocketTimeoutException);
}
Also used : Exchange(org.apache.camel.Exchange) SocketTimeoutException(java.net.SocketTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException)

Example 45 with SocketTimeoutException

use of java.net.SocketTimeoutException in project robovm by robovm.

the class PlainSocketFactory method connectSocket.

// non-javadoc, see interface org.apache.http.conn.SocketFactory
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOException {
    if (host == null) {
        throw new IllegalArgumentException("Target host may not be null.");
    }
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null.");
    }
    if (sock == null)
        sock = createSocket();
    if ((localAddress != null) || (localPort > 0)) {
        // we need to bind explicitly
        if (localPort < 0)
            // indicates "any"
            localPort = 0;
        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sock.bind(isa);
    }
    int timeout = HttpConnectionParams.getConnectionTimeout(params);
    InetSocketAddress remoteAddress;
    if (this.nameResolver != null) {
        remoteAddress = new InetSocketAddress(this.nameResolver.resolve(host), port);
    } else {
        remoteAddress = new InetSocketAddress(host, port);
    }
    try {
        sock.connect(remoteAddress, timeout);
    } catch (SocketTimeoutException ex) {
        throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
    }
    return sock;
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) InetSocketAddress(java.net.InetSocketAddress) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Aggregations

SocketTimeoutException (java.net.SocketTimeoutException)389 IOException (java.io.IOException)211 Test (org.junit.Test)95 SocketException (java.net.SocketException)53 Socket (java.net.Socket)52 InputStream (java.io.InputStream)46 ServerSocket (java.net.ServerSocket)43 InetSocketAddress (java.net.InetSocketAddress)39 UnknownHostException (java.net.UnknownHostException)37 ConnectException (java.net.ConnectException)36 MalformedURLException (java.net.MalformedURLException)30 URL (java.net.URL)30 OutputStream (java.io.OutputStream)27 DatagramPacket (java.net.DatagramPacket)25 HttpURLConnection (java.net.HttpURLConnection)25 ArrayList (java.util.ArrayList)23 File (java.io.File)22 HashMap (java.util.HashMap)22 InterruptedIOException (java.io.InterruptedIOException)21 EOFException (java.io.EOFException)19