diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/HttpOverSpdyTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/HttpOverSpdyTest.java index ab8f3c97ccea..be9fca2cc89e 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/HttpOverSpdyTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/HttpOverSpdyTest.java @@ -32,6 +32,7 @@ import java.net.Authenticator; import java.net.CookieManager; import java.net.HttpURLConnection; +import java.net.SocketTimeoutException; import java.net.URL; import java.util.Arrays; import java.util.Collections; @@ -307,8 +308,8 @@ protected HttpOverSpdyTest(Protocol protocol){ try { readAscii(connection.getInputStream(), Integer.MAX_VALUE); fail("Should have timed out!"); - } catch (IOException e){ - assertEquals("timeout", e.getMessage()); + } catch (SocketTimeoutException expected) { + assertEquals("timeout", expected.getMessage()); } } diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java index bf22e1501003..bb9a261e63ab 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java @@ -57,6 +57,7 @@ import java.net.ServerSocket; import java.net.Socket; import java.net.SocketAddress; +import java.net.SocketTimeoutException; import java.net.URI; import java.net.URL; import java.net.URLConnection; @@ -2202,7 +2203,7 @@ private void testRedirect(boolean temporary, String method) throws Exception { try { in.read(); // if Content-Length was accurate, this would return -1 immediately fail(); - } catch (IOException expected) { + } catch (SocketTimeoutException expected) { } } @@ -2238,7 +2239,7 @@ protected void configureSocket(Socket socket) throws IOException { byte[] data = new byte[16 * 1024 * 1024]; // 16 MiB. out.write(data); fail(); - } catch (IOException expected) { + } catch (SocketTimeoutException expected) { } } diff --git a/okhttp/src/main/java/com/squareup/okhttp/internal/spdy/SpdyStream.java b/okhttp/src/main/java/com/squareup/okhttp/internal/spdy/SpdyStream.java index 05ce57a96400..1c1f76fddfe1 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/internal/spdy/SpdyStream.java +++ b/okhttp/src/main/java/com/squareup/okhttp/internal/spdy/SpdyStream.java @@ -19,6 +19,7 @@ import java.io.EOFException; import java.io.IOException; import java.io.InterruptedIOException; +import java.net.SocketTimeoutException; import java.util.ArrayList; import java.util.List; import okio.AsyncTimeout; @@ -596,12 +597,21 @@ private void waitForIo() throws InterruptedIOException { * notify the waiting thread. */ class SpdyTimeout extends AsyncTimeout { + @Override protected void timedOut() { closeLater(ErrorCode.CANCEL); } - public void exitAndThrowIfTimedOut() throws InterruptedIOException { - if (exit()) throw new InterruptedIOException("timeout"); + @Override protected IOException newTimeoutException(IOException cause) { + SocketTimeoutException socketTimeoutException = new SocketTimeoutException("timeout"); + if (cause != null) { + socketTimeoutException.initCause(cause); + } + return socketTimeoutException; + } + + public void exitAndThrowIfTimedOut() throws IOException { + if (exit()) throw newTimeoutException(null /* cause */); } } } diff --git a/pom.xml b/pom.xml index 1e84f8807e57..c4629bb404a6 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ 1.7 - 1.4.0 + 1.5.0-SNAPSHOT 7.1.2.v20141202