]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8035 Do not display error in logs when web request is aborted
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 15 Sep 2016 13:55:41 +0000 (15:55 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 16 Sep 2016 13:15:30 +0000 (15:15 +0200)
server/sonar-server/src/main/java/org/sonar/server/ws/WebServiceEngine.java
server/sonar-server/src/main/java/org/sonar/server/ws/WsUtils.java
server/sonar-server/src/test/java/org/sonar/server/ws/WebServiceEngineTest.java
server/sonar-server/src/test/java/org/sonar/server/ws/WsUtilsTest.java

index a203464e20cc935235757a6d4bf43fc50db68650..3f9a1f3d81a8fb9bd58c3c9954359c55a7329810 100644 (file)
@@ -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);
index 6ee8781adbae616c4c3a621139364523852d4271..67f80278334d0cb6c1caa518084d7db25c955ef8 100644 (file)
@@ -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);
     }
index d8937cfa2da6ae85603ae12e4d5b2164bfed8e1d..4145340826b833e3403103a819aeb129bc72d566 100644 (file)
@@ -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 {
index 9bc26875551bf67d2c839b77663bb8557fc209e7..a0a1af4db0d7a94336a96a0ef2a7e9643bf3d8c8 100644 (file)
@@ -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