]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10154 Use Response.newJsonWriter() to write in WS api/system/info
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 29 Dec 2017 15:08:15 +0000 (16:08 +0100)
committerTeryk Bellahsene <teryk@users.noreply.github.com>
Wed, 3 Jan 2018 09:11:00 +0000 (10:11 +0100)
server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoAction.java
server/sonar-server/src/test/java/org/sonar/server/platform/ws/InfoActionTest.java

index c5fe8cf4a7df7005913888b8b07f4cc1d5bfa0b8..c219b4d9fa3d9de6310fed9c57dc9b512166b7ea 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.Change;
 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.
  */
@@ -44,27 +40,27 @@ public class InfoAction implements SystemWsAction {
 
   @Override
   public void define(WebService.NewController controller) {
-    controller.createAction("info")
+    WebService.NewAction action = controller.createAction("info")
       .setDescription("Get detailed information about system configuration.<br/>" +
-        "Requires 'Administer' permissions.<br/>" +
-        "Since 5.5, this web service becomes internal in order to more easily update result.")
+        "Requires 'Administer' permissions.")
       .setSince("5.1")
       .setInternal(true)
-      .setResponseExample(getClass().getResource("/org/sonar/server/platform/ws/info-example.json"))
+      .setResponseExample(getClass().getResource("info-example.json"))
       .setHandler(this);
 
+    action.setChangelog(
+      new Change("5.5", "Becomes internal to easily update result")
+    );
   }
 
   @Override
   public void handle(Request request, Response response) throws Exception {
     userSession.checkIsSystemAdministrator();
-    StringWriter stringWriter = new StringWriter();
-    JsonWriter json = JsonWriter.of(stringWriter);
+    JsonWriter json = response.newJsonWriter();
     json.beginObject();
     systemInfoWriter.write(json);
     json.endObject();
-    response.stream().setMediaType(JSON);
-    IOUtils.write(stringWriter.toString(), response.stream().output(), StandardCharsets.UTF_8);
+    json.close();
   }
 
 }
index 9d3b0c4d00d4d20bfda40a5adb3d1976efc39a33..99ed6b79f95aae4b016b357cdd037813b21220c0 100644 (file)
@@ -40,7 +40,7 @@ public class InfoActionTest {
 
   private SystemInfoWriter jsonWriter = new SystemInfoWriter(null) {
     @Override
-    public void write(JsonWriter json) throws Exception {
+    public void write(JsonWriter json) {
       json.prop("key", "value");
     }
   };
@@ -48,7 +48,7 @@ public class InfoActionTest {
   private WsActionTester ws = new WsActionTester(underTest);
 
   @Test
-  public void test_definition() throws Exception {
+  public void test_definition() {
     assertThat(ws.getDef().key()).isEqualTo("info");
     assertThat(ws.getDef().isInternal()).isTrue();
     assertThat(ws.getDef().responseExampleAsString()).isNotEmpty();