Example usage for org.json.simple JSONObject JSONObject

List of usage examples for org.json.simple JSONObject JSONObject

Introduction

In this page you can find the example usage for org.json.simple JSONObject JSONObject.

Prototype

JSONObject

Source Link

Usage

From source file:control.AutenticacionServlets.InsertarPermisos.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from  w  w w.  j av  a 2s.  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 {

    JSONObject jsonObject = new JSONObject();
    response.setContentType("application/json");

    try {

        int codigo_rol = Integer.parseInt(request.getParameter("rol"));
        int codigo_pantalla = Integer.parseInt(request.getParameter("pantalla"));
        String valor = request.getParameter("valor");

        PermisosAcceso manager = new PermisosAcceso();

        jsonObject = manager.insertarPermisos(codigo_rol, codigo_pantalla, valor);

        response.getWriter().write(jsonObject.toString());

    } catch (Exception ex) {

        jsonObject.put("error", 0);
        jsonObject.put("exception", ex.toString());

        response.getWriter().write(jsonObject.toString());
    }

}

From source file:com.appzone.sim.services.handlers.AppRegistrationServiceHandler.java

@Override
protected String doProcess(HttpServletRequest request) {

    String infoRequest = request.getParameter(KEY_INFO_REQUEST);

    if (infoRequest != null) {
        Application application = Application.getApplication();
        JSONObject json = new JSONObject();
        json.put(JSON_KEY_URL, application.getUrl());
        json.put(JSON_KEY_USERNAME, application.getUsername());
        json.put(JSON_KEY_PASSWORD, application.getPassword());

        return json.toJSONString();
    } else {/*from  w  w w.  ja  va 2 s . c  o m*/
        String url = request.getParameter(KEY_URL);
        String username = request.getParameter(KEY_USERNAME);
        String password = request.getParameter(KEY_PASSWORD);

        logger.info("configuring application with: " + url + " :: {} :: {}", username, password);

        Application.configure(url, username, password);

        JSONObject json = new JSONObject();
        json.put(ServiceHandler.JSON_KEY_RESULT, true);

        return json.toJSONString();
    }
}

From source file:de.minestar.sixteenblocks.Threads.JSONThread.java

@SuppressWarnings("unchecked")
@Override//from  w  w  w  .  j  a  va  2  s .c o m
public void run() {
    // Create sync thread to use notthreadsafe methods
    Bukkit.getScheduler().scheduleSyncDelayedTask(Core.getInstance(), new Runnable() {

        @Override
        public void run() {
            BufferedWriter bWriter = null;
            try {
                JSONObject json = new JSONObject();
                json.put("ConnectedUsers", Bukkit.getOnlinePlayers().length);
                json.put("Skins", aManager.getUsedAreaCount());
                json.put("Slots", Core.getAllowedMaxPlayer());
                bWriter = new BufferedWriter(new FileWriter(JSONFile));
                bWriter.write(json.toJSONString());
                bWriter.flush();
                bWriter.close();
            } catch (Exception e) {
                ConsoleUtils.printException(e, Core.NAME, "Can't save JSON");
            } finally {
                try {
                    if (bWriter != null)
                        bWriter.close();
                } catch (Exception e2) {
                    // IGNORE SECOND EXCEPTION
                }
            }
        }
    });

}

From source file:com.telefonica.iot.cygnus.utils.CommonUtilsForTests.java

/**
 * Creates a JSONObject-like notification.
 * @return A JSONObject-like notification
 *//*from   w  w  w.j a va 2 s. c o  m*/
public static JSONObject createNotification() {
    JSONObject attribute = new JSONObject();
    attribute.put("name", "temperature");
    attribute.put("type", "centigrade");
    attribute.put("value", "26.5");
    JSONArray attributes = new JSONArray();
    attributes.add(attribute);
    JSONObject contextElement = new JSONObject();
    contextElement.put("attributes", attributes);
    contextElement.put("type", "Room");
    contextElement.put("isPattern", "false");
    contextElement.put("id", "room1");
    JSONObject statusCode = new JSONObject();
    statusCode.put("code", "200");
    statusCode.put("reasonPhrase", "OK");
    JSONObject contextResponse = new JSONObject();
    contextResponse.put("contextElement", contextElement);
    contextResponse.put("statusCode", statusCode);
    JSONArray contextResponses = new JSONArray();
    contextResponses.add(contextResponse);
    JSONObject notification = new JSONObject();
    notification.put("subscriptionId", "51c0ac9ed714fb3b37d7d5a8");
    notification.put("originator", "localhost");
    notification.put("contextResponses", contextResponses);
    return notification;
}

