### Eclipse Workspace Patch 1.0 #P httpclient-cache Index: src/main/java/org/apache/http/impl/client/cache/CachingExec.java =================================================================== --- src/main/java/org/apache/http/impl/client/cache/CachingExec.java (revision 1422900) +++ src/main/java/org/apache/http/impl/client/cache/CachingExec.java (working copy) @@ -804,8 +804,6 @@ try { return Proxies.enhanceResponse(responseCache.cacheAndReturnResponse( target, request, backendResponse, requestDate, responseDate)); - } catch (IOException ioe) { - log.warn("Unable to store entries in cache", ioe); } finally { backendResponse.close(); } Index: src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java =================================================================== --- src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java (revision 1422900) +++ src/test/java/org/apache/http/impl/client/cache/TestCachingExec.java (working copy) @@ -43,11 +43,15 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.io.InputStream; +import java.net.SocketException; +import java.net.SocketTimeoutException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; import org.apache.http.Header; import org.apache.http.HttpHost; @@ -69,11 +73,13 @@ import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.conn.routing.HttpRoute; +import org.apache.http.entity.InputStreamEntity; import org.apache.http.impl.client.execchain.ClientExecChain; import org.apache.http.impl.cookie.DateUtils; import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHttpRequest; import org.apache.http.message.BasicHttpResponse; +import org.apache.http.util.EntityUtils; import org.easymock.Capture; import org.easymock.IExpectationSetters; import org.easymock.classextension.EasyMock; @@ -1347,6 +1353,50 @@ } + @Test + public void testSocketTimeoutExceptionIsNotSilentlyCatched() + throws Exception { + impl = new CachingExec(mockBackend, new BasicHttpCache(), + CacheConfig.DEFAULT); + Date now = new Date(); + + HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new HttpGet( + "http://foo.example.com")); + + final AtomicBoolean inputStreamIsClosed = new AtomicBoolean(false); + + HttpResponse resp1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, + HttpStatus.SC_OK, "OK"); + resp1.setEntity(new InputStreamEntity(new InputStream() { + private boolean closed = false; + + @Override + public void close() throws IOException { + closed = true; + } + + @Override + public int read() throws IOException { + if (closed) + throw new SocketException("Socket closed"); + throw new SocketTimeoutException("Read timed out"); + } + }, 128)); + resp1.setHeader("Date", DateUtils.formatDate(now)); + + backendExpectsAnyRequestAndReturn(resp1); + + replayMocks(); + try { + HttpResponse result1 = impl.execute(route, req1); + EntityUtils.toString(result1.getEntity()); + Assert.fail("We should have had a SocketTimeoutException"); + } catch (SocketTimeoutException e) { + } + verifyMocks(); + + } + @Test public void testIsSharedCache() { Assert.assertTrue(config.isSharedCache()); @@ -1372,7 +1422,7 @@ expect(mockCache.cacheAndReturnResponse(same(host), isA(HttpRequest.class), isA(HttpResponse.class), isA(Date.class), isA(Date.class))) - .andThrow(new IOException()).anyTimes(); + .andReturn(resp).anyTimes(); expect(mockBackend.execute( same(route), isA(HttpRequestWrapper.class),