use of net.sf.json.JSONArray in project promoted-builds-plugin by jenkinsci.
the class ManualCondition method doApprove.
/**
* Web method to handle the approval action submitted by the user.
*/
public void doApprove(StaplerRequest req, StaplerResponse rsp, @AncestorInPath PromotionProcess promotionProcess, @AncestorInPath AbstractBuild<?, ?> build) throws IOException, ServletException {
JSONObject formData = req.getSubmittedForm();
if (canApprove(promotionProcess, build)) {
List<ParameterValue> paramValues = new ArrayList<ParameterValue>();
if (parameterDefinitions != null && !parameterDefinitions.isEmpty()) {
JSONArray a = JSONArray.fromObject(formData.get("parameter"));
for (Object o : a) {
JSONObject jo = (JSONObject) o;
String name = jo.getString("name");
ParameterDefinition d = getParameterDefinition(name);
if (d == null)
throw new IllegalArgumentException("No such parameter definition: " + name);
paramValues.add(d.createValue(req, jo));
}
}
approve(build, promotionProcess, paramValues);
}
rsp.sendRedirect2("../../../..");
}
use of net.sf.json.JSONArray in project cobar by alibaba.
the class CobarNodeInstantPerfValueAjax method handleRequest.
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
AjaxParams params = new AjaxParams(request);
CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(params.getCobarNodeId());
JSONArray array = null;
String jsonRst = null;
String st = params.getValueType();
if (null == st || st.equals("")) {
throw new IllegalArgumentException("parameter 'cobarControlValueType' is unknown: " + st);
}
int type = typeMap.get(st);
switch(type) {
case TYPE_SERVER_STATUS:
jsonRst = JSONObject.fromObject(getServerStatus(params)).toString(2);
break;
case TYPE_PROCESSOR_STATUS:
List<Map<String, Object>> listProcessor = listProcessorStatus(params);
array = JSONArray.fromObject(listProcessor);
jsonRst = array.toString(2);
break;
case TYPE_THREAD_POOL:
List<Map<String, Object>> listThreadpool = listThreadPool(params);
array = JSONArray.fromObject(listThreadpool);
jsonRst = array.toString(2);
break;
case TYPE_COMMAND:
List<Map<String, Object>> listCommand = listCommand(params);
array = JSONArray.fromObject(listCommand);
jsonRst = array.toString(2);
break;
case TYPE_DATANODES:
List<Map<String, Object>> listDatanode = listDatanode(params);
array = JSONArray.fromObject(listDatanode);
jsonRst = array.toString(2);
break;
case TYPE_DATABASES:
List<String> listDatabase = null;
if (perfAccesser.checkConnection()) {
listDatabase = perfAccesser.listDataBases();
}
array = JSONArray.fromObject(listDatabase);
jsonRst = array.toString(2);
break;
case TYPE_DATASOURCES:
List<DataSources> listDatasource = null;
if (perfAccesser.checkConnection()) {
listDatasource = perfAccesser.listDataSources();
}
array = JSONArray.fromObject(listDatasource);
jsonRst = array.toString(2);
break;
case TYPE_CONNECTION:
List<Map<String, Object>> listConnection = listConnection(params);
array = JSONArray.fromObject(listConnection);
jsonRst = array.toString(2);
break;
default:
throw new IllegalArgumentException("parameter 'cobarNodeInstantPerfValueType' is known: " + params.getValueType());
}
perfAccesser = null;
response.setHeader("Content-Type", "text/json; charset=utf-8");
OutputStream out = response.getOutputStream();
out.write(jsonRst.getBytes("utf-8"));
out.flush();
}
use of net.sf.json.JSONArray in project cobar by alibaba.
the class ClusterInstantPerfValueAjax method handleRequest.
@SuppressWarnings("unchecked")
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
AjaxParams params = new AjaxParams(request);
String jsonRst = null;
String st = params.getValueType();
if (null == st || st.equals("")) {
throw new IllegalArgumentException("parameter 'cobarControlValueType' is unknown: " + st);
}
int type = valueTypeMap.get(st);
PropertyUtilsBean util = new PropertyUtilsBean();
switch(type) {
case TYPE_COBAR_MEMORY_USAGE:
List<Pair<Long, Integer>> mList = listCobarMemoryUsage(params);
JSONArray mArray = JSONArray.fromObject(mList);
jsonRst = mArray.toString(2);
break;
case TYPE_CLUSTER_THROUGHPUT_INFO:
List<Map<String, Object>> list1 = getClusterThroughput(params);
JSONArray arrayMap = JSONArray.fromObject(list1);
jsonRst = arrayMap.toString(2);
break;
case TYPE_CLUSTER_INFO:
AjaxResult rs = getClusterInfo(params);
Map<String, Object> map = null;
try {
map = util.describe(rs);
} catch (Exception e) {
logger.error(e);
throw new RuntimeException(e);
}
jsonRst = JSONObject.fromObject(map).toString(2);
break;
case TYPE_STATUS:
List<Pair<Long, String>> sList = getStatus(params);
JSONArray sArray = JSONArray.fromObject(sList);
jsonRst = sArray.toString(2);
break;
default:
throw new IllegalArgumentException("parameter 'ValueType' is known: " + params.getValueType());
}
response.setHeader("Content-Type", "text/json; charset=utf-8");
OutputStream out = response.getOutputStream();
out.write(jsonRst.getBytes("utf-8"));
out.flush();
}
use of net.sf.json.JSONArray in project cobar by alibaba.
the class CobarControlAjax method handleRequest.
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
AjaxParams params = new AjaxParams(request);
JSONArray array = null;
String jsonRst = null;
String st = params.getValueType();
if (null == st || st.equals("")) {
throw new IllegalArgumentException("parameter 'cobarControlValueType' is unknown: " + st);
}
int type = typeMap.get(st);
switch(type) {
case COBAR_LIST:
List<Map<String, Object>> cobarList = getCobarList(params);
array = JSONArray.fromObject(cobarList);
jsonRst = array.toString(2);
break;
case KILL_CONNECTION:
Pair<String, Boolean> kill = new Pair<String, Boolean>("result", killConnections(params));
jsonRst = JSONObject.fromObject(kill).toString(2);
break;
default:
throw new IllegalArgumentException("parameter 'cobarControlValueType' is unknown: " + params.getValueType());
}
response.setHeader("Content-Type", "text/json; charset=utf-8");
OutputStream out = response.getOutputStream();
out.write(jsonRst.getBytes("utf-8"));
out.flush();
}
use of net.sf.json.JSONArray in project pinpoint by naver.
the class JsonLibJSONArrayIT method arrayToJsonTest.
@Test
public void arrayToJsonTest() throws Exception {
Method fromObject = JSONArray.class.getMethod("fromObject", Object.class);
Method toString = JSONArray.class.getMethod("toString");
JSONArray jsonArray = JSONArray.fromObject(new Object[] { "pinpoint", "json-lib" });
String json = jsonArray.toString();
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
verifier.verifyTrace(event(SERVICE_TYPE, fromObject));
verifier.verifyTrace(event(SERVICE_TYPE, toString, Expectations.annotation(ANNOTATION_KEY, json.length())));
verifier.verifyTraceCount(0);
}
Aggregations