Example usage for com.google.gson JsonObject JsonObject

List of usage examples for com.google.gson JsonObject JsonObject

Introduction

In this page you can find the example usage for com.google.gson JsonObject JsonObject.

Prototype

JsonObject

Source Link

Usage

From source file:au.edu.unsw.cse.soc.federatedcloud.curator.CuratorAPI.java

License:Open Source License

@Path("/putRule")
@POST//from   w  ww.  jav a  2 s  . c  om
@Produces(MediaType.APPLICATION_JSON)
public Response putRule(RecommendationRule rule) {
    persistRecommendationRule(rule);
    log.warn("Composite Resource handler is not yet implemented.");

    JsonObject ruleID = new JsonObject();
    ruleID.addProperty("ruleID", rule.getId());
    return Response.status(Response.Status.OK).entity(ruleID.toString()).build();
}

From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.s3.AWSS3Deployer.java

License:Open Source License

@Path("/deploy")
@POST/*from  w  w  w . j a  v a 2s.c  o  m*/
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
/*@Override*/
public Response deploy(@QueryParam("descriptionid") String descriptionid) throws Exception {
    //Reading the credentials
    Properties properties = new Properties();
    properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties"));
    String accessKey = properties.getProperty("accessKey");
    String secretKey = properties.getProperty("secretKey");

    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

    AmazonS3Client client = new AmazonS3Client(credentials);

    //String name = description.getAttributes().get("name");
    String name = "ddweerasiri-test-bucket";
    //client.createBucket(name);

    log.info("Bucket was created with name:" + name);
    System.out.println("Helooooooo:" + descriptionid);

    JsonObject json = new JsonObject();
    json.addProperty("cloudResourceDescriptionId", descriptionid);
    return Response.status(Response.Status.OK).entity(json.toString()).build();
}

From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.s3.ClassForPaper.java

License:Open Source License

@Path("/deployResource")
@POST//w w  w  .  jav  a 2 s . co m
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response deployResource(@QueryParam("description") CRCD resourceDescription) throws Exception {
    //Reading the credentials
    Properties properties = new Properties();
    properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties"));
    String accessKey = properties.getProperty("accessKey");
    String secretKey = properties.getProperty("secretKey");
    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    AmazonS3Client client = new AmazonS3Client(credentials);

    String name = resourceDescription.getAttribute("bucket-name");
    Bucket bucket = client.createBucket(name);

    JsonObject json = new JsonObject();
    json.addProperty("resourceID", bucket.getName());
    return Response.status(Response.Status.OK).entity(json.toString()).build();
}

From source file:au.edu.unsw.cse.soc.federatedcloud.deployers.aws.s3.ClassForPaper.java

License:Open Source License

@Path("/undeployResource")
@POST//w  w  w  . ja v  a 2 s . c  o m
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response undeployResource(@QueryParam("resourceID") String resourceID) throws Exception {
    //Reading the credentials
    Properties properties = new Properties();
    properties.load(this.getClass().getResourceAsStream("/AwsCredentials.properties"));
    String accessKey = properties.getProperty("accessKey");
    String secretKey = properties.getProperty("secretKey");
    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    AmazonS3Client client = new AmazonS3Client(credentials);

    client.deleteBucket(resourceID);

    JsonObject json = new JsonObject();
    json.addProperty("result", "Bucket:" + resourceID + "undeployed.");
    return Response.status(Response.Status.OK).entity(json.toString()).build();
}

From source file:bank.AddUpdateBankVoucher.java

