List of usage examples for org.json.simple JSONArray toString
@Override
public String toString()
From source file:freebase.api.FreebaseAPI2.java
public static List<Film> getFilms(String fromDate, String toDate) { try {/*from w ww. j a va 2 s . c om*/ properties.load(new FileInputStream("freebase.properties")); HttpTransport httpTransport = new NetHttpTransport(); HttpRequestFactory requestFactory = httpTransport.createRequestFactory(); JSONParser parser = new JSONParser(); // String query = "[{\"id\":null,\"name\":null,\"type\":\"/astronomy/planet\"}]"; String query = readQueryFromFile("queries/q1.json"); query = manipulateQuery(query, fromDate, toDate); //JSONArray queryJObj = (JSONArray) JSONValue.parse(query); //query = queryJObj.toJSONString(); //query = "[{\"id\":null,\"name\":null,\"type\":\"/film/film\"}]"; //query = "[{\"mid\":null,\"name\":null,\"language\":\"English Language\",\"country\":\"United States of America\",\"type\":\"/film/film\",\"initial_release_date>=\":\"2000-01-01\",\"initial_release_date<=\":\"2020-01-01\",\"initial_release_date\":null,\"directed_by\":[{\"mid\":null,\"name\":null}],\"starring\":[{\"mid\":null,\"actor\":[{\"mid\":null,\"name\":null}],\"character\":[{\"mid\":null,\"name\":null}]}],\"limit\":1}]"; GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/mqlread"); url.put("query", query); url.put("key", properties.get("API_KEY")); // url.put("cursor", current_cursor); System.out.println("URL:" + url); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse httpResponse = request.execute(); JSONObject response = (JSONObject) parser.parse(httpResponse.parseAsString()); JSONArray results = (JSONArray) response.get("result"); // if (response.get("cursor") instanceof Boolean) { // System.out.println("End of The Result, cursor=" + response.get("cursor")); // } else { // current_cursor = (String) response.get("cursor"); // } // System.out.println(results.toString()); Utils.writeDataIntoFile(results.toString() + "\n", JSON_DUMP_FILE); List<Film> films = encodeJSON(results); return films; // for (Object result : results) { // System.out.println(JsonPath.read(result, "$.name").toString()); // } } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:com.itmanwuiso.checksums.dao.ResultJSONWriter.java
@SuppressWarnings("unchecked") public boolean write(List<HashResult> resuls, OutputStream outputStream) { if (null == resuls || outputStream == null) { throw new InvalidArgumentException("Resuls or OutputStream is " + "null."); }/*from w w w . j a v a 2 s . c o m*/ JSONArray jsons = new JSONArray(); for (HashResult hr : resuls) { jsons.add(converter.resultToJson(hr)); } try { outputStream.write(jsons.toString().getBytes()); outputStream.flush(); outputStream.close(); jsons.clear(); return true; } catch (IOException io) { logger.error("", io); } return false; }
From source file:com.erbjuder.logger.server.rest.services.TransactionLogRestService_V1.java
@GET @Path("/view") @Produces(MediaType.APPLICATION_JSON)/* w w w . ja v a 2s. c o m*/ public Response search(@QueryParam("logMessageId") String logMessageId, @QueryParam("dbSearchList") List<String> dataBaseSearchList) { try { // // Use dafault if no partition list are provided if (dataBaseSearchList == null || dataBaseSearchList.isEmpty()) { dataBaseSearchList = getDefaultSearchableDatabases(); } System.err.println("[ Got REST call ]"); System.err.println("logMessageId=[" + logMessageId + "]"); System.err.println("dataBaseSearchList=[" + dataBaseSearchList + "]"); LoggerSchema loggerSchema = new LoggerSchema(); ResultSetConverter converter = new ResultSetConverter(); JSONArray jsonResult = converter .toJSONArray(loggerSchema.fetch_LogMessageData(logMessageId, dataBaseSearchList)); return Response.ok(jsonResult.toString()).build(); } catch (Exception e) { return Response.serverError().build(); } }
From source file:control.ParametrizacionServlets.EliminarConsultores.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*w w w. j ava 2 s . co m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { int codigo = Integer.parseInt(request.getParameter("codigo")); JSONArray respError = new JSONArray(); Consultores manager = new Consultores(); respError = manager.Eliminar(codigo); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } catch (Exception e) { } }
From source file:control.ProcesoVertimientosServlets.EliminarEntidadLodos.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/* w w w . j a v a 2s. c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { int codigo = Integer.parseInt(request.getParameter("codigo")); JSONArray respError = new JSONArray(); ManejoLodos manager = new ManejoLodos(); respError = manager.Eliminar(codigo); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } catch (Exception ex) { // Logger.getLogger(EliminarLaboratorios.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:control.ProcesoVertimientosServlets.ValidarMonitoreosActivos.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w ww .j a v a 2 s. c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { int codigo = Integer.parseInt(request.getParameter("codigoProceso")); JSONArray resultado = new JSONArray(); ProgramarMonitoreo manager = new ProgramarMonitoreo(); resultado = manager.validarMonitoreoAct(codigo); for (Object jsonObject : resultado) { response.getWriter().write(resultado.toString()); } } catch (Exception e) { } }
From source file:control.ReportesServlets.EliminarHistorialDagma.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w.j av a 2 s. co m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { int codigo = Integer.parseInt(request.getParameter("codigoHistorial")); JSONArray respError = new JSONArray(); ReportesManager manager = new ReportesManager(); respError = manager.eliminarHistorialDagma(codigo); for (Object jsonObject : respError) { response.getWriter().write(respError.toString()); } } catch (Exception ex) { // Logger.getLogger(EliminarLaboratorios.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.hortonworks.amstore.view.TaskManagerService.java
/** * Handles: POST /taskmanager/postupdatetasks Add a task to the list of * tasks This is done because of BUG: a call to viewContext.putInstanceData * inside the servlet returns ERROR 500 after a while. * /*from ww w .ja v a 2 s . c o m*/ * @param headers * http headers * @param ui * uri info * * @return the response */ @POST @Path("/postupdatetasks") @Produces({ "text/html" }) public Response addPostUpdateTasks(String body, @Context HttpHeaders headers, @Context UriInfo ui) throws IOException { String current = viewContext.getInstanceData("post-update-tasks"); if (current == null) current = "[]"; JSONArray array = (JSONArray) JSONValue.parse(current); array.add(body); viewContext.putInstanceData("post-update-tasks", array.toString()); String output = "Added task:" + body; return Response.ok(output).type("text/html").build(); }
From source file:com.hortonworks.amstore.view.TaskManagerService.java
/** * Handles: POST /taskmanager/postinstalltasks Add a task to the list of * tasks This is done because of BUG: a call to viewContext.putInstanceData * inside the servlet returns ERROR 500 after a while. * //from w w w .j a v a 2 s . co m * @param headers * http headers * @param ui * uri info * * @return the response */ @POST @Path("/postinstalltasks") @Produces({ "text/html" }) public Response addPostInstallTasks(String body, @Context HttpHeaders headers, @Context UriInfo ui) throws IOException { String current = viewContext.getInstanceData("post-install-tasks"); if (current == null) current = "[]"; JSONArray array = (JSONArray) JSONValue.parse(current); array.add(body); viewContext.putInstanceData("post-install-tasks", array.toString()); String output = "Added task:" + body; return Response.ok(output).type("text/html").build(); }
From source file:com.hortonworks.amstore.view.TaskManagerService.java
/** * Handles: DELETE /taskmanager/postupdatetasks Removes a task from the * list of tasks This is done because of BUG: a call to * viewContext.putInstanceData inside the servlet returns ERROR 500 after a * while./*from www.ja va 2s. com*/ * * @param headers * http headers * @param ui * uri info * * @return the response */ @DELETE @Path("/postupdatetasks/{uri}") @Produces({ "text/html" }) public Response delPostUpdateTasks(@PathParam("uri") String uri, @Context HttpHeaders headers, @Context UriInfo ui) throws IOException { String response = ""; try { String current = viewContext.getInstanceData("post-update-tasks"); if (current == null) current = "[]"; JSONArray array = (JSONArray) JSONValue.parse(current); array.remove(URLDecoder.decode(uri)); viewContext.putInstanceData("post-update-tasks", array.toString()); /* * } catch( ParseException pe){ System.out.println("position: " + * pe.getPosition()); System.out.println(pe); } */ } catch (Exception e) { response += "Failed to remove: current=" + uri + "<br>"; response += "Error in service: " + e.toString(); return Response.ok(response).type("text/html").build(); } String entity = "{ \"status\": \"ok\" }"; return Response.ok(entity).type("text/html").build(); }