Example usage for org.json.simple JSONObject put

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

Introduction

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

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:com.iitb.cse.Utils.java

@SuppressWarnings("unchecked")

static String getApSettingsFileJson(String message) {
    JSONObject obj = new JSONObject();
    obj.put(Constants.action, Constants.sendApSettings);
    String[] apConf = message.split("\n");
    System.out.println(apConf.length);

    for (int i = 0; i < apConf.length; i++) {
        String[] apInfo = apConf[i].trim().split("=");
        if (apInfo[0].equalsIgnoreCase("USERNAME")) {

            if (apInfo.length == 1) {

                obj.put(Constants.username, "");
            } else {
                String _usrname = apInfo[1].trim();
                obj.put(Constants.username, _usrname);
            }//from   w w w  .j ava2 s.c  o  m

        } else if (apInfo[0].equalsIgnoreCase("PASSWORD")) {

            if (apInfo.length == 1) {
                //String _usrname = apInfo[1].trim();
                obj.put(Constants.password, "");
            } else {
                String _passwd = apInfo[1].trim();
                obj.put(Constants.password, _passwd);
            }

        } else if (apInfo[0].equalsIgnoreCase("BSSID")) {

            if (apInfo.length == 1) {
                obj.put(Constants.bssid, "");
            } else {
                String _bssid = apInfo[1].trim();
                obj.put(Constants.bssid, _bssid);
            }

        } else if (apInfo[0].equalsIgnoreCase("SSID")) {

            if (apInfo.length == 1) {
                obj.put(Constants.ssid, "");
            } else {
                String _ssid = apInfo[1].trim();
                obj.put(Constants.ssid, _ssid);
            }

        } else if (apInfo[0].equalsIgnoreCase("SECURITY")) {

            if (apInfo.length == 1) {
                obj.put("security", "");
            } else {
                String _sec = apInfo[1].trim();
                obj.put("security", _sec);
            }

        }
    }

    //obj.put(Constants.message,message);
    //   obj.put(Constants.textFileFollow, Boolean.toString(true));
    //   obj.put(Constants.serverTime, Long.toString(Calendar.getInstance().getTimeInMillis()));
    String jsonString = obj.toJSONString();
    System.out.println(jsonString);
    return jsonString;
}

From source file:com.fota.Link.sdpApi.java

public static String getCtnInfo(String ncn) throws JDOMException {
    String resultStr = "";
    String logData = "";
    try {/*from w  w  w.jav  a 2  s  .  c om*/
        String cpId = PropUtil.getPropValue("sdp3g.id");
        String cpPw = PropUtil.getPropValue("sdp3g.pw");
        String authorization = cpId + ":" + cpPw;
        logData = "\r\n---------- Get Ctn Req Info start ----------\r\n";
        logData += " getCtnRequestInfo - authorization : " + authorization;
        byte[] encoded = Base64.encodeBase64(authorization.getBytes());
        authorization = new String(encoded);

        String contractType = "0";
        String contractNum = ncn.substring(0, 9);
        String customerId = ncn.substring(10, ncn.length() - 1);

        JSONObject reqJObj = new JSONObject();
        reqJObj.put("transactionid", "");
        reqJObj.put("sequenceno", "");
        reqJObj.put("userid", "");
        reqJObj.put("screenid", "");
        reqJObj.put("CONTRACT_NUM", contractNum);
        reqJObj.put("CUSTOMER_ID", customerId);
        reqJObj.put("CONTRACT_TYPE", contractType);

        authorization = "Basic " + authorization;

        String endPointUrl = PropUtil.getPropValue("sdp.oif555.url");

        logData += "\r\n getCtnRequestInfo - endPointUrl : " + endPointUrl;
        logData += "\r\n getCtnRequestInfo - authorization(encode) : " + authorization;
        logData += "\r\n getCtnRequestInfo - Content-type : application/json";
        logData += "\r\n getCtnRequestInfo - RequestMethod : POST";
        logData += "\r\n getCtnRequestInfo - json : " + reqJObj.toString();
        logData += "\r\n---------- Get Ctn Req Info end ----------";

        logger.info(logData);

        // connection
        URL url = new URL(endPointUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        connection.setRequestProperty("Authorization", authorization);
        connection.setRequestProperty("Content-type", "application/json");

        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.connect();

        // output
        DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
        wr.writeBytes(reqJObj.toJSONString());
        wr.flush();
        wr.close();

        // input
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String inputLine = "";
        StringBuffer response = new StringBuffer();

        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }

        in.close();

        JSONParser jsonParser = new JSONParser();
        JSONObject respJsonObject = (JSONObject) jsonParser.parse(response.toString());

        //         String respTransactionId = (String) respJsonObject.get("transactionid");
        //         String respSequenceNo = (String) respJsonObject.get("sequenceno");
        //         String respReturnCode = (String) respJsonObject.get("returncode");
        //         String respReturnDescription = (String) respJsonObject.get("returndescription");
        //         String respErrorCode = (String) respJsonObject.get("errorcode");
        //         String respErrorDescription = (String) respJsonObject.get("errordescription");
        String respCtn = (String) respJsonObject.get("ctn");
        //         String respSubStatus = (String) respJsonObject.get("sub_status");
        //         String respSubStatusDate = (String) respJsonObject.get("sub_status_date");

        resultStr = respCtn;

        //resultStr = resValue;         
        //         resultStr = java.net.URLDecoder.decode(resultStr, "euc-kr");
        connection.disconnect();

    } catch (Exception e) {
        e.printStackTrace();
    }

    return resultStr;
}

