use of net.sf.json.JSONArray in project hudson-2.x by hudson.
the class JSONTest method testCanonicalWriter.
public void testCanonicalWriter() throws IOException {
JSONArray jsonArray = new JSONArray();
jsonArray.add(true);
jsonArray.add(1);
jsonArray.add(5.3);
JSONObject jsonObject = new JSONObject();
jsonObject.put("key1", "1");
jsonObject.put("key2", "2");
jsonObject.put("key3", "3");
jsonObject.put("string", "123\r\n\b\t\f\\\\u65E5\\u672C\\u8A9E");
jsonArray.add(jsonObject);
Writer writer = new StringWriter();
JSONCanonicalUtils.write(jsonArray, writer);
assertEquals(writer.toString(), "[true,1,5.3,{\"key1\":\"1\",\"key2\":\"2\",\"key3\":\"3\",\"string\":\"123\\u000d\\u000a\\u0008\\u0009\\u000c\\\\\\\\u65E5\\\\u672C\\\\u8A9E\"}]");
}
use of net.sf.json.JSONArray in project blueocean-plugin by jenkinsci.
the class HttpResponse method getContent.
@CheckForNull
public InputStream getContent() {
try {
HttpEntity entity = response.getEntity();
if (getStatus() >= 300) {
ErrorMessage errorMessage = new ErrorMessage(getStatus(), getStatusLine());
// WireMock returns "Bad Request" for the status message; it's also pretty nondescript
if (StringUtils.isEmpty(errorMessage.message) || "Bad Request".equals(errorMessage.message)) {
String message;
List<ErrorMessage.Error> errors = new ArrayList<>();
try {
JSONObject jsonResponse = JSONObject.fromObject(IOUtils.toString(entity.getContent()));
JSONArray arr = jsonResponse.getJSONArray("errors");
StringBuilder messageBuilder = new StringBuilder();
for (int i = 0; i < arr.size(); i++) {
JSONObject err = arr.getJSONObject(i);
if (i > 0) {
messageBuilder.append(", ");
}
messageBuilder.append(err.getString("message"));
StringBuilder details = new StringBuilder();
if (err.has("details")) {
JSONArray errorDetails = err.getJSONArray("details");
for (int detailIdx = 0; detailIdx < errorDetails.size(); detailIdx++) {
details.append(errorDetails.getString(detailIdx)).append("\n");
}
} else {
details.append("no error details");
}
errors.add(new ErrorMessage.Error("", err.getString("exceptionName"), details.toString()));
}
message = messageBuilder.toString();
} catch (Exception e) {
logger.error("An error occurred getting BitBucket API error content", e);
message = "An unknown error was reported from the BitBucket server";
}
errorMessage = new ErrorMessage(getStatus(), message).addAll(errors);
} else {
EntityUtils.consume(entity);
}
throw new ServiceException(getStatus(), errorMessage, null);
}
return entity == null ? null : entity.getContent();
} catch (IOException e) {
throw new ServiceException.UnexpectedErrorException(e.getMessage(), e);
}
}
use of net.sf.json.JSONArray in project blueocean-plugin by jenkinsci.
the class JenkinsJSExtensions method getExtensionsData.
/**
* Return the actual data, from /js-extensions
*/
public static JSONArray getExtensionsData() {
Object jsExtensionData = getJenkinsJSExtensionData();
JSONArray jsExtensionDataJson = JSONArray.fromObject(jsExtensionData);
return jsExtensionDataJson;
}
use of net.sf.json.JSONArray in project blueocean-plugin by jenkinsci.
the class SSEConnection method toJSONArray.
private JSONArray toJSONArray(Collection<EventFilter> filters) {
JSONArray a = new JSONArray();
for (EventFilter f : filters) {
JSONObject o = new JSONObject();
o.putAll(f);
a.add(o);
}
return a;
}
use of net.sf.json.JSONArray in project cachecloud by sohutv.
the class AppController method assembleJson.
private String assembleJson(List<AppCommandStats> appCommandStatsList, Integer addDay) {
if (appCommandStatsList == null || appCommandStatsList.isEmpty()) {
return "[]";
}
List<SimpleChartData> list = new ArrayList<SimpleChartData>();
for (AppCommandStats stat : appCommandStatsList) {
try {
SimpleChartData chartData = SimpleChartData.getFromAppCommandStats(stat, addDay);
list.add(chartData);
} catch (ParseException e) {
logger.info(e.getMessage(), e);
}
}
JSONArray jsonArray = JSONArray.fromObject(list);
return jsonArray.toString();
}
Aggregations