List of usage examples for org.json.simple JSONObject toJSONString
public String toJSONString()
From source file:cn.vlabs.duckling.vwb.PromitionLogFilter.java
private void logAccessJson(String referer, String referHost, String referHostName, String requestUrl) { JSONObject obj = new JSONObject(); obj.put("type", "access"); obj.put("referHost", referHost); obj.put("referHostName", referHostName); obj.put("referer", referer); obj.put("requestUrl", requestUrl); obj.put("logDate", formatData2String(new Date(), "yyyy-MM-dd HH:mm:ss")); log.info(obj.toJSONString()); }
From source file:com.fujitsu.dc.core.rs.box.BoxResource.java
/** * GET ?? ./*from ww w .j ava 2 s . com*/ * @return JAX-RS Response */ @GET public Response get() { // this.davRsCmp.checkAccessContext(this.davRsCmp.getAccessContext(), BoxPrivilege.READ); // ?box??????? // ???null?????????box???????? // ??????????? String key = "box-" + this.box.getId(); Progress progress = ProgressManager.getProgress(key); if (progress == null) { JSONObject response = createNotRequestedResponse(); return Response.ok().entity(response.toJSONString()).build(); } String jsonString = progress.getValue(); JSONObject jsonObj = null; try { jsonObj = (JSONObject) (new JSONParser()).parse(jsonString); } catch (ParseException e) { throw DcCoreException.Server.DATA_STORE_UNKNOWN_ERROR.reason(e); } // ????????box???????? JSONObject barInfo = (JSONObject) jsonObj.get("barInfo"); if (barInfo == null) { log.info("cache(" + key + "): process" + (String) jsonObj.get("process")); JSONObject response = createNotRequestedResponse(); return Response.ok().entity(response.toJSONString()).build(); } // box??????????? JSONObject response = createResponse(barInfo); return Response.ok().entity(response.toJSONString()).build(); }
From source file:gov.nasa.jpl.memex.pooledtimeseries.PoT.java
private static void writeSimilarityToJSONFile(ArrayList<Path> files, double[][] similarities) { JSONObject root_json_obj = new JSONObject(); for (int i = 0; i < similarities.length; i++) { JSONObject fileJsonObj = new JSONObject(); for (int j = 0; j < similarities[0].length; j++) { fileJsonObj.put(files.get(j).getFileName(), similarities[i][j]); }//from w ww . j a v a2 s . com root_json_obj.put(files.get(i).getFileName(), fileJsonObj); } try { outputFile = outputFile.substring(0, outputFile.lastIndexOf('.')) + ".json"; FileWriter file = new FileWriter(outputFile); file.write(root_json_obj.toJSONString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:io.personium.core.rs.box.BoxResource.java
/** * GET ?? ./*w ww . j a va 2 s . com*/ * @return JAX-RS Response */ @GET public Response get() { // this.davRsCmp.checkAccessContext(this.davRsCmp.getAccessContext(), BoxPrivilege.READ); // ?box??????? // ???null?????????box???????? // ??????????? String key = "box-" + this.box.getId(); Progress progress = ProgressManager.getProgress(key); if (progress == null) { JSONObject response = createNotRequestedResponse(); return Response.ok().entity(response.toJSONString()).build(); } String jsonString = progress.getValue(); JSONObject jsonObj = null; try { jsonObj = (JSONObject) (new JSONParser()).parse(jsonString); } catch (ParseException e) { throw PersoniumCoreException.Server.DATA_STORE_UNKNOWN_ERROR.reason(e); } // ????????box???????? JSONObject barInfo = (JSONObject) jsonObj.get("barInfo"); if (barInfo == null) { log.info("cache(" + key + "): process" + (String) jsonObj.get("process")); JSONObject response = createNotRequestedResponse(); return Response.ok().entity(response.toJSONString()).build(); } // box??????????? JSONObject response = createResponse(barInfo); return Response.ok().entity(response.toJSONString()).build(); }
From source file:hoot.services.controllers.job.ExportJobResourceTest.java
@Test @Category(UnitTest.class) public void testProcess() throws Exception { String params = "{\"translation\":\"MGCP.js\",\"inputtype\":\"db\",\"input\":\"ToyTestA\",\"outputtype\":\"gdb\",\"removereview\" : \"false\"}"; String tempOutputPath = TEMP_OUTPUT_PATH; JSONObject arg = new JSONObject(); arg.put("outputfolder", tempOutputPath + "/" + "f9a8d471"); tempOutputPath = arg.toJSONString(); String jobArgs = ",\"exec\":\"osm2ogrscript\",\"params\":[{\"input\":\"ToyTestA\"},{\"translation\":\"MGCP.js\"},"; jobArgs += "{\"outputtype\":\"gdb\"},{\"removereview\":\"false\"},{\"inputtype\":\"db\"},"; jobArgs += tempOutputPath + ","; jobArgs += "{\"output\":\"f9a8d471\"},{\"outputname\":\"f9a8d471\"}],"; jobArgs += "\"exectype\":\"make\"}"; ExportJobResource spy = Mockito.spy(new ExportJobResource()); Mockito.doNothing().when((JobControllerBase) spy).postJobRquest(anyString(), anyString()); JobId resp = spy.process(params);//from w w w . ja va2s .c o m String jobId = resp.getJobid(); jobArgs = jobArgs.replaceAll("f9a8d471", jobId); verify(spy).postJobRquest(Matchers.matches(jobId), Matchers.endsWith(jobArgs)); }
From source file:com.dnastack.ga4gh.impl.BeaconizeVariantImpl.java
/** * Queries the Variant API implementation for variants at the given position * * @param reference The reference (or chromosome) * @param position Position on the reference * @param alt The alternate allele to match against (currently not supported by GASearchVariantsRequest) * @return A JSON Object containing a GASearchVariantsResponse * @throws IOException Problems contacting API * @throws ParseException Problems parsing response *///www.j a v a 2 s . com private JSONObject submitVariantSearchRequest(String reference, long position, String alt) throws IOException, ParseException { JSONObject obj = new JSONObject(); JSONArray list = new JSONArray(); list.addAll(Arrays.asList(variantSetIds)); obj.put("variantSetIds", list); obj.put("referenceName", reference); obj.put("start", position); obj.put("end", (position + 1)); String json = obj.toJSONString(); URL url = new URL(fullVariantSearchURL); StringBuilder postData = new StringBuilder(); postData.append(json); byte[] postDataBytes = postData.toString().getBytes("UTF-8"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); conn.setDoOutput(true); conn.getOutputStream().write(postDataBytes); StringBuilder sb = new StringBuilder(); Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); for (int c; (c = in.read()) >= 0;) { sb.append((char) c); } String jsonString = sb.toString(); return (JSONObject) JSONValue.parseWithException(jsonString); }
From source file:com.nubits.nubot.tasks.SubmitLiquidityinfoTask.java
private void logOrderJSON(JSONObject orderHistory) { FilesystemUtils.writeToFile(orderHistory.toJSONString(), jsonFile_orders, false); }
From source file:com.nubits.nubot.tasks.SubmitLiquidityinfoTask.java
private void logBalanceJSON(JSONObject balanceHistory) { FilesystemUtils.writeToFile(balanceHistory.toJSONString(), jsonFile_balances, false); }
From source file:hudson.plugins.chainreactorclient.ChainReactorInvalidServerException.java
ChainReactorConnector(AbstractBuild build, PrintStream logger) { this.build = build; this.logger = logger; JSONObject jsonobj = new JSONObject(); jsonobj.put("project", this.build.getProject().getName()); jsonobj.put("build_no", this.build.getNumber()); jsonobj.put("build", this.build.getFullDisplayName()); jsonobj.put("url", this.build.getAbsoluteUrl()); Result res = build.getResult(); jsonobj.put("result", res.toString()); this.json = jsonobj.toJSONString(); }
From source file:co.edu.uniandes.ecos.statusquo.services.PacienteService.java
@POST @Produces(MediaType.APPLICATION_JSON)/*w w w. j a va 2s . com*/ public Response crearPaciente(Paciente paciente) { final JSONObject rta = new JSONObject(); try { pacienteService.save(paciente); rta.put("paciente_id", paciente.getId()); } catch (Exception ex) { ex.printStackTrace(System.out); return Response.status(500).header("Access-Control-Allow-Origin", "*").entity(0).build(); } return Response.status(200).header("Access-Control-Allow-Origin", "*").entity(rta.toJSONString()).build(); }