List of usage examples for org.json.simple JSONObject clear
void clear();
From source file:modelo.ApiManager.java
public static void limpiarJSONObject(JSONObject jsonObject) { if (!jsonObject.isEmpty()) { jsonObject.clear(); }/*from w w w . j av a2 s . c o m*/ }
From source file:com.punyal.medusaserver.californiumServer.core.MedusaValidation.java
public static Client check(String medusaServerAddress, String myTicket, String ticket) { CoapClient coapClient = new CoapClient(); Logger.getLogger("org.eclipse.californium.core.network.CoAPEndpoint").setLevel(Level.OFF); Logger.getLogger("org.eclipse.californium.core.network.EndpointManager").setLevel(Level.OFF); Logger.getLogger("org.eclipse.californium.core.network.stack.ReliabilityLayer").setLevel(Level.OFF); CoapResponse response;//from ww w. ja v a2 s . co m coapClient.setURI(medusaServerAddress + "/" + MEDUSA_SERVER_VALIDATION_SERVICE_NAME); JSONObject json = new JSONObject(); json.put(JSON_MY_TICKET, myTicket); json.put(JSON_TICKET, ticket); response = coapClient.put(json.toString(), 0); if (response != null) { //System.out.println(response.getResponseText()); try { json.clear(); json = (JSONObject) JSONValue.parse(response.getResponseText()); long expireTime = (Long) json.get(JSON_TIME_TO_EXPIRE) + (new Date()).getTime(); String userName = json.get(JSON_USER_NAME).toString(); String[] temp = json.get(JSON_ADDRESS).toString().split("/"); String address; if (temp[1] != null) address = temp[1]; else address = "0.0.0.0"; Client client = new Client(InetAddress.getByName(address), userName, null, UnitConversion.hexStringToByteArray(ticket), expireTime); return client; } catch (Exception e) { } } else { // TODO: take } return null; }
From source file:net.modsec.ms.connector.ConnRequestHandler.java
/** * Stops the modsecurity instance if not stopped before. * @param json// w w w .j a v a2 s. co m */ @SuppressWarnings("unchecked") public static void onStopRequest(JSONObject json) { log.info("onStopRequest called.. : " + json.toJSONString()); MSConfig config = MSConfig.getInstance(); String cmd = config.getConfigMap().get("MSStop"); JSONObject resp = executeShScript(cmd, json); if (((String) resp.get("status")).equals("0")) { resp.put("message", "Modsecuity Sucessfully Stoped"); } log.info("Sending Json :" + resp.toJSONString()); ConnectorService.getConnectorProducer().send(resp.toJSONString()); resp.clear(); }
From source file:net.modsec.ms.connector.ConnRequestHandler.java
/** * Starts the modsecurity instance if not running. * @param json //from w w w .jav a 2 s . co m */ @SuppressWarnings("unchecked") public static void onStartRequest(JSONObject json) { log.info("onStartRequest called.. : " + json.toJSONString()); MSConfig config = MSConfig.getInstance(); String cmd = config.getConfigMap().get("MSStart"); JSONObject resp = executeShScript(cmd, json); if (((String) resp.get("status")).equals("0")) { resp.put("message", "Modsecuity Sucessfully Started"); } log.info("Sending Json :" + resp.toJSONString()); ConnectorService.getConnectorProducer().send(resp.toJSONString()); resp.clear(); }
From source file:net.modsec.ms.connector.ConnRequestHandler.java
/** * Restarts the instance./*from w w w.jav a 2s . c o m*/ * @param json */ @SuppressWarnings("unchecked") public static void onRestartRequest(JSONObject json) { log.info("onRestartRequest called.. : " + json.toJSONString()); MSConfig config = MSConfig.getInstance(); String cmd = config.getConfigMap().get("MSRestart"); JSONObject resp = executeShScript(cmd, json); if (((String) resp.get("status")).equals("0")) { resp.put("message", "Modsecuity Sucessfully Restarted"); } log.info("Sending Json :" + resp.toJSONString()); ConnectorService.getConnectorProducer().send(resp.toJSONString()); resp.clear(); }
From source file:net.modsec.ms.connector.ConnRequestHandler.java
/** * Checks the modsecurity current status whether its running or stopped. * @param json/*from w w w . j a va 2s .c o m*/ */ @SuppressWarnings("unchecked") public static void onStatusRequest(JSONObject json) { log.info("onStatusRequest called.. : " + json.toJSONString()); MSConfig config = MSConfig.getInstance(); String cmd = config.getConfigMap().get("MSStatus"); JSONObject resp = executeShScript(cmd, json); if (((String) resp.get("status")).equals("0")) { log.info("Message After Execution:" + (String) resp.get("message")); if (((String) resp.get("message")).contains("running")) { resp.put("msStatus", "1"); } else { resp.put("msStatus", "0"); } } log.info("Sending Json :" + resp.toJSONString()); ConnectorService.getConnectorProducer().send(resp.toJSONString()); resp.clear(); }
From source file:copter.MPU9150.java
@Override public void run() { JSONObject res = new JSONObject(); while (true) { try {// ww w. j ava 2 s . c o m if (sendAccelData || sendGyroData) { res.clear(); } if (sendAccelData) { List<Double> readAccel = this.readAccel(); res.put("accelX", readAccel.get(0)); res.put("accelY", readAccel.get(1)); res.put("accelZ", readAccel.get(2)); } if (sendGyroData) { List<Double> readGyro = this.readGyro(); res.put("gyroX", readGyro.get(0)); res.put("gyroY", readGyro.get(1)); res.put("gyroZ", readGyro.get(2)); } if (sendAccelData || sendGyroData) { this.conn.send(res.toJSONString()); } Thread.sleep(50); } catch (Exception ex) { Logger.getLogger(MPU9150.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:eclserver.threads.EmergencyNotifyPush.java
private String getJsonString(String machineName, String confirmURL) { JSONObject m1 = new JSONObject(); m1.clear(); JSONArray list1 = new JSONArray(); try {/* w w w.j ava 2s . c o m*/ m1.put("details", enPanel.getNotifyDetails()); m1.put("acknowledgeurl", confirmURL + "?MyMessage=EmergencyNotificationAcknowledged"); list1.add(m1); } catch (Exception ex) { // ex.printStackTrace(); } String jsonString = "{\"Source\":[{\"machinename\":\"" + machineName + "\"}],"; jsonString += "\"Confirmation\":[{\"url\":\"" + confirmURL + "\"}],"; jsonString += "\"EmergencyCall\":" + list1.toString() + "}"; System.out.println("Call JSON: " + jsonString); return jsonString; }
From source file:eclserver.db.objects.ContactsDao.java
public String getJSONString(String machineName, String confirmURL) { // {"Source": [ {"machinename":"localhost" }], // "Confirmation": [ {"url":"http://CI0000001380643/PushConfirmation/PUSHConfirmationHandler.ashx?MyMessage=ContactsAdded"}], String jsonString = "{\"Source\":[{\"machinename\":\"" + machineName + "\"}],"; jsonString += "\"Confirmation\":[{\"url\":\"" + confirmURL + "\"}],"; jsonString += "\"Contacts\":["; JSONObject m1 = new JSONObject(); m1.clear(); // JSONArray list1 = new JSONArray(); try {//from w w w .j a v a2s .co m stmtGetListEntries.clearParameters(); ResultSet result = stmtGetListEntries.executeQuery(); while (result.next()) { m1.clear(); m1.put("GROUPNAME", result.getString("GROUPNAME")); m1.put("FIRSTNAME", result.getString("FIRSTNAME")); m1.put("LASTNAME", result.getString("LASTNAME")); m1.put("TITLE", result.getString("TITLE")); m1.put("COMPANY", result.getString("COMPANY")); m1.put("EMAIL", result.getString("EMAIL")); m1.put("HOMEPHONE", result.getString("HOMEPHONE")); m1.put("WORKPHONE", result.getString("WORKPHONE")); m1.put("MOBILEPHONE", result.getString("MOBILEPHONE")); m1.put("PIN", result.getString("DEVICEPIN")); m1.put("ADDRESS1", result.getString("ADDRESS1")); m1.put("ADDRESS2", result.getString("ADDRESS2")); m1.put("CITY", result.getString("CITY")); m1.put("STATE", result.getString("STATE")); m1.put("ZIPCODE", result.getString("ZIP")); m1.put("COUNTRY", result.getString("COUNTRY")); System.out.println("database record " + m1.toString()); jsonString += "" + m1.toString() + ","; } } catch (SQLException sqle) { System.out.println("SQLEXCEPTION in ContactsDao.getJSONString " + sqle.getMessage()); } //TBF: remove last comma correctly if (jsonString.endsWith(",")) { jsonString = jsonString.substring(0, jsonString.length() - 1); } jsonString += "]}"; System.out.println("\n\n\n JSON STRING " + jsonString); return jsonString; }
From source file:eclserver.threads.EmergencyCallPush.java
private String getJsonString(String machineName, String confirmURL) { JSONObject m1 = new JSONObject(); m1.clear(); JSONArray list1 = new JSONArray(); try {// w w w . j a va2s. co m m1.put("milliseconds", ecPanel.getCallDateTime()); m1.put("phonenumber", ecPanel.getCallBridge()); m1.put("details", ecPanel.getCallDescription()); m1.put("accepturl", confirmURL + "?MyMessage=EmergencyCallAccepted"); m1.put("declineurl", confirmURL + "?MyMessage=EmergencyCallDeclined"); list1.add(m1); } catch (Exception ex) { System.out.println("EXCEPTION GETTING JSON STRING: " + ex.getMessage()); } String jsonString = "{\"Source\":[{\"machinename\":\"" + machineName + "\"}],"; jsonString += "\"Confirmation\":[{\"url\":\"" + confirmURL + "\"}],"; jsonString += "\"EmergencyCall\":" + list1.toString() + "}"; // System.out.println("Call JSON STRING: " + jsonString); return jsonString; }