aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-06-27 14:25:06 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-06-29 08:59:47 +0200
commit6f754683a488d38ae95e3f6143f81a1b8f24b0fb (patch)
tree766a137fe7ff5d84d4e0ed693dc7defc7a56042e
parent2c261abdcead698b11f9f4a09e2c7494ed2d62ee (diff)
downloadsonarqube-6f754683a488d38ae95e3f6143f81a1b8f24b0fb.tar.gz
sonarqube-6f754683a488d38ae95e3f6143f81a1b8f24b0fb.zip
SONAR-8733 no log nor sendError in for ClientAbortException
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/plugins/StaticResourcesServlet.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/plugins/StaticResourcesServletTest.java18
2 files changed, 21 insertions, 1 deletions
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;
@@ -145,6 +147,22 @@ public class StaticResourcesServletTest {
}
@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");
when(componentContainer.getComponentByType(PluginRepository.class)).thenThrow(new RuntimeException("Simulating a error"));