]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8733 no log nor sendError in for ClientAbortException 2201/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 27 Jun 2017 12:25:06 +0000 (14:25 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 29 Jun 2017 06:59:47 +0000 (08:59 +0200)
server/sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java
server/sonar-server/src/test/java/org/sonar/server/plugins/StaticResourcesServletTest.java

index b27456ab48872844f73d09a6f1c3bf6ce0e6cbfd..70a53afaf9ba501591156c07427f6641aa594470 100644 (file)
@@ -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() + "/");
   }
 
index 0fe3f9d10ce5d9cb38134ec9c41136808643090e..08b8124cacc64f7b8a610edbc9676340cc5f82b9 100644 (file)
@@ -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");