]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10060 api/system/info throws clean message when an exception is thrown
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 29 Nov 2017 16:31:50 +0000 (17:31 +0100)
committerTeryk Bellahsene <teryk@users.noreply.github.com>
Thu, 30 Nov 2017 15:28:43 +0000 (16:28 +0100)
server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoAction.java

index 177d26965c121a9ab7c9a7dbae4c0140c5c0a2f1..c5fe8cf4a7df7005913888b8b07f4cc1d5bfa0b8 100644 (file)
  */
 package org.sonar.server.platform.ws;
 
+import java.io.StringWriter;
+import java.nio.charset.StandardCharsets;
+import org.apache.commons.io.IOUtils;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.server.user.UserSession;
 
+import static org.sonarqube.ws.MediaTypes.JSON;
+
 /**
  * Implementation of the {@code info} action for the System WebService.
  */
@@ -53,11 +58,13 @@ public class InfoAction implements SystemWsAction {
   @Override
   public void handle(Request request, Response response) throws Exception {
     userSession.checkIsSystemAdministrator();
-    try (JsonWriter json = response.newJsonWriter()) {
-      json.beginObject();
-      systemInfoWriter.write(json);
-      json.endObject();
-    }
+    StringWriter stringWriter = new StringWriter();
+    JsonWriter json = JsonWriter.of(stringWriter);
+    json.beginObject();
+    systemInfoWriter.write(json);
+    json.endObject();
+    response.stream().setMediaType(JSON);
+    IOUtils.write(stringWriter.toString(), response.stream().output(), StandardCharsets.UTF_8);
   }
 
 }