Example usage for org.json.simple JSONObject toString

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

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:com.netflix.raigad.resources.ElasticsearchConfig.java

@GET
@Path("/get_nodes")
public Response getNodes() {
    try {/*  w  ww. ja v a 2  s . com*/
        logger.info("Fetching nodes via get_nodes ...");
        final List<RaigadInstance> instances = raigadServer.getInstanceManager().getAllInstances();
        if (instances != null && !instances.isEmpty()) {
            JSONObject esCarJson = EsUtils.transformRaigadInstanceToJson(instances);
            return Response.ok(esCarJson.toString()).build();
        }
    } catch (Exception e) {
        logger.error("Error while executing get_nodes", e);
        return Response.serverError().build();
    }
    return Response.status(500).build();
}

From source file:com.hortonworks.amstore.view.proxy.RequestBuilder.java

public RequestBuilder setData(JSONObject data) {
    this.data = data.toString();
    return this;
}

From source file:gov.nih.nci.caintegrator.application.lists.ajax.CommonListFunctions.java

public static String uniteLists(String[] sLists, String groupName, String groupType, String action) {

    JSONObject res = new JSONObject();
    String results = "pass";

    UserListBeanHelper helper = new UserListBeanHelper();
    try {/*from  www .  j  a  va2 s.c o m*/
        List<String> al = Arrays.asList(sLists);
        if (action.equals("join")) {
            helper.uniteLists(al, groupName, ListType.valueOf(groupType));
        } else if (action.equalsIgnoreCase("difference")) {
            helper.differenceLists(al, groupName, ListType.valueOf(groupType));
        } else {
            if (helper.isIntersection(al)) {
                helper.intersectLists(al, groupName, ListType.valueOf(groupType));
            } else
                results = "fail";
        }
    } catch (Exception e) {
        results = "fail";
    }
    res.put("results", results);
    res.put("groupType", groupType);
    res.put("action", action);

    return res.toString();
}

From source file:au.org.paperminer.db.PublisherHelper.java

/**
 * Get general Info about a publisher/*  w  w w  .ja va 2s.c o  m*/
 * @param id
 * @return info as JSON array using table column names as keys
 * @throws PaperMinerException
 */
public String getInfo(String id) throws PaperMinerException {
    String res = "";
    HashMap<String, String> data = getRecord(id);
    if (data != null) {
        JSONObject obj = new JSONObject();
        obj.putAll(data);
        res = obj.toString();
    }
    return res;
}

From source file:control.UsuariosServlets.ActualizarUsuarios.java

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

    Integer respuesta = 0;

    try {
        String usuario = request.getParameter("descripcion");
        Integer rol = Integer.parseInt(request.getParameter("rol"));
        Integer codigo = Integer.parseInt(request.getParameter("codigo"));

        Usuarios manager = new Usuarios();
        respuesta = manager.actualizarUsuarios(usuario, rol, codigo);

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

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("error", respuesta);
        response.getWriter().write(jsonObject.toString());

    } catch (Exception ex) {

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

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("error", respuesta);
        response.getWriter().write(jsonObject.toString());
    }
}

From source file:control.UsuariosServlets.InsertarUsuario.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//w w  w . jav a2 s  .  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 {

    Integer respuesta = 0;

    try {
        String usuario = request.getParameter("descripcion");
        Integer rol = Integer.parseInt(request.getParameter("rol"));

        Usuarios manager = new Usuarios();
        respuesta = manager.insertarUsuarios(usuario, rol);

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

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("error", respuesta);
        response.getWriter().write(jsonObject.toString());

    } catch (Exception ex) {

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

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("error", respuesta);
        response.getWriter().write(jsonObject.toString());
    }

}

From source file:org.matmaul.freeboxos.internal.RestManager.java

public HttpEntity createJsonEntity(JSONObject jsonObj) {
    return new StringEntity(jsonObj.toString(), ContentType.APPLICATION_JSON);
}

From source file:control.ParametrizacionServlets.SeleccionarAsociacionContratos.java

/**
 * /*from   w  ww  . j a v a  2  s . c o m*/
 * Llama al manager y obtiene la informacion de una actividad
 * economica especifica.
 * 
 * @param request
 * @param response 
 */
private void getAsociacion(HttpServletRequest request, HttpServletResponse response) {

    try {

        //Obtenemos los parametros
        int contrato = Integer.parseInt(request.getParameter("contrato"));

        //Obtenemos La informacion del manager
        AsociacionContratos manager = new AsociacionContratos();
        JSONObject jsonArray = manager.getAsociacion(contrato);
        String jsonString = jsonArray.toString();

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

    } catch (Exception ex) {
        //Logger.getLogger(SeleccionarActEconomica.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.intuit.tweetstest.TweetsController.java

protected void sendResponse(HttpServletResponse response, JSONObject result) throws IOException {
    response.setCharacterEncoding("UTF-8");
    String resultStr = result.toString();
    response.setContentType("application/json");
    response.getWriter().print(resultStr);
}

From source file:control.ParametrizacionServlets.SeleccionarPuntoVertimientoContrato.java

/**
 * /*from w ww  .ja  va  2s  .  c  o m*/
 * Llama al manager y obtiene la informacion de una actividad
 * economica especifica.
 * 
 * @param request
 * @param response 
 */
private void getPuntoVertimiento(HttpServletRequest request, HttpServletResponse response) {

    try {

        //Obtenemos los parametros
        String codigo = request.getParameter("codigo");

        //Obtenemos La informacion del manager
        PuntosVertimiento manager = new PuntosVertimiento();
        JSONObject jsonArray = manager.getPuntoVertimiento(codigo);
        String jsonString = jsonArray.toString();

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

    } catch (Exception ex) {
        //Logger.getLogger(SeleccionarActEconomica.class.getName()).log(Level.SEVERE, null, ex);
    }
}