From source file:JavaCloud.Api.java

public ArrayList<String> apiModulesList() throws CoreException {
    JSONObject object = new JSONObject();
    object.put("token", token);
    JSONArray jsonmodules = (JSONArray) Utils.request(address, "/api/api/list_api_modules/", object);
    ArrayList<String> modules = new ArrayList<String>();
    for (int i = 0; i < jsonmodules.size(); i++) {
        modules.add(jsonmodules.get(i).toString());
    }//from  w  ww.  j a  va 2 s  .c o m

    return modules;
}

From source file:com.wso2.rfid.apicalls.APICall.java

public static void userCheckin(String deviceID, String rfid, String url, String consumerKey,
        String consumerSecret) throws UserCheckinException {
    //        String url = "https://gateway.apicloud.cloudpreview.wso2.com:8243/t/indikas.com/wso2coniot/1.0.0/conferences/2/userCheckIn";
    Token token = getToken(consumerKey, consumerSecret);
    if (token != null) {
        HttpClient httpClient = new HttpClient();
        JSONObject json = new JSONObject();
        json.put("uuid", deviceID);
        json.put("rfid", rfid);
        try {//from w  w  w .jav  a 2  s.  c  o  m
            HttpResponse httpResponse = httpClient.doPost(url, "Bearer " + token.getAccessToken(),
                    json.toJSONString(), "application/json");
            int statusCode = httpResponse.getStatusLine().getStatusCode();
            if (statusCode != 200) {
                throw new UserCheckinException(
                        "User checkin failed. HTTP Status Code:" + statusCode + ", RFID: " + rfid + ", CK="
                                + consumerKey + ", CS=" + consumerSecret + ", URL=" + url);
            }
        } catch (IOException e) {
            log.error("", e);
        }
    }
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.actions.Speed.java

@SuppressWarnings("unchecked")
@Override/*from  w w w . j  a va 2s . co  m*/
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", "speed");
    if (getTimestamp() != 0) {
        o.put("time", getTimestamp());
        o.put("value", speedOverGround);
    }
    return o.toJSONString();
}

From source file:control.ProcesoVertimientosServlets.EliminarAnexoInformes.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*from  w  w w .  j a  v a2s.c  om*/
 * @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 resp = new JSONObject();
    try {
        int codigo = Integer.parseInt(request.getParameter("codigo"));
        int codigoProceso = Integer.parseInt(request.getParameter("codigoProceso"));

        InformeProcesoSeco manager = new InformeProcesoSeco();

        resp = manager.eliminarAnexos(codigo, codigoProceso);

        response.setContentType("application/json");
        response.getWriter().write(resp.toString());

    } catch (Exception ex) {
        resp.put("error", 0);
        response.getWriter().write(resp.toString());
    }

}

From source file:localworker.LocalWorker.java

@SuppressWarnings("unchecked")
@Override//from   ww w  .ja va  2  s. c  o m
public void run() {
    JSONParser parser = new JSONParser();
    JSONObject json;
    String task_id = null;
    String task;

    try {

        while (true) {
            //waiting up to 100ms for an element to become available.
            String messageBody = jobQ.poll(100, TimeUnit.MILLISECONDS);

            if (messageBody != null) {

                json = (JSONObject) parser.parse(messageBody);

                task_id = json.get("task_id").toString();
                task = json.get("task").toString();

                Thread.sleep(Long.parseLong(task));

                JSONObject result = new JSONObject();
                result.put("task_id", task_id);
                result.put("result", "0");
                respQ.put(result.toString());

                //System.out.println(Thread.currentThread().getName()+" sleep done!");
            }
        }

    } catch (Exception e) {
        JSONObject result = new JSONObject();
        result.put("task_id", task_id);
        result.put("result", "1");
        try {
            respQ.put(result.toString());

        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
    }
}

From source file:com.saludtec.web.PagosWeb.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        String servicio = request.getRequestURI().replace("/HCEMed/Pagos/", "");
        switch (servicio) {
        case "guardar":
            guardarPago(request).writeJSONString(out);
            break;

        case "listar":
            listarPago(request).writeJSONString(out);
            break;

        default:/*  w  w  w. j  av a  2  s .co  m*/
            obj = new JSONObject();
            objArray = new JSONArray();
            obj.put("error", "404 - El servicio " + servicio + " no existe");
            objArray.add(obj);
            objArray.writeJSONString(out);
            break;
        }
    }
}