List of usage examples for org.json.simple JSONObject JSONObject
JSONObject
From source file:modelo.ProcesoVertimientosManagers.InformeProcesoSeco.java
public JSONObject registrar(int codigoProceso, Integer laboratorioProcesoSeco, Integer consultorProcesoSeco, String fechaEntregaProcesoSeco, String fechaRadicacionProcesoSeco, String fechaEntDevolProcesoSeco, String fechaDevolProcesoSeco, String observacionDevolProsesoSeco, Integer tipoDevolProcesoSeco, String observacionesProcesoSeco) { JSONObject jsonObject = new JSONObject(); try {//from www .java 2 s. c o m RegistrarProcesoSeco registrar = new RegistrarProcesoSeco(codigoProceso, laboratorioProcesoSeco, consultorProcesoSeco, fechaEntregaProcesoSeco, fechaRadicacionProcesoSeco, fechaEntDevolProcesoSeco, fechaDevolProcesoSeco, observacionDevolProsesoSeco, tipoDevolProcesoSeco, observacionesProcesoSeco); registrar.ejecutar(); jsonObject.put("resultado", registrar.getResultado()); } catch (Exception ex) { } return jsonObject; }
From source file:hd3gtv.mydmam.db.orm.AutotestOrm.java
public static AutotestOrm populate(int index) { AutotestOrm result = new AutotestOrm(); result.key = "THISISMYKEY" + String.valueOf(index); result.strvalue = "Hello world with cnts"; result.bytvalue = result.strvalue.toUpperCase().getBytes(); result.intvalue = 42;//from w w w. j a va 2s.com result.lngvalue = -3329447494103907027L; result.bolvalue = true; result.fltvalue = 6.55957f; result.dlbvalue = (double) result.lngvalue / 11d; result.uuivalue = UUID.fromString("110E8400-E29B-11D4-A716-446655440000"); result.jsovalue = new JSONObject(); result.jsovalue.put("Hello", "world"); result.jsovalue.put("Count", index); result.jsavalue = new JSONArray(); result.jsavalue.add("One"); result.jsavalue.add(42); result.jsavalue.add("Un"); try { result.addressvalue = InetAddress.getLocalHost(); } catch (UnknownHostException e) { e.printStackTrace(); } result.sbuvalue = new StringBuffer(); result.sbuvalue.append(result.key); result.sbuvalue.append(result.strvalue); result.sbuvalue.append(result.lngvalue); result.calendarvalue = Calendar.getInstance(); result.calendarvalue.set(1995, 05, 23, 10, 04, 8); result.calendarvalue.set(Calendar.MILLISECOND, 666); result.dtevalue = result.calendarvalue.getTime(); result.strarrayvalue = new String[2]; result.strarrayvalue[0] = result.strvalue; result.strarrayvalue[1] = result.key; result.serializvalue = new HashMap<String, String>(); result.serializvalue.put("Some var", result.strvalue); result.serializvalue.put("Other var", result.uuivalue.toString()); result.enumvalue = MyEnum.ME; result.iamempty = ""; result.iamanindex = index; result.donttouchme = "F*ck you"; return result; }
From source file:com.telefonica.iot.cygnus.backends.http.JsonResponseTest.java
/** * Sets up tests by creating a unique instance of the tested class, and by * defining the behaviour of the mocked classes. * /* w w w . jav a2 s. co m*/ * @throws Exception */ @Before public void setUp() throws Exception { // set up the instance of the tested class JSONObject obj = new JSONObject(); obj.put("test", "test"); Header[] headers = { new BasicHeader("Content-type", "application/x-www-form-urlencoded"), new BasicHeader("Content-type", "application/x-www-form-urlencoded"), new BasicHeader("Accep", "text/html,text/xml,application/xml"), new BasicHeader("Connection", "keep-alive"), new BasicHeader("keep-alive", "115"), new BasicHeader( "User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.2) Firefox/3.6.2") }; response = new JsonResponse(obj, 200, "OK", null); }
From source file:com.telefonica.pyretic.backendchannel.BackendChannel.java
@Override void foundTerminator() { /*The end of a command or message has been seen. * *///from w w w .j av a 2 s.c o m Object obj = JSONValue.parse(this.getBuff()); JSONArray array = (JSONArray) obj; String type = array.get(0).toString(); if (type.equals("packet")) { multiHandler.sendToSwitch((JSONObject) array.get(1), type); } else if (type.equals("inject_discovery_packet")) { JSONObject newObj = new JSONObject(); newObj.put("switch", array.get(1)); newObj.put("inport", array.get(2)); multiHandler.sendToSwitch(newObj, type); } else if (type.equals("install")) { System.out.println("install"); } else if (type.equals("delete")) { System.out.println("delete"); } else if (type.equals("clear")) { System.out.println("clear"); } else if (type.equals("barrier")) { System.out.println("clear"); } else if (type.equals("flow_stats_request")) { System.out.println("clear"); } else { System.out.println("ERROR: Unknown msg from frontend " + array.get(1)); } }
From source file:hoot.services.nativeInterfaces.ProcessStreamInterfaceTest.java
@Test @Category(UnitTest.class) public void testcreateCmd() throws Exception { String jobIdStr = java.util.UUID.randomUUID().toString(); JSONArray args = new JSONArray(); JSONObject translation = new JSONObject(); translation.put("translation", "/test/loc/translation.js"); args.add(translation);// w w w . j ava 2 s .co m JSONObject output = new JSONObject(); output.put("output", "/test/loc/out.osm"); args.add(output); JSONObject input = new JSONObject(); input.put("input", "/test/loc/input.shp"); args.add(output); JSONObject command = new JSONObject(); command.put("exectype", "hoot"); command.put("exec", "ogr2osm"); command.put("params", args); ProcessStreamInterface ps = new ProcessStreamInterface(); Class[] cArg = new Class[1]; cArg[0] = JSONObject.class; Method method = ProcessStreamInterface.class.getDeclaredMethod("createCmdArray", cArg); method.setAccessible(true); String[] ret = (String[]) method.invoke(ps, command); String commandStr = ArrayUtils.toString(ret); String expected = "{hoot,--ogr2osm,/test/loc/translation.js,/test/loc/out.osm,/test/loc/out.osm}"; Assert.assertEquals(expected, commandStr); }
From source file:org.jboss.aerogear.test.api.application.PushApplicationWorker.java
@Override public JSONObject marshall(PushApplication application) { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", application.getName()); jsonObject.put("description", application.getDescription()); return jsonObject; }
From source file:control.ParametrizacionServlets.ActualizarPuntoVertimiento.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w ww.ja 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 { JSONObject resError = new JSONObject(); try { //Obtenemos el numero de contrato Double contrato = Double.parseDouble(request.getParameter("contrato")); //Obtenemos la cadena con la informacion y la convertimos en un //JSONArray String puntos = request.getParameter("puntos"); Object obj = JSONValue.parse(puntos); JSONArray jsonArray = new JSONArray(); jsonArray = (JSONArray) obj; //Recorremos el JSONArray y obtenemos la informacion. for (int i = 0; i < jsonArray.size(); i++) { JSONObject jsonObject = (JSONObject) jsonArray.get(i); String ubicacion = (String) jsonObject.get("ubicacion"); String latitud = (String) jsonObject.get("latitud"); String longitud = (String) jsonObject.get("longitud"); String observacion = (String) jsonObject.get("observacion"); int estado = Integer.parseInt((String) jsonObject.get("estado")); String codigo = (String) jsonObject.get("codigo"); String tipoEstructura = (String) jsonObject.get("tipoEstructura"); //Creamos el manager y guardamos la informacion. PuntosVertimiento manager = new PuntosVertimiento(); manager.actualizar(codigo, ubicacion, latitud, longitud, observacion, estado, contrato, tipoEstructura); } resError.put("error", 1); } catch (Exception ex) { resError.put("error", 0); } }
From source file:control.ClienteServlets.InsertarCliente.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// ww w. j av a2 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 { JSONObject respError = new JSONObject(); try { //Obtenemos los parametros String nit = request.getParameter("nit"); String razonSocial = request.getParameter("razonSocial"); String direccion = request.getParameter("direccion"); String barrio = request.getParameter("barrio"); String correo = request.getParameter("correo"); String correo2 = request.getParameter("correo2"); String web = request.getParameter("web"); String representanteLegal = request.getParameter("representanteLegal"); String estadoUltVertimiento = request.getParameter("estadoUltVertimiento"); String ciiu = request.getParameter("ciiu"); String comuna = request.getParameter("comuna"); String telefono = request.getParameter("telefono"); String telefono2 = request.getParameter("telefono2"); String usoServicio = request.getParameter("usoServicio"); Integer respuesta; //Creamos el manager para registrar la informacion ClientesManager manager = new ClientesManager(); respuesta = manager.insertar(nit, razonSocial, ciiu, direccion, barrio, comuna, telefono, telefono2, usoServicio, correo, correo2, web, representanteLegal, estadoUltVertimiento); response.setContentType("application/json"); respError.put("error", respuesta); response.getWriter().write(respError.toString()); } catch (Exception ex) { response.setContentType("application/json"); respError.put("error", 0); response.getWriter().write(respError.toString()); } }
From source file:control.ProcesoVertimientosServlets.InsertarProgramacionMonitoreo.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// www. j a v a 2 s .com * @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 { JSONObject respError = new JSONObject(); try { //Obtenemos el numero de contrato String consultorMonitoreo = request.getParameter("consultorMonitoreo"); String fechaMonitoreo = request.getParameter("fechaMonitoreo"); String horaInicioMonitoreo = request.getParameter("horaInicioMonitoreo"); String horaFinMonitoreo = request.getParameter("horaFinMonitoreo"); int laboratorioMonitoreo = Integer.parseInt(request.getParameter("laboratorioMonitoreo")); int codigoProceso = Integer.parseInt(request.getParameter("codigoProceso")); String observacion = request.getParameter("observacionesReprogramacion"); String duracionMonitoreo = request.getParameter("duracionMonitoreo"); //Insertamos el programacion del monitoreo y obtenemos el codigo ProgramarMonitoreo manager = new ProgramarMonitoreo(); int codigoMonitoreo = manager.insertar(consultorMonitoreo, fechaMonitoreo, horaInicioMonitoreo, horaFinMonitoreo, laboratorioMonitoreo, codigoProceso, observacion, duracionMonitoreo); //Obtenemos la cadena con la informacion y la convertimos en un //JSONArray String puntos = request.getParameter("puntosVertimiento"); Object obj = JSONValue.parse(puntos); JSONArray jsonArray = new JSONArray(); jsonArray = (JSONArray) obj; //Recorremos el JSONArray y obtenemos la informacion. for (int i = 0; i < jsonArray.size(); i++) { //Obtenemos la info de los puntos JSONObject jsonObject = (JSONObject) jsonArray.get(i); int codigoPunto = Integer.parseInt((String) jsonObject.get("codigo")); int codigoActividad = Integer.parseInt((String) jsonObject.get("actividad")); //Creamos el manager y guardamos la informacion. manager.insertarPuntoMonitoreo(codigoPunto, codigoActividad, codigoMonitoreo); } respError.put("error", "1"); response.getWriter().write(respError.toString()); } catch (Exception ex) { respError.put("error", "0"); response.getWriter().write(respError.toString()); } }
From source file:me.uni.sushilkumar.geodine.util.WhatsCooking.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request/*from w ww . jav a2s . co m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); PrintWriter out = response.getWriter(); try { JSONObject obj = new JSONObject(); JSONArray array = new JSONArray(); DBConnection con = new DBConnection(); ArrayList<String> cuisineList = con.getCuisineList(); Random generator = new Random(); int size = cuisineList.size(); for (int i = 0; i < 10; i++) { JSONObject temp = new JSONObject(); String title = cuisineList.get(generator.nextInt(size)); //title=WordUtils.capitalize(title); temp.put("title", title); title = title.replaceAll("\\s+", "-"); String link = "cuisine/" + title; temp.put("link", link); array.add(temp); } obj.put("links", array); out.println(obj.toJSONString()); } catch (SQLException ex) { Logger.getLogger(WhatsCooking.class.getName()).log(Level.SEVERE, null, ex); } finally { out.close(); } }