From source file:net.modsec.ms.connector.ConnRequestHandler.java

/**
 * Checks the modsecurity current status whether its running or stopped.
 * @param json/*from w  w  w .  j av  a 2s .  c  om*/
 */
@SuppressWarnings("unchecked")
public static void onStatusRequest(JSONObject json) {

    log.info("onStatusRequest called.. : " + json.toJSONString());
    MSConfig config = MSConfig.getInstance();
    String cmd = config.getConfigMap().get("MSStatus");

    JSONObject resp = executeShScript(cmd, json);
    if (((String) resp.get("status")).equals("0")) {

        log.info("Message After Execution:" + (String) resp.get("message"));
        if (((String) resp.get("message")).contains("running")) {
            resp.put("msStatus", "1");
        } else {
            resp.put("msStatus", "0");
        }

    }

    log.info("Sending Json :" + resp.toJSONString());
    ConnectorService.getConnectorProducer().send(resp.toJSONString());
    resp.clear();

}

From source file:com.fujitsu.dc.test.jersey.box.acl.AclTest.java

/**
     * Role??./*from  ww  w .j a va 2 s .  co m*/
     * @param cellName ??
     * @param token 
     * @param roleName ??
     * @param code ?
     */
    @SuppressWarnings("unchecked")
    public static void createRole(final String cellName, final String token, final String roleName,
            final int code) {
        JSONObject body = new JSONObject();
        body.put("Name", roleName);

        TResponse res = Http.request("role-create.txt").with("token", token).with("cellPath", cellName)
                .with("body", body.toString()).returns();

        assertEquals(code, res.getStatusCode());

    }

From source file:com.maestrodev.maestrocontinuumplugin.ContinuumWorkerTest.java

@SuppressWarnings("unchecked")
private static JSONObject createContinuumFields() {
    JSONObject fields = new JSONObject();
    fields.put("host", "localhost");
    fields.put("port", 80);
    fields.put("username", "admin");
    fields.put("password", "admin0");
    fields.put("web_path", "/continuum");
    fields.put("use_ssl", false);
    fields.put(ContinuumWorker.CONTEXT_OUTPUTS, new JSONObject());

    JSONObject runOptions = new JSONObject();
    runOptions.put("username", RUN_USERNAME);
    fields.put("run_options", runOptions);

    return fields;
}

From source file:com.fujitsu.dc.test.utils.UserDataUtils.java

/**
 * ??????./*ww w .j a  v a  2 s. c o  m*/
 * @param token 
 * @param code ??
 * @param cell 
 * @param box 
 * @return ?
 */
@SuppressWarnings("unchecked")
public static TResponse create(String token, int code, String cell, String box) {
    JSONObject body = new JSONObject();
    body.put("__id", "auth_test");
    TResponse res = Http.request("box/odatacol/create.txt").with("cell", cell).with("box", box)
            .with("collection", "setodata").with("entityType", "Price")
            .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
            .with("token", "Bearer " + token).with("body", body.toJSONString()).returns().statusCode(code)
            .debug();
    return res;
}

