List of usage examples for org.json.simple JSONObject toJSONString
public String toJSONString()
From source file:com.netflix.raigad.resources.ElasticsearchAdmin.java
@GET @Path("/shard_allocation_disable/{type}") public Response esShardAllocationDisable(@PathParam("type") String type) throws IOException, InterruptedException, JSONException { logger.info("Disabling Shard Allocation through REST call ..."); if (!type.equalsIgnoreCase("transient") && !type.equalsIgnoreCase("persistent")) throw new IOException("Parameter must be equal to transient or persistent"); //URL/*from www . j a v a 2 s. com*/ String url = "http://127.0.0.1:" + config.getHttpPort() + "/_cluster/settings"; JSONObject settings = new JSONObject(); JSONObject property = new JSONObject(); property.put(SHARD_REALLOCATION_PROPERTY, "none"); settings.put(type, property); String RESPONSE = SystemUtils.runHttpPutCommand(url, settings.toJSONString()); return Response.ok(REST_SUCCESS, MediaType.APPLICATION_JSON).build(); }
From source file:com.nubits.nubot.testsmanual.TestRPCLiquidityInfo.java
private void testGetLiquidityInfo() { if (Global.rpcClient.isConnected()) { JSONObject responseObject = Global.rpcClient.getLiquidityInfo(NuRPCClient.USDchar); if (null == responseObject) { LOG.error("Something went wrong while sending liquidityinfo"); } else {/*from ww w . j a v a 2s . c om*/ LOG.info(responseObject.toJSONString()); } } else { LOG.error("Nu Client offline. "); } }
From source file:com.studevs.controllers.Index.java
@RequestMapping(value = "ajax_test") @ResponseBody//from w w w.java 2 s.c om public String doRequest2() { // JSONArray array = new JSONArray(); // // JSONObject object1 = new JSONObject(); // object1.put("number", String.valueOf(new Random().nextInt() * 1000)+" 1"); // object1.put("date", new Date().toString()+" 1"); // // JSONObject object2 = new JSONObject(); // object2.put("number", String.valueOf(new Random().nextInt() * 1000)+" 2"); // object2.put("date", new Date().toString()+" 2"); JSONObject object3 = new JSONObject(); object3.put("number", String.valueOf(new Random().nextInt() * 1000) + " 3"); object3.put("date", new Date().toString() + " 3"); // array.add(object1); // array.add(object2); // array.add(object3); return object3.toJSONString(); }
From source file:com.nubits.nubot.tests.TestRPC.java
private void testGetLiquidityInfo() { if (Global.rpcClient.isConnected()) { JSONObject responseObject = Global.rpcClient.getLiquidityInfo(NuRPCClient.USDchar); if (null == responseObject) { LOG.severe("Something went wrong while sending liquidityinfo"); } else {//from w w w . java 2 s .co m LOG.info(responseObject.toJSONString()); } } else { LOG.severe("Nu Client offline. "); } }
From source file:cs.rsa.ts14dist.appserver.RabbitMQDaemon.java
@Override public void run() { Connection connection = null; Channel channel = null;//from w ww.j a v a 2s. c o m try { ConnectionFactory factory = new ConnectionFactory(); logger.info("Starting RabbitMQDaemon, MQ IP = " + hostname); factory.setHost(hostname); connection = factory.newConnection(); channel = connection.createChannel(); channel.queueDeclare(rpcQueueName, false, false, false, null); channel.basicQos(1); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(rpcQueueName, false, consumer); while (true) { String response = null; // Block and fetch next msg from queue QueueingConsumer.Delivery delivery = consumer.nextDelivery(); BasicProperties props = delivery.getProperties(); BasicProperties replyProps = new BasicProperties.Builder().correlationId(props.getCorrelationId()) .build(); try { String message = new String(delivery.getBody(), "UTF-8"); logger.trace("Received msg: " + message); // Convert the message to a JSON request object JSONObject request = (JSONObject) JSONValue.parse(message); // Delegate to the server request handler for handling the // request and computing an answer JSONObject reply = serverRequestHandler.handleRequest(request); // Convert the answer back into a string for replying to // client response = reply.toJSONString(); } catch (Exception e) { logger.error(" Exception in MQDAemon run()/while true] " + e.toString()); response = "wrong"; } finally { logger.trace("Returning answer: " + response); channel.basicPublish("", props.getReplyTo(), replyProps, response.getBytes("UTF-8")); channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); logger.trace("Answer acknowledged."); } } } catch (Exception e) { logger.error("Exception in daemon's outer loop: nested exception" + e.getMessage()); e.printStackTrace(); } finally { if (connection != null) { try { connection.close(); } catch (Exception ignore) { } } } }
From source file:com.aerothai.database.radiosignal.RadiosignalResource.java
/** * Retrieves representation of an instance of com.aerothai.RadiosignalResource * @return an instance of java.lang.String *///from w w w . java 2s . c om @GET @Produces("application/json") public String listRadiosignalAt(@PathParam("id") int id) { String response = null; System.out.println("List Radiosignal At ID"); try { JSONObject radiosignalData = null; RadiosignalService radiosignalService = new RadiosignalService(); radiosignalData = radiosignalService.GetRadiosignalAt(id); response = radiosignalData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }
From source file:at.ac.tuwien.dsg.quelle.cloudServicesModel.util.conversions.ConvertToJSON.java
public static String convertToJSON(MultiLevelRequirements multiLevelRequirements) { //traverse the tree to do the JSON properly List<JSONObject> jsontree = new ArrayList<JSONObject>(); List<MultiLevelRequirements> multiLevelRequirementsTree = new ArrayList<MultiLevelRequirements>(); JSONObject root = processMultiLevelRequirementsElement(multiLevelRequirements); jsontree.add(root);// w w w . j a va 2 s . c om multiLevelRequirementsTree.add(multiLevelRequirements); //traverse the tree in a DFS manner while (!multiLevelRequirementsTree.isEmpty()) { MultiLevelRequirements currentlyProcessed = multiLevelRequirementsTree.remove(0); JSONObject currentlyProcessedJSONObject = jsontree.remove(0); JSONArray childrenArray = new JSONArray(); //process children for (MultiLevelRequirements child : currentlyProcessed.getContainedElements()) { JSONObject childJSON = processMultiLevelRequirementsElement(child); childrenArray.add(childJSON); //next to process are children jsontree.add(childJSON); multiLevelRequirementsTree.add(child); } if (currentlyProcessedJSONObject.containsKey("children")) { JSONArray array = (JSONArray) currentlyProcessedJSONObject.get("children"); array.addAll(childrenArray); } else { currentlyProcessedJSONObject.put("children", childrenArray); } } return root.toJSONString(); }
From source file:gamepub.beans.FaceBookAuthorizationBean.java
private String addPictureUrl(String json, String pictureUrl) { JSONParser jsonParser = new JSONParser(); String result = ""; try {// w w w.j a v a 2 s .c o m JSONObject jsonObject = (JSONObject) jsonParser.parse(json); jsonObject.put("picture", pictureUrl); result = jsonObject.toJSONString(); // String jsonComponent=array.get(index).toString(); } catch (ParseException ex) { } return result; }
From source file:com.aerothai.database.device.DeviceResource.java
/** * Retrieves representation of an instance of com.aerothai.DeviceResource * @return an instance of java.lang.String *//*from w w w . j a v a 2 s. c o m*/ @GET @Produces("application/json") public String listDeviceAt(@PathParam("id") int id) { String response = null; System.out.println("List Device At ID"); try { JSONObject deviceData = null; DeviceService deviceService = new DeviceService(); deviceData = deviceService.GetDeviceAt(id); response = deviceData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }
From source file:com.solace.samples.BasicReplier.java
public void run(String... args) { System.out.println("BasicReplier initializing..."); try {/* ww w.j a v a 2s .com*/ // Create an Mqtt client final MqttClient mqttClient = new MqttClient("tcp://" + args[0], "HelloWorldBasicReplier"); MqttConnectOptions connOpts = new MqttConnectOptions(); connOpts.setCleanSession(true); // Connect the client System.out.println("Connecting to Solace broker: tcp://" + args[0]); mqttClient.connect(connOpts); System.out.println("Connected"); // Latch used for synchronizing b/w threads final CountDownLatch latch = new CountDownLatch(1); // Topic filter the client will subscribe to receive requests final String requestTopic = "T/GettingStarted/request"; // Callback - Anonymous inner-class for receiving request messages mqttClient.setCallback(new MqttCallback() { public void messageArrived(String topic, MqttMessage message) throws Exception { try { // Parse the received request message and convert payload to a JSONObject Object payloadObj = parser.parse(new String(message.getPayload())); JSONObject jsonPayload = (JSONObject) payloadObj; // Get the correlationId and replyTo fields from the payload String correlationId = (String) jsonPayload.get("correlationId"); String replyTo = (String) jsonPayload.get("replyTo"); String messageContent = (String) jsonPayload.get("message"); System.out.println("\nReceived a request message!" + "\n\tCorrel. Id: " + correlationId + "\n\tReply To: " + replyTo + "\n\tMessage: " + messageContent + "\n"); // Create the response payload in JSON format and set correlationId // to the id received in the request message above. Requestor will // use this to correlate the response with its request message. JSONObject obj = new JSONObject(); obj.put("correlationId", correlationId); obj.put("message", "Sample Response"); String respPayload = obj.toJSONString(); // Create a response message and set the response payload MqttMessage respMessage = new MqttMessage(respPayload.getBytes()); respMessage.setQos(0); System.out.println("Sending response to: " + replyTo); // Publish the response message to the replyTo topic retrieved // from the request message above MqttTopic mqttTopic = mqttClient.getTopic(replyTo); mqttTopic.publish(respMessage); latch.countDown(); // unblock main thread } catch (ParseException ex) { System.out.println("Exception parsing request message!"); ex.printStackTrace(); } } public void connectionLost(Throwable cause) { System.out.println("Connection to Solace broker lost!" + cause.getMessage()); latch.countDown(); } public void deliveryComplete(IMqttDeliveryToken token) { } }); // Subscribe client to the topic filter with a QoS level of 0 System.out.println("Subscribing client to request topic: " + requestTopic); mqttClient.subscribe(requestTopic, 0); System.out.println("Waiting for request message..."); // Wait for till we have received a request and sent a response try { latch.await(); // block here until message received, and latch will flip } catch (InterruptedException e) { System.out.println("I was awoken while waiting"); } // Disconnect the client mqttClient.disconnect(); System.out.println("Exiting"); System.exit(0); } catch (MqttException me) { System.out.println("reason " + me.getReasonCode()); System.out.println("msg " + me.getMessage()); System.out.println("loc " + me.getLocalizedMessage()); System.out.println("cause " + me.getCause()); System.out.println("excep " + me); me.printStackTrace(); } }