diff --git a/source/java/org/alfresco/repo/webdav/GetMethod.java b/source/java/org/alfresco/repo/webdav/GetMethod.java index 66c6cab694..ed0a58bb5d 100644 --- a/source/java/org/alfresco/repo/webdav/GetMethod.java +++ b/source/java/org/alfresco/repo/webdav/GetMethod.java @@ -283,7 +283,7 @@ public class GetMethod extends WebDAVMethod break; } t = t.getCause(); - if (t instanceof SocketException) + if (t instanceof SocketException || t.getClass().getSimpleName().equals("ClientAbortException")) { logAsError = false; } diff --git a/source/test-java/org/alfresco/repo/webdav/GetMethodTest.java b/source/test-java/org/alfresco/repo/webdav/GetMethodTest.java index d583a45997..1d2d3b18d0 100644 --- a/source/test-java/org/alfresco/repo/webdav/GetMethodTest.java +++ b/source/test-java/org/alfresco/repo/webdav/GetMethodTest.java @@ -186,4 +186,63 @@ public class GetMethodTest assertNull(e.getCause()); // Avoids logging stacking trace } } + + @Test + public void readByteRangeContentDoesNotLogClientAbortException() throws IOException, WebDAVServerException + { + // getContentService() during range request + when(davHelper.getServiceRegistry()).thenReturn(serviceRegistry); + when(serviceRegistry.getContentService()).thenReturn(contentService); + + req.addHeader("Range", "bytes=500-1500"); + getMethod.parseRequestHeaders(); + IOException caEx = new ClientAbortException(); + IOException ioEx = new IOException("Wrapping the socket exception.", caEx); + + // Somewhere along the line a client disconnect will happen (IOException) + when(resp.getOutputStream()).thenThrow(ioEx); + + try + { + getMethod.readContent(fileInfo, reader); + fail("Exception should have been thrown."); + } + catch(WebDAVServerException e) + { + verify(logger, never()).error(anyString(), same(ioEx)); + verify(logger).debug(anyString(), same(ioEx)); + assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getHttpStatusCode()); + assertNull(e.getCause()); // Avoids logging stacking trace + } + } + + @Test + public void readContentDoesNotLogClientAbortException() throws IOException, WebDAVServerException + { + IOException caEx = new ClientAbortException(); + ContentIOException contentEx = new ContentIOException("Wrapping the socket exception.", caEx); + + // Reader.getContent() will throw a ContentIOException when a client aborts. + doThrow(contentEx).when(reader).getContent(any(OutputStream.class)); + + try + { + getMethod.readContent(fileInfo, reader); + fail("Exception should have been thrown."); + } + catch(WebDAVServerException e) + { + verify(logger, never()).error(anyString(), same(contentEx)); + // Error will only be seen when debugging. + verify(logger).debug(anyString(), same(contentEx)); + assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getHttpStatusCode()); + assertNull(e.getCause()); // Avoids logging stacking trace + } + } + + // Fake ClientAbortException class - to emulate Tomcat's and JBOSS's ClientAbortException. + private static class ClientAbortException extends IOException + { + + } }