List of usage examples for org.json.simple JSONValue toJSONString
public static String toJSONString(Object value)
From source file:com.ls.zencat.JsonApi.java
private JSONObject routerRequest(String router, String method, HashMap data) throws Exception { // Construct standard URL for requests HttpPost httpost = new HttpPost(ZENOSS_INSTANCE + "/zport/dmd/" + ROUTERS.get(router) + "_router"); // Content-type MUST be set to 'application/json' httpost.addHeader("Content-type", "application/json; charset=utf-8"); httpost.setHeader("Accept", "application/json"); ArrayList packagedData = new ArrayList(); packagedData.add(data);//from w w w .j av a2 s .c o m HashMap reqData = new HashMap(); reqData.put("action", router); reqData.put("method", method); reqData.put("data", packagedData); reqData.put("type", "rpc"); // Increment the request count ('tid'). More important if sending multiple // calls in a single request reqData.put("tid", String.valueOf(this.reqCount++)); // Set the POST content to be a JSON-serialized version of request data httpost.setEntity(new StringEntity(JSONValue.toJSONString(reqData))); // Execute the request, and return the JSON-deserialized data String response = httpclient.execute(httpost, responseHandler); return (JSONObject) jsonParser.parse(response); }
From source file:name.martingeisse.common.javascript.jsonbuilder.JsonValueBuilder.java
/** * Converts a JsonSimple compatible object to a JSON value and * puts it into the place used by this builder. * // w w w . j a va 2 s .c o m * @param object the object to convert to JSON * @return the continuation */ public final C convertSimple(Object object) { getBuilder().append(JSONValue.toJSONString(object)); return getContinuation(); }
From source file:me.neatmonster.spacertk.scheduler.Job.java
@Override public void run() { if (SpaceRTK.getInstance().actionsManager.contains(actionName)) try {/*from www . j a v a 2 s .c o m*/ SpaceRTK.getInstance().actionsManager.execute(actionName, actionArguments); } catch (final InvalidArgumentsException e) { e.printStackTrace(); } catch (final UnhandledActionException e) { e.printStackTrace(); } else Utilities.sendMethod(actionName, JSONValue.toJSONString(Arrays.asList(actionArguments)) .replace("[[", "[").replace("],[", ",").replace("]]", "]")); }
From source file:com.mch.registry.ccs.server.CcsClient.java
/** * Creates a JSON encoded NACK message for an upstream message received from * an application.//from w w w . j av a 2 s. c om * * @param to RegistrationId of the device who sent the upstream message. * @param messageId messageId of the upstream message to be acknowledged to * CCS. * @return JSON encoded ack. */ public static String createJsonNack(String to, String messageId) { Map<String, Object> message = new HashMap<String, Object>(); message.put("message_type", "ack"); message.put("to", to); message.put("message_id", messageId); return JSONValue.toJSONString(message); }
From source file:edu.anu.spice.SpiceStats.java
@Override public String toJSONString() { return JSONValue.toJSONString(this.toJSONArray()); }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.algorithm.StatusProxy.java
@SuppressWarnings("unchecked") @Override/*from ww w . ja v a 2 s.co m*/ public void changeSetCourse(List<IRVCommand> courseCommandList, boolean immediate) { JSONArray a = new JSONArray(); for (IRVCommand cmd : courseCommandList) { a.add(rvCommandToJSON(cmd)); } JSONObject o = new JSONObject(); o.put("immediate", Boolean.valueOf(immediate)); o.put("course", a); String x = JSONValue.toJSONString(a); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(setCourseUrl); HttpResponse response; String responseString = ""; try { StringEntity entity = new StringEntity(x, "setcourse/json", null); httppost.setEntity(entity); response = httpclient.execute(httppost); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 200) responseString = EntityUtils.toString(response.getEntity()); else LOG.error("Error at accessing " + setCourseUrl + " code=" + statusCode + " reason=" + response.getStatusLine().getReasonPhrase()); LOG.info("Upload new course to " + setCourseUrl + " response=" + responseString); } catch (Exception e) { LOG.error("Can not access " + setCourseUrl, e); } // TODO return a value ? }
From source file:au.org.paperminer.main.LocationFilter.java
/** * Returns JSON struct for a given set of TROVE ids: * refs: [{troveId:[locnId,freq]*]*/*from w ww .j av a 2 s.com*/ * or blank if none. * @param req * @param resp */ private void getReferences(HttpServletRequest req, HttpServletResponse resp) { HashMap<String, ArrayList<ArrayList<String>>> map = new HashMap<String, ArrayList<ArrayList<String>>>(); try { String arg = req.getParameter("lst"); if ((arg != null) && (arg.length() > 0)) { String[] refs = arg.split(","); m_logger.debug("locationFilter getReferences: " + arg + " length:" + refs.length); for (int i = 0; i < refs.length; i++) { ArrayList<ArrayList<String>> tmp = m_helper.getLocationsForRef(refs[i]); if (tmp != null) { map.put(refs[i], tmp); m_logger.debug("locationFilter ref: " + refs[i] + " is " + tmp); } } } resp.setContentType("text/json"); PrintWriter pm = resp.getWriter(); String jsonStr = ""; if (map.size() > 0) { jsonStr = "{\"refs\":" + JSONValue.toJSONString(map) + "}"; } pm.write(jsonStr); pm.close(); m_logger.debug("locationFilter getReferences JSON: " + jsonStr); } catch (PaperMinerException ex) { req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e301"); } catch (IOException ex) { req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e114"); } }
From source file:com.mobicage.rogerthat.registration.AbstractRegistrationActivity.java
public String getMobileInfo() { T.REGISTRATION(); MobileInfo info = SystemPlugin.gatherMobileInfo(mService); String json = JSONValue.toJSONString(info.toJSONMap()); return json; }
From source file:edu.anu.spice.SemanticTuple.java
@SuppressWarnings("unchecked") @Override// ww w . j ava 2s.c o m public String toJSONString() { JSONObject jsonObj = new JSONObject(); JSONArray tuple = new JSONArray(); for (SemanticConcept concept : this.tuple) { tuple.add(concept.toJSONString()); } jsonObj.put("tuple", tuple); jsonObj.put("truth_value", this.truthValue); return JSONValue.toJSONString(jsonObj); }
From source file:ezbake.frack.storm.core.StormPipelineSubmitter.java
@Override public void submit(final Pipeline pipeline) throws IOException { long startTime = System.currentTimeMillis(); String id = pipeline.getId(); log.info("Submitting {} to Storm", id); NimbusClient client = null;/*from w ww. ja va2 s.c om*/ try { TopologyBuilder builder = new TopologyBuilder(); StormConfiguration stormConfig = new StormConfiguration(pipeline.getProperties()); boolean quarantineEnabled = new EzProperties(stormConfig, true) .getBoolean(PipelineConfiguration.ENABLE_QUARANTINE, false); // I would like to use a HashMultimap here, but the resulting set object is not serializable. // Unfortunately this means we have to use our own Multimap with a HashSet object as each value. // Each key in this multimap is the pipe ID of stream source, and each value for that key is a // stream name on which the source pipe will be emitting Tuples. Map<String, Set<String>> streams = new HashMap<>(); List<Pipeline.PipeInfo> pipeInfos = pipeline.getPipeInfos(); log.debug("Translating Pipes to Spouts/Bolts"); Set<String> streamIds = Sets.newHashSet(); if (quarantineEnabled) { QuarantineSpout quarantineSpout = new QuarantineSpout(stormConfig, id, streamIds); builder.setSpout(QuarantineSpout.SPOUT_ID, quarantineSpout); } for (Pipeline.PipeInfo pipeInfo : pipeInfos) { String pipeId = pipeInfo.getPipeId(); Pipe pipe = pipeInfo.getPipe(); if (!streams.containsKey(pipeId)) { streams.put(pipeId, new HashSet<String>()); } if (Pipeline.isListener(pipe)) { FrackListenerSpout listener = new FrackListenerSpout(pipeInfo, stormConfig, id, streams.get(pipeId), startTime); builder.setSpout(pipeId, listener, stormConfig.getNumExecutors(pipeId)) .setNumTasks(stormConfig.getNumTasks(pipeId)); } else if (Pipeline.isGenerator(pipe)) { log.debug("Adding spout for {}", pipeId); FrackSpout generator = new FrackSpout(pipeInfo, stormConfig, id, streams.get(pipeId), startTime); builder.setSpout(pipeId, generator, stormConfig.getNumExecutors(pipeId)) .setNumTasks(stormConfig.getNumTasks(pipeId)); } else if (Pipeline.isWorker(pipe)) { log.info("Adding bolt for {}", pipeId); FrackBolt frackBolt = new FrackBolt(pipeInfo, stormConfig, id, streams.get(pipeId), startTime); BoltDeclarer declarer = builder.setBolt(pipeId, frackBolt, stormConfig.getNumExecutors(pipeId)) .setNumTasks(stormConfig.getNumTasks(pipeId)); // Create a stream id which is used by the quarantine spout to emit to specific workers if (quarantineEnabled) { streamIds.add(pipeId); declarer.shuffleGrouping(QuarantineSpout.SPOUT_ID, pipeId); } Worker worker = (Worker) pipe; String streamId = worker.getType().getCanonicalName(); for (String input : pipeInfo.getInputs()) { if (!streams.containsKey(input)) { streams.put(input, new HashSet<String>()); } log.info("Adding input {} for bolt", input); streams.get(input).add(streamId); log.info("Input {} and Stream {}", input, streamId); declarer.shuffleGrouping(input, streamId); } } } // Upload the jar to the nimbus String uploadedLocation = StormSubmitter.submitJar(stormConfig, pipeline.getProperties().getProperty(PipelineConfiguration.JAR_LOCATION_PROP)); // Start the topology client = NimbusClient.getConfiguredClient(stormConfig); String serConf = JSONValue.toJSONString(stormConfig); client.getClient().submitTopology(pipeline.getId(), uploadedLocation, serConf, builder.createTopology()); } catch (AlreadyAliveException e) { throw new IOException(String.format("Pipeline with name '%s' already exists!", id), e); } catch (InvalidTopologyException e) { throw new IOException(String.format("Pipeline '%s' is invalid", id), e); } catch (IOException e) { throw new IOException("Could not initialize default Storm configuration", e); } catch (TException e) { throw new IOException("Thrift Exception occurred when submitting topology", e); } finally { if (client != null) { client.close(); } } }