Example usage for org.json.simple JSONObject get

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

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

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

/**
 * Parses the incomming requests and process it accordingly.
 * @param msg/*from  w  w w  .  j av a2s.  c  o  m*/
 */
public static void onConRequest(String msg) {

    log.info("onConRequest called :" + msg);
    JSONParser parser = new JSONParser();
    try {

        Object obj = parser.parse(msg);
        JSONObject json = (JSONObject) obj;

        String action = (String) json.get("action");

        if (action.equals("start")) {

            onStartRequest(json);

        } else if (action.equals("stop")) {

            onStopRequest(json);

        } else if (action.equals("restart")) {

            onRestartRequest(json);

        } else if (action.equals("status")) {

            onStatusRequest(json);

        } else if (action.equals("readMSConfig")) {

            onReadMSConfig(json);

        } else if (action.equals("writeMSConfig")) {

            onWriteMSConfig(json);

        } else if (action.equals("deployRules")) {

            onDeployMSRules(json);

        }

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

}

From source file:de.minestar.minestarlibrary.utils.PlayerUtils.java

public static String getCurrentUUIDFromMojang(String oldName) {
    try {//from   w  w w.  j a v  a 2 s. com
        JSONObject object = getHTTPGetRequestAsObject(
                "https://api.mojang.com/users/profiles/minecraft/" + oldName + "?at=000000");
        return (String) object.get("id");
    } catch (Exception e) {
        JSONObject object = getHTTPGetRequestAsObject(
                "https://api.mojang.com/users/profiles/minecraft/" + oldName);
        return (String) object.get("id");
    }
}

From source file:de.minestar.minestarlibrary.utils.PlayerUtils.java

public static String getCurrentPlayerNameFromMojang(String oldName) {
    try {/*from w  w  w .jav a  2 s .  c  o m*/
        JSONObject object = getHTTPGetRequestAsObject(
                "https://api.mojang.com/users/profiles/minecraft/" + oldName + "?at=000000");
        return (String) object.get("name");
    } catch (Exception e) {
        JSONObject object = getHTTPGetRequestAsObject(
                "https://api.mojang.com/users/profiles/minecraft/" + oldName);
        return (String) object.get("name");
    }
}

From source file:com.fujitsu.dc.test.jersey.bar.BarInstallTestUtils.java

/**
 * Box??./*from   w w  w . j  ava2  s . c  o  m*/
 * @param location Location
 */
public static void waitBoxInstallCompleted(String location) {
    DcResponse response = null;
    JSONObject bodyJson = null;

    long startTime = System.currentTimeMillis();
    while (true) {
        response = ODataCommon.getOdataResource(location);
        if (HttpStatus.SC_OK == response.getStatusCode()) {
            bodyJson = (JSONObject) ((JSONObject) response.bodyAsJson());
            if (!ProgressInfo.STATUS.PROCESSING.value().equals(bodyJson.get("status"))) {
                return;
            }
            assertNull(bodyJson.get("installed_at"));
            assertNotNull(bodyJson.get("progress"));
            assertNotNull(bodyJson.get("started_at"));
        }
        if (System.currentTimeMillis() - startTime > BAR_INSTALL_TIMEOUT) {
            fail("Failed to bar file install: takes too much time. [" + BAR_INSTALL_TIMEOUT + "millis]");
        }
        try {
            Thread.sleep(BAR_INSTALL_SLEEP_TIME);
        } catch (InterruptedException e) {
            log.info("Interrupted: " + e.getMessage());
        }
    }

}

From source file:de.dailab.plistacontest.client.RecommenderItem.java

/**
 * Parse the ORP json Messages./*from   ww  w  .  j  a v a  2  s.c  om*/
 * 
 * @param _jsonMessageBody
 * @return the parsed values encapsulated in a map; null if an error has
 *         been detected.
 */
public static RecommenderItem parseItemUpdate(String _jsonMessageBody) {
    try {
        final JSONObject jsonObj = (JSONObject) JSONValue.parse(_jsonMessageBody);

        String itemID = jsonObj.get("id") + "";
        if ("null".equals(itemID)) {
            itemID = "0";
        }
        String domainID = jsonObj.get("domainid") + "";
        String text = jsonObj.get("text") + "";
        String flag = jsonObj.get("flag") + "";
        boolean recommendable = ("0".equals(flag));

        // parse date, now is default
        String createdAt = jsonObj.get("created_at") + "";
        Long created = System.currentTimeMillis();

        // maybe the field is called timeStamp instead of created_at
        if ("null".equals(createdAt)) {
            created = (Long) jsonObj.get("timestamp");
        } else {
            // parse the date string and derive the long date number
            try {
                SimpleDateFormat sdf;
                sdf = RecommenderItem.sdf.get();
                created = sdf.parse(createdAt).getTime();
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        RecommenderItem result = new RecommenderItem(null /* userID */, Long.valueOf(itemID),
                Long.valueOf(domainID), created);
        result.setText(text);
        result.setRecommendable(recommendable);
        return result;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:io.personium.test.jersey.bar.BarInstallTestUtils.java

/**
 * Box??.//from   w  w w .  j a v a 2 s  .  c o m
 * @param location Location
 */
public static void waitBoxInstallCompleted(String location) {
    PersoniumResponse response = null;
    JSONObject bodyJson = null;

    long startTime = System.currentTimeMillis();
    while (true) {
        response = ODataCommon.getOdataResource(location);
        if (HttpStatus.SC_OK == response.getStatusCode()) {
            bodyJson = (JSONObject) ((JSONObject) response.bodyAsJson());
            if (!ProgressInfo.STATUS.PROCESSING.value().equals(bodyJson.get("status"))) {
                return;
            }
            assertNull(bodyJson.get("installed_at"));
            assertNotNull(bodyJson.get("progress"));
            assertNotNull(bodyJson.get("started_at"));
        }
        if (System.currentTimeMillis() - startTime > BAR_INSTALL_TIMEOUT) {
            fail("Failed to bar file install: takes too much time. [" + BAR_INSTALL_TIMEOUT + "millis]");
        }
        try {
            Thread.sleep(BAR_INSTALL_SLEEP_TIME);
        } catch (InterruptedException e) {
            log.info("Interrupted: " + e.getMessage());
        }
    }

}

From source file:fr.bmartel.protocol.google.oauth.device.OauthForDeviceResponse.java

/**
 * convert json object api response to oaut device response java object
 * /*w  w  w  . j a v  a2 s.  c  o m*/
 * @param response
 * @return
 */
public static OauthForDeviceResponse decodeOauthForDeviceResponse(JSONObject response) {
    if (response != null) {
        if (response.containsKey(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_DEVICE_CODE)
                && response.containsKey(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_USER_CODE)
                && response.containsKey(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_VERIFICATION_URL)
                && response.containsKey(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_EXPIRING)
                && CommonUtils
                        .isInteger(response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_EXPIRING).toString())
                && response.containsKey(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_INTERVAL)
                && CommonUtils.isInteger(
                        response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_INTERVAL).toString())) {

            // build oauth device response
            return new OauthForDeviceResponse(
                    response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_DEVICE_CODE).toString(),
                    response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_USER_CODE).toString(),
                    response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_VERIFICATION_URL).toString(),
                    Integer.parseInt(
                            response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_EXPIRING).toString()),
                    Integer.parseInt(
                            response.get(OauthGoogleConstants.OAUTH_DEVICE_RESPONSE_INTERVAL).toString()));
        }
    }
    return null;
}

