From: Sébastien Lesaint Date: Tue, 27 Jun 2017 12:25:06 +0000 (+0200) Subject: SONAR-8733 no log nor sendError in for ClientAbortException X-Git-Tag: 6.5-M2~75 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F2201%2Fhead;p=sonarqube.git SONAR-8733 no log nor sendError in for ClientAbortException --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java index b27456ab488..70a53afaf9b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java @@ -68,6 +68,8 @@ public class StaticResourcesServlet extends HttpServlet { } else { silentlySendError(response, SC_NOT_FOUND); } + } catch (ClientAbortException e) { + LOG.trace(format("Client canceled loading resource [%s] from plugin [%s]", resource, pluginKey), e); } catch (Exception e) { LOG.error(format("Unable to load resource [%s] from plugin [%s]", resource, pluginKey), e); silentlySendError(response, SC_INTERNAL_SERVER_ERROR); @@ -97,7 +99,7 @@ public class StaticResourcesServlet extends HttpServlet { /** * @return part of request URL after servlet path */ - private String getPluginKeyAndResourcePath(HttpServletRequest request) { + private static String getPluginKeyAndResourcePath(HttpServletRequest request) { return StringUtils.substringAfter(request.getRequestURI(), request.getContextPath() + request.getServletPath() + "/"); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/StaticResourcesServletTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/StaticResourcesServletTest.java index 0fe3f9d10ce..08b8124cacc 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/plugins/StaticResourcesServletTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/StaticResourcesServletTest.java @@ -23,6 +23,7 @@ import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.catalina.connector.ClientAbortException; import org.junit.Rule; import org.junit.Test; import org.sonar.api.Plugin; @@ -35,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -144,6 +146,22 @@ public class StaticResourcesServletTest { when(componentContainer.getComponentByType(PluginRepository.class)).thenReturn(pluginRepository); } + @Test + public void does_not_fail_nor_log_not_attempt_to_send_error_if_ClientAbortException_is_raised() throws ServletException, IOException { + String pluginKey = "myplugin"; + mockRequest(pluginKey, "foo.txt"); + when(pluginRepository.hasPlugin(pluginKey)).thenReturn(true); + when(pluginRepository.getPluginInstance(pluginKey)).thenReturn(new TestPluginA()); + when(componentContainer.getComponentByType(PluginRepository.class)).thenReturn(pluginRepository); + when(response.getOutputStream()).thenThrow(new ClientAbortException("Simulating ClientAbortException")); + + underTest.doGet(request, response); + + assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty(); + assertThat(logTester.logs(LoggerLevel.TRACE)).containsOnly("Client canceled loading resource [static/foo.txt] from plugin [myplugin]"); + verify(response, times(0)).sendError(anyInt()); + } + @Test public void does_not_fail_when_response_is_committed_after_other_error() throws ServletException, IOException { mockRequest("myplugin", "image.png");