From source file:com.fujitsu.dc.test.utils.UserDataUtils.java

/**
 * ??????.// w w w. j a  v  a  2s .c o m
 * @param token 
 * @param code ??
 * @return ?
 */
@SuppressWarnings("unchecked")
public static TResponse update(String token, int code) {
    JSONObject body = new JSONObject();
    body.put("__id", "auth_test");
    body.put("prop", "prop");
    TResponse res = Http.request("box/odatacol/update.txt").with("cell", "testcell1").with("box", "box1")
            .with("collection", "setodata").with("entityType", "Price").with("id", "auth_test")
            .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
            .with("token", token).with("ifMatch", "*").with("body", body.toJSONString()).returns()
            .statusCode(code).debug();
    return res;
}

From source file:com.fujitsu.dc.test.utils.UserDataUtils.java

/**
 * ?MERGE?????.//from w  w  w  .  j av a  2 s. co  m
 * @param token 
 * @param code ??
 * @return ?
 */
@SuppressWarnings("unchecked")
public static TResponse merge(String token, int code) {
    JSONObject body = new JSONObject();
    body.put("__id", "auth_test");
    body.put("prop", "prop");
    TResponse res = Http.request("box/odatacol/merge.txt").with("cell", "testcell1").with("box", "box1")
            .with("collection", "setodata").with("entityType", "Price").with("id", "auth_test")
            .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON)
            .with("token", token).with("ifMatch", "*").with("body", body.toJSONString()).returns()
            .statusCode(code).debug();
    return res;
}

From source file:com.fujitsu.dc.test.utils.UserDataUtils.java

/**
 * NP???????./* www .  j  ava  2  s .co m*/
 * @param token 
 * @param code ??
 * @return ?
 */
@SuppressWarnings("unchecked")
public static TResponse createViaNP(String token, int code) {
    JSONObject body = new JSONObject();
    body.put("__id", "npdata");
    TResponse res = Http.request("box/odatacol/createNP.txt").with("cell", "testcell1").with("box", "box1")
            .with("collection", "setodata").with("entityType", "Price").with("id", "auth_test")
            .with("navPropName", "_Sales").with("accept", MediaType.APPLICATION_JSON)
            .with("contentType", MediaType.APPLICATION_JSON).with("token", token)
            .with("body", body.toJSONString()).returns().statusCode(code).debug();

    return res;
}

From source file:at.ac.tuwien.dsg.quelle.cloudServicesModel.util.conversions.ConvertToJSON.java

public static String convertToJSON(MultiLevelRequirements multiLevelRequirements) {

    //traverse the tree to do the JSON properly
    List<JSONObject> jsontree = new ArrayList<JSONObject>();
    List<MultiLevelRequirements> multiLevelRequirementsTree = new ArrayList<MultiLevelRequirements>();

    JSONObject root = processMultiLevelRequirementsElement(multiLevelRequirements);

    jsontree.add(root);/*from www  . j a v a2  s . co  m*/
    multiLevelRequirementsTree.add(multiLevelRequirements);

    //traverse the tree in a DFS manner
    while (!multiLevelRequirementsTree.isEmpty()) {
        MultiLevelRequirements currentlyProcessed = multiLevelRequirementsTree.remove(0);
        JSONObject currentlyProcessedJSONObject = jsontree.remove(0);
        JSONArray childrenArray = new JSONArray();
        //process children
        for (MultiLevelRequirements child : currentlyProcessed.getContainedElements()) {
            JSONObject childJSON = processMultiLevelRequirementsElement(child);
            childrenArray.add(childJSON);

            //next to process are children
            jsontree.add(childJSON);
            multiLevelRequirementsTree.add(child);
        }
        if (currentlyProcessedJSONObject.containsKey("children")) {
            JSONArray array = (JSONArray) currentlyProcessedJSONObject.get("children");
            array.addAll(childrenArray);
        } else {
            currentlyProcessedJSONObject.put("children", childrenArray);
        }
    }

    return root.toJSONString();

}