aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-11-29 17:31:50 +0100
committerTeryk Bellahsene <teryk@users.noreply.github.com>2017-11-30 16:28:43 +0100
commitaafecafc4ea56a6099731ab58572e376d27bd9f9 (patch)
tree83649c4623ba4e0978ba9db7beb4574b38bd43d7
parent44b3ae596e9f6298b02610589f5ea00f87f73139 (diff)
downloadsonarqube-aafecafc4ea56a6099731ab58572e376d27bd9f9.tar.gz
sonarqube-aafecafc4ea56a6099731ab58572e376d27bd9f9.zip
SONAR-10060 api/system/info throws clean message when an exception is thrown
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoAction.java17
1 files changed, 12 insertions, 5 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoAction.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoAction.java
index 177d26965c1..c5fe8cf4a7d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoAction.java
@@ -19,12 +19,17 @@
*/
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);
}
}