From source file:de.minestar.minestarlibrary.utils.PlayerUtils.java

public static String getUUIDFromMojang(String playerName) {
    JSONObject json = getHTTPGetRequestAsObject(
            "https://api.mojang.com/users/profiles/minecraft/" + playerName);
    if (json != null) {
        return (String) json.get("id");
    }//from  w w  w  .  ja  va2s .  c o  m
    return null;
}

From source file:com.apigee.edge.config.mavenplugin.KVMMojo.java

public static List getOrgKVM(ServerProfile profile) throws IOException {

    HttpResponse response = RestUtil.getOrgConfig(profile, "keyvaluemaps");
    if (response == null)
        return new ArrayList();
    JSONArray kvms = null;/*from  ww  w .  j  av a 2  s . c o  m*/
    try {
        logger.debug("output " + response.getContentType());
        // response can be read only once
        String payload = response.parseAsString();
        logger.debug(payload);

        /* Parsers fail to parse a string array.
         * converting it to an JSON object as a workaround */
        String obj = "{ \"kvms\": " + payload + "}";

        JSONParser parser = new JSONParser();
        JSONObject obj1 = (JSONObject) parser.parse(obj);
        kvms = (JSONArray) obj1.get("kvms");

    } catch (ParseException pe) {
        logger.error("Get KVM parse error " + pe.getMessage());
        throw new IOException(pe.getMessage());
    } catch (HttpResponseException e) {
        logger.error("Get KVM error " + e.getMessage());
        throw new IOException(e.getMessage());
    }

    return kvms;
}

From source file:com.apigee.edge.config.mavenplugin.KVMMojo.java

public static List getEnvKVM(ServerProfile profile) throws IOException {

    HttpResponse response = RestUtil.getEnvConfig(profile, "keyvaluemaps");
    if (response == null)
        return new ArrayList();
    JSONArray kvms = null;// ww w. ja  v  a 2  s .  c  om
    try {
        logger.debug("output " + response.getContentType());
        // response can be read only once
        String payload = response.parseAsString();
        logger.debug(payload);

        /* Parsers fail to parse a string array.
         * converting it to an JSON object as a workaround */
        String obj = "{ \"kvms\": " + payload + "}";

        JSONParser parser = new JSONParser();
        JSONObject obj1 = (JSONObject) parser.parse(obj);
        kvms = (JSONArray) obj1.get("kvms");

    } catch (ParseException pe) {
        logger.error("Get KVM parse error " + pe.getMessage());
        throw new IOException(pe.getMessage());
    } catch (HttpResponseException e) {
        logger.error("Get KVM error " + e.getMessage());
        throw new IOException(e.getMessage());
    }

    return kvms;
}