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:controller.Json.java

/**
 * Outputs JSON string with given message, specify state {Error: something
 * went wrong, Passed: everything is OK}
 * //from w  ww.  j  av a2s . c o m
 * @param state
 * @param message
 * @return
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public String createJson(State state, String message) {
    JSONObject jsonParse = new JSONObject();
    this._state = (state.equals(State.ERROR)) ? "ERROR" : "SUCCEEDED";
    jsonParse.put("STATE", _state);
    jsonParse.put("MESSAGE", message);
    _json = new StringWriter();
    try {
        jsonParse.writeJSONString(_json);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return _json.toString();
}

From source file:io.personium.core.rs.StatusResource.java

/**
 * GET???./*from w ww. j  a v  a  2s.c o  m*/
 * @return JAS-RS Response
 */
@SuppressWarnings("unchecked")
@GET
@Produces("application/json")
public Response get() {
    StringBuilder sb = new StringBuilder();

    // 
    Properties props = PersoniumUnitConfig.getProperties();
    JSONObject responseJson = new JSONObject();
    JSONObject propertiesJson = new JSONObject();
    for (String key : props.stringPropertyNames()) {
        String value = props.getProperty(key);
        propertiesJson.put(key, value);
    }
    responseJson.put("properties", propertiesJson);

    // Cell?/
    //responseJson.put("service", checkServiceStatus());

    // ElasticSearch Health
    EsClient client = EsModel.client();
    JSONObject esJson = new JSONObject();
    esJson.put("health", client.checkHealth());
    responseJson.put("ElasticSearch", esJson);

    sb.append(responseJson.toJSONString());
    return Response.status(HttpStatus.SC_OK).entity(sb.toString()).build();
}

From source file:logout.logout_servlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from   w ww  . j ava2s  .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 {
    String token = request.getParameter("access_token");
    Connection currentCon = null;
    JSONObject arrayObj = new JSONObject();
    String query = "DELETE FROM tokendata WHERE token ='" + token + "'";

    try {
        //connect to database
        currentCon = ConnectionManager.getConnection();
        PreparedStatement ps = currentCon.prepareStatement(query);
        int i = ps.executeUpdate();
        arrayObj.put("status", "ok");
        System.out.println("DELETE TOKEN");

    }

    catch (Exception ex) {
        System.out.println("Log out failed: An Exception has occurred! " + ex);
    }

    finally {
        if (currentCon != null) {
            try {
                currentCon.close();
            } catch (Exception e) {
            }
            currentCon = null;
        }
    }
    response.setContentType("application/json:charset=UTF-8");
    response.getWriter().write(arrayObj.toString());
}

From source file:modelo.ParametrizacionManagers.Consultores.java

/**
* 
* Llama al delegate para Eliminar un Consultorio
* 
* @param codigo     /*from   w  w  w .j  av  a  2s .  c  om*/
* @throws Exception 
*/
public JSONArray Eliminar(int codigo) throws Exception {

    JSONArray jsonArray = new JSONArray();
    JSONObject jsonObject = new JSONObject();

    Integer respError;

    EliminarConsultores delete = new EliminarConsultores(codigo);
    delete.ejecutar();

    respError = delete.getError();

    jsonObject.put("error", respError);

    jsonArray.add(jsonObject);

    return jsonArray;

}

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

@SuppressWarnings("unchecked")
@Override//from  w w w.  j  ava2  s .c o  m
public String toJSONString() {
    JSONObject o = new JSONObject();
    o.put("type", "altitude");
    if (getTimestamp() != 0) {
        o.put("time", getTimestamp());
        o.put("value", altitudeOverGround);
    }
    return o.toJSONString();
}

From source file:com.telefonica.iot.tidoop.apiext.backends.ckan.CKANResponseTest.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.ja va2  s .  c  o  m
 *  
 * @throws Exception
 */
@Before
public void setUp() throws Exception {
    // set up the instance of the tested class
    ckanResponse = new CKANResponse(new JSONObject(), 200);
}

From source file:com.flaptor.indextank.api.resources.Autocomplete.java

/**
 * @see java.lang.Runnable#run()//from  w  w  w  .j ava2s .  c om
 */
public void run() {
    IndexEngineApi api = (IndexEngineApi) ctx().getAttribute("api");
    HttpServletResponse res = res();

    String characterEncoding = api.getCharacterEncoding();
    try {
        req().setCharacterEncoding(characterEncoding);
        res.setCharacterEncoding(characterEncoding);
        res.setContentType("application/json");
    } catch (UnsupportedEncodingException ignored) {
    }

    String query = params("query");
    String field = params("field");
    String callback = params("callback");

    if (field == null || field.isEmpty()) {
        field = "text";
    }

    List<String> complete = api.complete(query, field);

    JSONObject json = new JSONObject();
    json.put("query", query);
    json.put("suggestions", complete);

    if (callback != null && !callback.trim().isEmpty()) {
        print(callback.trim() + "(" + json.toJSONString() + ")");
    } else {
        print(json.toJSONString());
    }

}

From source file:com.conwet.silbops.msg.ContextMsg.java

@Override
@SuppressWarnings("unchecked")
public JSONObject getPayloadAsJSON() {

    JSONObject json = new JSONObject();
    json.put("context", context.toJSON());
    json.put("id", id);

    return json;//www .ja v a2 s. com
}

From source file:control.ProcesoVertimientosServlets.SeleccionarTasaRetributiva.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request// w w  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 jsonObject1 = new JSONObject();
    try {
        int codigoProceso = Integer.parseInt(request.getParameter("codigoProceso"));
        ProgramarMonitoreo manager = new ProgramarMonitoreo();
        jsonObject1 = manager.getTasaRetributiva(codigoProceso);

        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");
        response.getWriter().write(jsonObject1.toString());

    } catch (SQLException ex) {

    }

}

From source file:control.ParametrizacionServlets.InsertarUnidadesMedida.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from   www  . 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 {

    JSONObject respError = new JSONObject();

    try {

        //Obtenemos los datos enviados.
        String descripcion = request.getParameter("descripcion");

        //Creamos el manager para registrar la informacion
        UnidadesMedida manager = new UnidadesMedida();
        respError = manager.insertar(descripcion);

        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");
        response.getWriter().write(respError.toString());

    } catch (Exception ex) {
        //Armamos la respuesta JSON y la enviamos
        response.setContentType("application/json");
        respError.put("error", 0);
        response.getWriter().write(respError.toString());
    }

}