List of usage examples for org.json.simple JSONObject toJSONString
public String toJSONString()
From source file:controllers.ControllerServlet.java
private void save() { String filePath;//from w w w . j a va 2 s .c om filePath = "/Users/ivan/Desktop/ufns.json"; JSONObject obj = UFNS.getInstance().getJSONObject(); try { FileWriter file = new FileWriter(filePath); file.write(obj.toJSONString()); file.flush(); file.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:formatter.handler.post.FormatterPostHandler.java
/** * Handle a POST request/*from www.j ava2s .c o m*/ * @param request the raw request * @param response the response we will write to * @param urn the rest of the URL after stripping off the context * @throws ProjectException */ public void handle(HttpServletRequest request, HttpServletResponse response, String urn) throws FormatterException { try { //System.out.println("About to parse params"); parseImportParams(request); Connection conn = Connector.getConnection(); String jStr = conn.getFromDb(Database.METADATA, docid); JSONObject jDoc = (JSONObject) JSONValue.parse(jStr); if (version1 != null && isEditor) { //System.out.println("adding "+version1+"to metadata"); jDoc.put(JSONKeys.VERSION1, version1); jStr = jDoc.toJSONString(); jStr = jStr.replaceAll("\\\\/", "/"); String resp = conn.putToDb(Database.METADATA, docid, jStr); //System.out.println("Server response:"+resp); } else System.out.println("version1=" + version1 + " isEditor:" + Boolean.toString(isEditor)); } catch (Exception e) { try { response.getWriter().println("Status: 500; Exception " + e.getMessage()); } catch (Exception ex) { } System.out.println(e.getMessage()); throw new FormatterException(e); } }
From source file:org.kitodo.data.elasticsearch.index.type.TemplateType.java
@SuppressWarnings("unchecked") @Override// w ww. j a v a 2 s . c o m public HttpEntity createDocument(Template template) { JSONObject templateObject = new JSONObject(); templateObject.put("origin", template.getOrigin()); Integer process = template.getProcess() != null ? template.getProcess().getId() : null; templateObject.put("process", process); templateObject.put("properties", addObjectRelation(template.getProperties())); return new NStringEntity(templateObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:com.fujitsu.dc.test.utils.UserDataUtils.java
/** * NP???????./*from w w w . ja v a2 s. com*/ * @param token * @param code ?? * @param body * @param cell ?? * @param box ?? * @param collection ?? * @param entityType * @param id ?__id * @param navPropName NavigationProperty??("_"??) * @return ? */ public static TResponse createViaNP(String token, JSONObject body, String cell, String box, String collection, String entityType, String id, String navPropName, int code) { TResponse res = Http.request("box/odatacol/createNP.txt").with("cell", cell).with("box", box) .with("collection", collection).with("entityType", entityType).with("id", id) .with("navPropName", "_" + navPropName).with("accept", MediaType.APPLICATION_JSON) .with("contentType", MediaType.APPLICATION_JSON).with("token", token) .with("body", body.toJSONString()).returns().statusCode(code).debug(); return res; }
From source file:functionaltests.RestSchedulerTagTest.java
@Test public void testTaskIdsByUnknownTag() throws Exception { HttpResponse response = sendRequest("jobs/" + submittedJobId + "/tasks/tag/unknownTag"); JSONObject jsonObject = toJsonObject(response); System.out.println(jsonObject.toJSONString()); assertEquals("0", jsonObject.get("size").toString()); }
From source file:functionaltests.RestSchedulerTagTest.java
@Test public void testTaskStatesByTag() throws Exception { HttpResponse response = sendRequest("jobs/" + submittedJobId + "/taskstates/LOOP-T2-1"); JSONObject jsonObject = toJsonObject(response); System.out.println(jsonObject.toJSONString()); assertEquals("4", jsonObject.get("size").toString()); }
From source file:functionaltests.RestSchedulerTagTest.java
@Test public void testTaskStatesByUnknownTag() throws Exception { HttpResponse response = sendRequest("jobs/" + submittedJobId + "/taskstates/unknownTag"); JSONObject jsonObject = toJsonObject(response); System.out.println(jsonObject.toJSONString()); assertEquals("0", jsonObject.get("size").toString()); }
From source file:functionaltests.RestSchedulerTagTest.java
@Test public void testTaskResultValueByUnknownTag() throws Exception { HttpResponse response = sendRequest("jobs/" + submittedJobId + "/tasks/tag/unknownTag/result/value"); JSONObject jsonObject = toJsonObject(response); System.out.println(jsonObject.toJSONString()); assertEquals(0, jsonObject.size());/*from w w w .j ava 2 s . co m*/ }
From source file:functionaltests.RestSchedulerTagTest.java
@Test public void testTaskResultSerializedvalueByUnknownTag() throws Exception { HttpResponse response = sendRequest( "jobs/" + submittedJobId + "/tasks/tag/unknownTag/result/serializedvalue"); JSONObject jsonObject = toJsonObject(response); System.out.println(jsonObject.toJSONString()); assertEquals(0, jsonObject.size());//w w w . jav a 2 s .c om }
From source file:copter.GpsdConnector.java
public void init() { logger.log("Init GPS started..."); if (connected) { logger.log("GPS is already connected, no try to connect again."); return;// w w w.j a v a2 s .c om } initMembers(); initGpsd(); String gpsd_host = Config.getInstance().getString("gps", "gpsd_host"); int gpsd_port = Config.getInstance().getInt("gps", "gpsd_port"); ep = null; try { ep = new GPSdEndpoint(gpsd_host, gpsd_port, new ResultParser()); } catch (IOException ex) { logger.log(ex.getMessage()); } if (ep != null) { ep.addListener(new ObjectListener() { @Override public void handleTPV(final TPVObject tpv) { setTpvObject(tpv); if (streamGpsData) { JSONObject res = new JSONObject(); res.put("lng", tpv.getLongitude()); res.put("lat", tpv.getLatitude()); conn.send(res.toJSONString()); } } @Override public void handleSKY(final SKYObject sky) { for (final SATObject sat : sky.getSatellites()) { } } @Override public void handleSUBFRAME(final SUBFRAMEObject subframe) { } @Override public void handleATT(final ATTObject att) { } @Override public void handleDevice(final DeviceObject device) { } @Override public void handleDevices(final DevicesObject devices) { for (final DeviceObject d : devices.getDevices()) { } } }); ep.start(); } if (thread != null) { thread.interrupt(); } thread = new Thread(this); thread.start(); }