APISonar


org.sonar.server.plugins.MimeTypes.JSON

> org > sonar > server > plugins > MimeTypes > JSON
org APIs sonar APIs server APIs plugins APIs MimeTypes APIs JSON APIs

Example 1
private void write409(Response response, RuleKey ruleKey) {
    Rule rule = service.getNonNullByKey(ruleKey);

    Response.Stream stream = response.stream();
    stream.setStatus(409);
    stream.setMediaType(MimeTypes.JSON);
    JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output(), StandardCharsets.UTF_8)).beginObject().name("rule");
    mapping.write(rule, json, null /* TODO replace by SearchOptions immutable constant */);
    json.endObject().close();
  }
Example 2
public void handle(Request request, Response response) throws Exception {
    ProjectRepositories ref = projectReferentialsLoader.load(ProjectRepositoryQuery.create()
      .setModuleKey(request.mandatoryParam(PARAM_KEY))
      .setProfileName(request.param(PARAM_PROFILE))
      .setPreview(request.mandatoryParamAsBoolean(PARAM_PREVIEW)));
    response.stream().setMediaType(MimeTypes.JSON);
    IOUtils.write(ref.toJson(), response.stream().output());
  }
Example 3
public void internal_error() throws Exception {
    ValidatingRequest request = new SimpleRequest("GET");
    ServletResponse response = new ServletResponse();
    engine.execute(request, response, "api/system", "fail");

    assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"Unexpected\"}]}");
    assertThat(response.stream().httpStatus()).isEqualTo(500);
    assertThat(response.stream().mediaType()).isEqualTo(MimeTypes.JSON);
  }