private JsonObject saveVoucher(ArrayList<BankPaymentReceiptModel> detail) {
    final JsonObject jResultObj = new JsonObject();
    Connection dataConnection = null;
    if (dataConnection == null) {
        dataConnection = helper.getConnMpAdmin();
    }/*  ww w.jav  a 2 s. co  m*/
    if (dataConnection != null) {
        try {
            dataConnection.setAutoCommit(false);
            String sql = null;
            PreparedStatement psLocal = null;
            if (detail.get(0).getRef_no().equalsIgnoreCase("")) {
                sql = "INSERT INTO BPRHD (VDATE, TOT_BAL, USER_ID, CTYPE, BANK_CD,AC_CD,CHEQUE_NO,CHEQUE_DATE,branch_cd, OPP_BANK_NAME,REF_NO) "
                        + "VALUES (?, ?, ?, ?, ?, ?,?,?,?,?,?)";
                //            ref_no = lb.generateCPNo(type);
                if (detail.get(0).getType() == 0) {
                    detail.get(0).setRef_no(lb.generateKey(dataConnection, "BPRHD", "REF_NO", "BP", 7));
                } else {
                    detail.get(0).setRef_no(lb.generateKey(dataConnection, "BPRHD", "REF_NO", "BR", 7));
                }
            } else if (!detail.get(0).getRef_no().equalsIgnoreCase("")) {
                if (detail.get(0).getType() == 0) {
                    BankPaymentUpdate cp = new BankPaymentUpdate();
                    cp.deleteEntry(dataConnection, detail.get(0).getRef_no());
                } else if (detail.get(0).getType() == 1) {
                    BankReciept cr = new BankReciept();
                    cr.deleteEntry(dataConnection, detail.get(0).getRef_no());
                }
                sql = "DELETE FROM BPRDT WHERE REF_NO='" + detail.get(0).getRef_no() + "'";
                psLocal = dataConnection.prepareStatement(sql);
                psLocal.executeUpdate();

                sql = "DELETE FROM payment WHERE REF_NO='" + detail.get(0).getRef_no() + "'";
                psLocal = dataConnection.prepareStatement(sql);
                psLocal.executeUpdate();

                sql = "UPDATE BPRHD SET VDATE=?, TOT_BAL=?, USER_ID=?, CTYPE=?, BANK_CD=?,AC_CD=?,CHEQUE_NO=?,CHEQUE_DATE=?, "
                        + "EDIT_NO=EDIT_NO+1, TIME_STAMP=CURRENT_TIMESTAMP,branch_cd=?,OPP_BANK_NAME=? WHERE REF_NO=?";
            }
            psLocal = dataConnection.prepareStatement(sql);
            psLocal.setString(1, detail.get(0).getVdate());
            psLocal.setDouble(2, detail.get(0).getTot_amt());
            psLocal.setString(3, detail.get(0).getUser_id());
            psLocal.setInt(4, detail.get(0).getType());
            psLocal.setString(5, detail.get(0).getBank_cd());
            psLocal.setString(6, detail.get(0).getAc_cd());
            psLocal.setString(7, detail.get(0).getCheque_no());
            psLocal.setString(8, detail.get(0).getCheque_date());
            psLocal.setString(9, detail.get(0).getBranch_cd());
            psLocal.setString(10, detail.get(0).getParty_bank_name());
            psLocal.setString(11, detail.get(0).getRef_no());
            psLocal.executeUpdate();

            sql = "Update BPRHD set INIT_TIMESTAMP = TIME_STAMP where ref_no='" + detail.get(0).getRef_no()
                    + "'";
            psLocal = dataConnection.prepareStatement(sql);
            psLocal.executeUpdate();

            sql = "INSERT INTO BPRDT (SR_NO, DOC_REF_NO, BAL, REMARK, REF_NO) " + "VALUES (?, ?, ?, ?, ?)";
            psLocal = dataConnection.prepareStatement(sql);
            for (int i = 0; i < detail.size(); i++) {
                {
                    psLocal.setInt(1, i + 1);
                    psLocal.setString(2, detail.get(i).getDoc_ref_no());
                    psLocal.setDouble(3, detail.get(i).getAmt());
                    psLocal.setString(4, detail.get(i).getRemark());
                    psLocal.setString(5, detail.get(0).getRef_no());
                    psLocal.executeUpdate();

                    sql = "INSERT INTO PAYMENT (CASH_AMT, BANK_CD, BANK_NAME, BANK_BRANCH, CHEQUE_NO, CHEQUE_DATE, BANK_AMT, CARD_NAME, CARD_AMT, REF_NO,USER_ID,vou_date)"
                            + " VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
                    PreparedStatement pstLocal = dataConnection.prepareStatement(sql);
                    pstLocal.setDouble(1, 0.00);
                    pstLocal.setString(2, detail.get(0).getBank_cd());
                    pstLocal.setString(3, "");
                    pstLocal.setString(4, "");
                    pstLocal.setString(5, "");
                    pstLocal.setString(6, detail.get(0).getCheque_date());
                    if (detail.get(0).getType() == 0) {
                        pstLocal.setDouble(7, detail.get(0).getAmt() * -1);
                    } else {
                        pstLocal.setDouble(7, detail.get(0).getAmt());
                    }
                    pstLocal.setString(8, "");
                    pstLocal.setDouble(9, 0.00);
                    pstLocal.setString(10, detail.get(0).getRef_no());
                    pstLocal.setString(11, detail.get(0).getUser_id());
                    pstLocal.setString(12, detail.get(0).getVdate());
                    pstLocal.executeUpdate();

                }
            }

            if (detail.get(0).getType() == 0) {
                BankPaymentUpdate cp = new BankPaymentUpdate();
                cp.addEntry(dataConnection, detail.get(0).getRef_no());
            } else if (detail.get(0).getType() == 1) {
                BankReciept cr = new BankReciept();
                cr.addEntry(dataConnection, detail.get(0).getRef_no());
            }

            dataConnection.commit();
            dataConnection.setAutoCommit(true);
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
        } catch (SQLNonTransientConnectionException ex1) {
            ex1.printStackTrace();
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            ex.printStackTrace();
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
            try {
                dataConnection.rollback();
                dataConnection.setAutoCommit(true);
            } catch (Exception e) {
            }
        }
    }
    return jResultObj;
}

