From ff2080895e028b5db95cffb2059b43f3bc4648ef Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Tue, 11 Feb 2014 22:21:05 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud) 57866: Merged V4.2-BUG-FIX (4.2.1) to HEAD-BUG-FIX (Cloud/4.3) 57858: Merged V4.1-BUG-FIX (4.1.8) to V4.2-BUG-FIX (4.2.1) 57816: Merged DEV to V4.1-BUG-FIX (4.1.8) 57643: MNT-8989: MP4 and mov accessed over WebDav on safari or Chrome cause exceptions in log Added ClientAbortException check. Added unit tests. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@61899 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/repo/webdav/GetMethod.java | 2 +- .../alfresco/repo/webdav/GetMethodTest.java | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) 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 + { + + } }