From aafecafc4ea56a6099731ab58572e376d27bd9f9 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Wed, 29 Nov 2017 17:31:50 +0100 Subject: [PATCH] SONAR-10060 api/system/info throws clean message when an exception is thrown --- .../sonar/server/platform/ws/InfoAction.java | 17 ++++++++++++----- 1 file 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); } } -- 2.39.5