} 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);
/**
* @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() + "/");
}
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;
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;
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");