diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-09-15 15:55:41 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-09-16 15:15:30 +0200 |
commit | 2c0518b380ddb1933cb16d51bb943965da834ed1 (patch) | |
tree | 8d6147552e7e5dfd6856555e542cc5527ad3cab3 /server | |
parent | 777d3a179ecc4900883a699fd13c4b528509ccb2 (diff) | |
download | sonarqube-2c0518b380ddb1933cb16d51bb943965da834ed1.tar.gz sonarqube-2c0518b380ddb1933cb16d51bb943965da834ed1.zip |
SONAR-8035 Do not display error in logs when web request is aborted
Diffstat (limited to 'server')
4 files changed, 10 insertions, 12 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/ws/WebServiceEngine.java b/server/sonar-server/src/main/java/org/sonar/server/ws/WebServiceEngine.java index a203464e20c..3f9a1f3d81a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ws/WebServiceEngine.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ws/WebServiceEngine.java @@ -117,7 +117,7 @@ public class WebServiceEngine implements LocalConnector, Startable { Throwable cause = e.getCause(); if (cause != null && cause instanceof ClientAbortException) { // Request has been aborted by the client, nothing can been done as Tomcat has committed the response - LOGGER.warn("Request {} has been aborted by client, error is '{}'", request, e.getMessage()); + LOGGER.debug("Request {} has been aborted by client, error is '{}'", request, e.getMessage()); return; } LOGGER.error("Fail to process request " + request, e); diff --git a/server/sonar-server/src/main/java/org/sonar/server/ws/WsUtils.java b/server/sonar-server/src/main/java/org/sonar/server/ws/WsUtils.java index 6ee8781adba..67f80278334 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ws/WsUtils.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ws/WsUtils.java @@ -20,7 +20,6 @@ package org.sonar.server.ws; import com.google.common.base.Optional; -import com.google.common.base.Throwables; import com.google.protobuf.Message; import java.io.OutputStream; import java.io.OutputStreamWriter; @@ -60,8 +59,7 @@ public class WsUtils { } } } catch (Exception e) { - LOG.error("Error while writing protobuf message {}", MessageFormatter.print(msg)); - Throwables.propagate(e); + throw new IllegalStateException(format("Error while writing protobuf message %s", MessageFormatter.print(msg)), e); } finally { IOUtils.closeQuietly(output); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/ws/WebServiceEngineTest.java b/server/sonar-server/src/test/java/org/sonar/server/ws/WebServiceEngineTest.java index d8937cfa2da..4145340826b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ws/WebServiceEngineTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ws/WebServiceEngineTest.java @@ -295,7 +295,7 @@ public class WebServiceEngineTest { underTest.execute(request, response); assertThat(response.stream().outputAsString()).isEmpty(); - assertThat(logTester.logs(LoggerLevel.WARN)).isNotEmpty(); + assertThat(logTester.logs(LoggerLevel.DEBUG)).isNotEmpty(); } static class SystemWs implements WebService { diff --git a/server/sonar-server/src/test/java/org/sonar/server/ws/WsUtilsTest.java b/server/sonar-server/src/test/java/org/sonar/server/ws/WsUtilsTest.java index 9bc26875551..a0a1af4db0d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ws/WsUtilsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ws/WsUtilsTest.java @@ -30,11 +30,13 @@ import org.sonarqube.ws.MediaTypes; import org.sonarqube.ws.WsPermissions; import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.test.ExceptionCauseMatcher.hasType; public class WsUtilsTest { @Rule public ExpectedException expectedException = ExpectedException.none(); + @Rule public LogTester logger = new LogTester(); @@ -73,13 +75,11 @@ public class WsUtilsTest { WsPermissions.Permission message = WsPermissions.Permission.newBuilder().setName("permission-name").build(); - try { - // provoke NullPointerException - WsUtils.writeProtobuf(message, null, new DumbResponse()); - } catch (Exception e) { - assertThat(e).isInstanceOf(NullPointerException.class); - assertThat(logger.logs()).contains("Error while writing protobuf message org.sonarqube.ws.WsPermissions.Permission[name: \"permission-name\"]"); - } + expectedException.expect(IllegalStateException.class); + expectedException.expectCause(hasType(NullPointerException.class)); + expectedException.expectMessage("Error while writing protobuf message org.sonarqube.ws.WsPermissions.Permission[name: \"permission-name\"]"); + // provoke NullPointerException + WsUtils.writeProtobuf(message, null, new DumbResponse()); } @Test |