*/
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.
*/
@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();
}
}
private SystemInfoWriter jsonWriter = new SystemInfoWriter(null) {
@Override
- public void write(JsonWriter json) throws Exception {
+ public void write(JsonWriter json) {
json.prop("key", "value");
}
};
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();