List of usage examples for org.json JSONObject toString
public String toString()
From source file:com.whizzosoftware.hobson.mqtt.MQTTPlugin.java
@Override public void sendMessage(final String topic, final JSONObject payload) { executeInEventLoop(new Runnable() { @Override/*from w w w . j a v a 2s. co m*/ public void run() { try { mqtt.publish(topic, payload.toString().getBytes(), 0, false, null, new IMqttActionListener() { @Override public void onSuccess(IMqttToken iMqttToken) { logger.debug("MQTT message sent successfully"); } @Override public void onFailure(IMqttToken iMqttToken, Throwable throwable) { logger.error("Failed to send MQTT message", throwable); } }); } catch (MqttException e) { logger.error("Failed to send MQTT message", e); } } }); }
From source file:eu.smartfp7.linkeddatamanager.interfaces.TextSearch.java
/** * Finding activities identified by a certain keywords * @param label: The keywords to search//from w ww. j a va 2s .co m * @param lang: The language of the keywords * @param dataset: The dataset in which perform the search. By default DBpedia * @return A JSON file format with the found activities * @throws IOException */ @GET @Path("activities") @Produces({ MediaType.APPLICATION_JSON }) public Response searchActivity(@QueryParam("label") String label, @QueryParam("lang") @DefaultValue("en") String lang, @QueryParam("dataset") @DefaultValue("dbpedia") String dataset) throws IOException { //public void searchActivity(String label, String lang, int page, int pageSize) throws IOException{ InputStream in = null; Mapping m = new MappingManager().getMapping(dataset); logger.info("Invoking searchActivity by text-search"); logger.info("Dataset: " + dataset); logger.info("Label: " + label); logger.info("Language: " + lang); TextQueryBuilder builder = new TextQueryBuilder(m); builder.setCriteria(true, false, label, lang); String query = builder.printQuery(); SPARQLtoJSON queryer = new SPARQLtoJSON(m.getEndpoint(), m); try { JSONObject res = queryer.executeSPARQL(query); //System.out.println("Los resultados: " + res); in = new ByteArrayInputStream(res.toString().getBytes()); } catch (Exception e) { e.printStackTrace(); logger.info("Something wrong with the invocation of searchActivity by text-search"); return Response.serverError().build(); } logger.info("Invoked searchActivity by text-search"); return Response.ok(in).build(); }
From source file:eu.smartfp7.linkeddatamanager.interfaces.TextSearch.java
/** * Finding venues identified by a certain keywords * @param label: The keywords to search// w ww .j av a 2 s . c o m * @param lang: The language of the keywords * @param dataset: The dataset in which perform the search. By default DBpedia * @return A JSON file format with the found venues */ //public void seachLocation(String label, String lang, int page, int pageSize){ @GET @Path("venues") @Produces({ MediaType.APPLICATION_JSON }) public Response searchLocation(@QueryParam("label") String label, @QueryParam("lang") @DefaultValue("en") String lang, @QueryParam("dataset") @DefaultValue("dbpedia") String dataset) throws IOException { logger.info("Invoking searchLocation by text-search"); logger.info("Dataset: " + dataset); logger.info("Label: " + label); logger.info("Language: " + lang); InputStream in = null; Mapping m = new MappingManager().getMapping(dataset); TextQueryBuilder builder = new TextQueryBuilder(m); builder.setCriteria(false, true, label, lang); String query = builder.printQuery(); SPARQLtoJSON queryer = new SPARQLtoJSON(m.getEndpoint(), m); try { JSONObject res = queryer.executeSPARQL(query); //System.out.println("Los resultados: " + res); in = new ByteArrayInputStream(res.toString().getBytes()); } catch (Exception e) { e.printStackTrace(); logger.info("Something wrong with the invocation of searchLocation by text-search"); return Response.serverError().build(); } logger.info("Invoked searchLocation by text-search"); return Response.ok(in).build(); }
From source file:com.hp.ov.sdk.rest.http.core.client.HttpRestClient.java
/** * Send the request to OV and read the response. * * @param restParams connection parameters. * @param jsonObject request body./*from www . j av a 2 s . c om*/ * * @return * A string representing the response data. * @throws * SDKBadRequestException on unsupported method (PUT, GET..) **/ public String sendRequest(RestParams restParams, JSONObject jsonObject) throws SDKBadRequestException { return processRequestType(restParams, jsonObject.toString(), false); }
From source file:com.hp.ov.sdk.rest.http.core.client.HttpRestClient.java
/** * Send the request to OV and read the response. * * @param restParams connection parameters. * @param jsonObject//from w ww.j a va2s . c om * request body. * @param forceReturnTask * Forces the check for the Location header (task) even when the response code is not 202. * * @return * A string representing the response data. * @throws * SDKBadRequestException on unsupported method (PUT, GET..) **/ public String sendRequest(RestParams restParams, JSONObject jsonObject, boolean forceReturnTask) throws SDKBadRequestException { return processRequestType(restParams, jsonObject.toString(), forceReturnTask); }
From source file:org.loklak.server.Accounting.java
public static void main(String[] args) { Accounting a = new Accounting(); a.addRequest("/api/test.json", "q=test"); JSONObject r = a.getRequests("/api/test.json"); System.out.println(r.toString()); }
From source file:org.chronotext.cinder.CinderBridge.java
public synchronized String getMemoryInfo() { MemoryInfo memoryInfo = new MemoryInfo(); ((ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(memoryInfo); JSONObject json = new JSONObject(); try {//w w w.j av a2 s .co m json.put("availMem", memoryInfo.availMem); json.put("threshold", memoryInfo.threshold); json.put("lowMemory", memoryInfo.lowMemory); } catch (JSONException e) { } return json.toString(); }
From source file:com.android.fancyblurdemo.volley.toolbox.JsonObjectRequest.java
/** * Creates a new request./*from ww w .jav a 2 s. c o m*/ * @param method the HTTP method to use * @param url URL to fetch the JSON from * @param jsonRequest A {@link org.json.JSONObject} to post with the request. Null is allowed and * indicates no parameters will be posted along with request. * @param listener Listener to receive the JSON response * @param errorListener Error listener, or null to ignore errors. */ public JsonObjectRequest(int method, String url, JSONObject jsonRequest, Listener<JSONObject> listener, ErrorListener errorListener) { super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(), listener, errorListener); }
From source file:reseau.jeu.serveur.Protocole.java
public static String construireMsgJoueurInitialisation(Joueur joueur, Terrain terrain) { JSONObject msg = new JSONObject(); try {//from w w w . ja v a 2 s.c o m msg.put("TYPE", JOUEUR_INITIALISATION); msg.put("STATUS", OK); msg.put("ID_JOUEUR", joueur.getId()); msg.put("ID_EMPLACEMENT", joueur.getEmplacement().getId()); msg.put("ID_EQUIPE", joueur.getEquipe().getId()); msg.put("NOM_FICHIER_TERRAIN", terrain.getNomFichier()); } catch (JSONException e) { e.printStackTrace(); } return msg.toString(); }
From source file:reseau.jeu.serveur.Protocole.java
public static String construireMsgJoueursEtat(ArrayList<Joueur> joueurs) { JSONObject msg = new JSONObject(); JSONArray JSONjoueurs = new JSONArray(); try {//from w w w.j av a2 s . c o m msg.put("TYPE", JOUEURS_ETAT); Joueur joueur; JSONObject JSONjoueur; for (int j = 0; j < joueurs.size(); j++) { // recuperation du joueur joueur = joueurs.get(j); // construction du joueur JSONjoueur = new JSONObject(); JSONjoueur.put("ID_JOUEUR", joueur.getId()); JSONjoueur.put("NOM_JOUEUR", joueur.getPseudo()); JSONjoueur.put("ID_EMPLACEMENT", joueur.getEmplacement().getId()); JSONjoueur.put("ID_EQUIPE", joueur.getEquipe().getId()); // ajout la liste des joueurs JSONjoueurs.put(JSONjoueur); } msg.put("JOUEURS", JSONjoueurs); } catch (JSONException e) { e.printStackTrace(); } return msg.toString(); }