From source file:bank.BankDelete.java

private JsonObject saveVoucher(String ref_no, int type) {
    final JsonObject jResultObj = new JsonObject();
    Connection dataConnection = null;
    if (dataConnection == null) {
        dataConnection = helper.getConnMpAdmin();
    }//ww  w . j a v a 2 s  . c o m
    if (dataConnection != null) {
        try {
            String sql = "SELECT doc_ref_no FROM billadjst WHERE dr_doc_ref_no='" + ref_no
                    + "' OR cr_doc_ref_no='" + ref_no + "'";
            PreparedStatement pstLocal = dataConnection.prepareStatement(sql);
            ResultSet rsLocal = pstLocal.executeQuery();
            if (rsLocal.next()) {
                jResultObj.addProperty("result", -1);
                jResultObj.addProperty("Cause", "Voucher is in adjustment process");
            } else {
                dataConnection.setAutoCommit(false);
                PreparedStatement psLocal = null;
                if (type == 0) {
                    BankPaymentUpdate cp = new BankPaymentUpdate();
                    cp.deleteEntry(dataConnection, ref_no);
                } else if (type == 1) {
                    BankReciept cr = new BankReciept();
                    cr.deleteEntry(dataConnection, ref_no);
                }
                sql = "DELETE FROM BPRDT WHERE REF_NO='" + ref_no + "'";
                psLocal = dataConnection.prepareStatement(sql);
                psLocal.executeUpdate();

                sql = "DELETE FROM payment WHERE REF_NO='" + ref_no + "'";
                psLocal = dataConnection.prepareStatement(sql);
                psLocal.executeUpdate();

                sql = "delete from  BPRHD WHERE REF_NO=?";
                psLocal = dataConnection.prepareStatement(sql);
                psLocal.setString(1, ref_no);
                psLocal.executeUpdate();

                dataConnection.commit();
                dataConnection.setAutoCommit(true);
                jResultObj.addProperty("result", 1);
                jResultObj.addProperty("Cause", "success");
            }
        } catch (SQLNonTransientConnectionException ex1) {
            ex1.printStackTrace();
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            ex.printStackTrace();
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
            try {
                dataConnection.rollback();
                dataConnection.setAutoCommit(true);
            } catch (Exception e) {
            }
        }
    }
    return jResultObj;
}

From source file:bank.GetBankPaymentHeader.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  w  w  w.ja va  2s .  c o  m
 *
 * @param request servlet request
 * @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 {
    Connection dataConnection = null;

    final JsonObject jResultObj = new JsonObject();
    final String from_date = request.getParameter("from_date");
    final String to_date = request.getParameter("to_date");
    final String v_type = request.getParameter("v_type");
    final String branch_cd = request.getParameter("branch_cd");
    if (dataConnection == null) {
        dataConnection = helper.getConnMpAdmin();
    }

    if (dataConnection != null) {
        try {
            String sql = "select c.AC_CD,c.REF_NO,VDATE,a.FNAME,c1.BAL,c1.REMARK,c.cheque_no,c.branch_cd from bprhd c left join bprdt c1 on c.REF_NO=c1.REF_NO"
                    + " left join ACNTMST a on c.AC_CD=a.AC_CD where VDATE>=? and VDATE<=? and CTYPE=?  ";
            if (!branch_cd.equalsIgnoreCase("0")) {
                sql += " and branch_cd=" + branch_cd;
            }
            sql += " order by VDATE,ref_no";
            PreparedStatement pstLocal = dataConnection.prepareStatement(sql);
            pstLocal.setString(1, from_date);
            pstLocal.setString(2, to_date);
            pstLocal.setString(3, v_type);
            ResultSet rsLocal = pstLocal.executeQuery();
            JsonArray array = new JsonArray();
            while (rsLocal.next()) {
                JsonObject object = new JsonObject();
                object.addProperty("REF_NO", rsLocal.getString("REF_NO"));
                object.addProperty("VDATE", rsLocal.getString("VDATE"));
                object.addProperty("FNAME", rsLocal.getString("FNAME"));
                object.addProperty("BAL", rsLocal.getString("BAL"));
                object.addProperty("REMARK", rsLocal.getString("REMARK"));
                object.addProperty("AC_CD", rsLocal.getString("AC_CD"));
                object.addProperty("CHEQUE_NO", rsLocal.getString("CHEQUE_NO"));
                object.addProperty("BRANCH_CD", rsLocal.getString("BRANCH_CD"));
                array.add(object);
            }
            jResultObj.addProperty("result", 1);
            jResultObj.addProperty("Cause", "success");
            jResultObj.add("data", array);
        } catch (SQLNonTransientConnectionException ex1) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", "Server is down");
        } catch (SQLException ex) {
            jResultObj.addProperty("result", -1);
            jResultObj.addProperty("Cause", ex.getMessage());
        }
    }
    response.getWriter().print(jResultObj);
}

From source file:basic.BasicExample.java

License:Open Source License

public BasicExample() throws Exception {
    socket = new SocketIO();
    socket.connect("http://127.0.0.1:3001/", this);

    // Sends a string to the server.
    socket.send("Hello Server");

    // Sends a JSON object to the server.
    JsonObject json = new JsonObject();

    json.add("key", new JsonPrimitive("value"));
    json.add("key2", new JsonPrimitive("another value"));
    socket.send(json);/*w  w  w  . j av a  2s  .  c om*/

    // Emits an event to the server.
    socket.emit("event", "argument1", "argument2", 13.37);
}

From source file:be.bukkit.bungee.staffchat.BungeeMetricsLite.java

License:Open Source License

private void postPlugin(final boolean ping) throws IOException {
    // Create data object
    JsonObject jsonData = new JsonObject();

    // Plugin and server information
    jsonData.addProperty("guid", guid);
    jsonData.addProperty("plugin_version", plugin.getDescription().getVersion());
    jsonData.addProperty("server_version",
            plugin.getProxy().getVersion() + " (MC: " + plugin.getProxy().getGameVersion() + ')');

    jsonData.addProperty("auth_mode", plugin.getProxy().getConfig().isOnlineMode() ? 1 : 0);
    jsonData.addProperty("players_online", plugin.getProxy().getOnlineCount());

    // New data as of R6, system information
    jsonData.addProperty("osname", OS_NAME.value());
    String osArch = OS_ARCH.value();
    jsonData.addProperty("osarch", osArch.equals("amd64") ? "x86_64" : osArch);
    jsonData.addProperty("osversion", OS_VERSION.value());
    jsonData.addProperty("cores", Runtime.getRuntime().availableProcessors());
    jsonData.addProperty("java_version", JAVA_VERSION.value());

    if (ping)//from  w ww .ja  v a 2 s  . c om
        jsonData.addProperty("ping", 1);

    // Get json output from GSON
    String json = JSON.toJson(jsonData);

    // Open URL connection
    URL url = new URL(REPORT_URL + URLEncoder.encode(plugin.getDescription().getName(), "UTF-8"));
    URLConnection con = url.openConnection();

    byte[] data = json.getBytes(Charsets.UTF_8);
    byte[] gzip = null;

    try { // Compress using GZIP
        gzip = gzip(data);
    } catch (Exception ignored) {
    }

    // Add request headers
    con.addRequestProperty(USER_AGENT, "MCStats/" + REVISION);
    con.addRequestProperty(CONTENT_TYPE, "application/json");
    if (gzip != null) {
        con.addRequestProperty(CONTENT_ENCODING, "gzip");
        data = gzip;
    }

    con.addRequestProperty(CONTENT_LENGTH, String.valueOf(data.length));
    con.addRequestProperty(ACCEPT, "application/json");
    con.addRequestProperty(CONNECTION, "close");

    con.setDoOutput(true);

    // Write json data to the opened stream
    try (OutputStream out = con.getOutputStream()) {
        out.write(data);
        out.flush();
    }

    String response; // Read the response
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
        response = reader.readLine();
    }

    // Check for error
    if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
        if (response == null)
            response = "null";
        else if (response.startsWith("7"))
            response = response.substring(response.startsWith("7,") ? 2 : 1);
        throw new IOException(response);
    }
}

From source file:be.iminds.iot.dianne.builder.DianneBuilder.java

License:Open Source License

private void getAvailableModules(PrintWriter writer) {
    List<ModuleTypeDTO> moduleTypes = new ArrayList<ModuleTypeDTO>();
    synchronized (factories) {
        for (ModuleFactory f : factories) {
            moduleTypes.addAll(f.getAvailableModuleTypes());
        }/* www . j av  a 2  s . c  om*/
    }

    JsonArray jsonModules = new JsonArray();
    for (ModuleTypeDTO moduleType : moduleTypes) {
        JsonObject jsonModule = new JsonObject();
        jsonModule.add("type", new JsonPrimitive(moduleType.type));
        jsonModule.add("category", new JsonPrimitive(moduleType.category));
        if (moduleType.trainable) {
            jsonModule.add("trainable", new JsonPrimitive(true));
        }
        jsonModules.add(jsonModule);
    }
    writer.write(jsonModules.toString());
    writer.flush();
}