Search in sources :

Example 66 with JsonObject

use of org.json.simple.JsonObject in project tdi-studio-se by Talend.

the class OAuthClient method getSOAPEndpoint.

public static String getSOAPEndpoint(Token token, String version) throws MalformedURLException, IOException, ParseException {
    URLConnection idConn = new URL(token.getId()).openConnection();
    idConn.setRequestProperty("Authorization", "Bearer " + token.getAccess_token());
    String endpointURL = null;
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(idConn.getInputStream()));
        JSONParser jsonParser = new JSONParser();
        JSONObject json = (JSONObject) jsonParser.parse(reader);
        JSONObject urls = (JSONObject) json.get("urls");
        endpointURL = urls.get("partner").toString().replace("{version}", version);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException ignore) {
            }
        }
    }
    return endpointURL;
}
Also used : InputStreamReader(java.io.InputStreamReader) JSONObject(org.json.simple.JSONObject) BufferedReader(java.io.BufferedReader) JSONParser(org.json.simple.parser.JSONParser) IOException(java.io.IOException) URLConnection(java.net.URLConnection) URL(java.net.URL)

Example 67 with JsonObject

use of org.json.simple.JsonObject in project TotalFreedomMod by TotalFreedom.

the class Module_players method getResponse.

@Override
@SuppressWarnings("unchecked")
public NanoHTTPD.Response getResponse() {
    final JSONObject responseObject = new JSONObject();
    final JSONArray players = new JSONArray();
    final JSONArray superadmins = new JSONArray();
    final JSONArray telnetadmins = new JSONArray();
    final JSONArray senioradmins = new JSONArray();
    final JSONArray developers = new JSONArray();
    // All online players
    for (Player player : Bukkit.getOnlinePlayers()) {
        players.add(player.getName());
    }
    // Admins
    for (Admin admin : plugin.al.getActiveAdmins()) {
        final String username = admin.getName();
        switch(admin.getRank()) {
            case SUPER_ADMIN:
                superadmins.add(username);
                break;
            case TELNET_ADMIN:
                telnetadmins.add(username);
                break;
            case SENIOR_ADMIN:
                senioradmins.add(username);
                break;
        }
    }
    // Developers
    developers.addAll(FUtil.DEVELOPERS);
    responseObject.put("players", players);
    responseObject.put("superadmins", superadmins);
    responseObject.put("telnetadmins", telnetadmins);
    responseObject.put("senioradmins", senioradmins);
    responseObject.put("developers", developers);
    final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString());
    response.addHeader("Access-Control-Allow-Origin", "*");
    return response;
}
Also used : Player(org.bukkit.entity.Player) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) NanoHTTPD(me.totalfreedom.totalfreedommod.httpd.NanoHTTPD) Admin(me.totalfreedom.totalfreedommod.admin.Admin)

Example 68 with JsonObject

use of org.json.simple.JsonObject in project rest.li by linkedin.

the class ConfigRunner method main.

public static void main(String[] args) throws Exception {
    //get server configuration
    String path = new File(new File(".").getAbsolutePath()).getCanonicalPath() + "/src/main/d2Config/d2Config.json";
    JSONParser parser = new JSONParser();
    Object object = parser.parse(new FileReader(path));
    JSONObject json = (JSONObject) object;
    System.out.println("Finished parsing d2 topology config");
    String zkConnectString = (String) json.get("zkConnectString");
    int zkSessionTimeout = ((Long) json.get("zkSessionTimeout")).intValue();
    String zkBasePath = (String) json.get("zkBasePath");
    int zkRetryLimit = ((Long) json.get("zkRetryLimit")).intValue();
    Map<String, Object> serviceDefaults = (Map<String, Object>) json.get("defaultServiceProperties");
    //this contains the topology of our system
    Map<String, Object> clusterServiceConfigurations = (Map<String, Object>) json.get("d2Clusters");
    // 'comment' has no special meaning in json...
    clusterServiceConfigurations.remove("comment");
    System.out.println("Populating zookeeper with d2 configuration");
    //d2Config is the utility class for populating zookeeper with our topology
    //some the params are not needed for this simple example so we will just use
    //default value by passing an empty map
    D2Config d2Config = new D2Config(zkConnectString, zkSessionTimeout, zkBasePath, zkSessionTimeout, zkRetryLimit, (Map<String, Object>) Collections.EMPTY_MAP, serviceDefaults, clusterServiceConfigurations, (Map<String, Object>) Collections.EMPTY_MAP, (Map<String, Object>) Collections.EMPTY_MAP);
    //populate zookeeper
    d2Config.configure();
    System.out.println("Finished populating zookeeper with d2 configuration");
}
Also used : JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) FileReader(java.io.FileReader) D2Config(com.linkedin.d2.discovery.util.D2Config) File(java.io.File) Map(java.util.Map)

Example 69 with JsonObject

use of org.json.simple.JsonObject in project rest.li by linkedin.

the class ExampleD2Server method parseConfig.

private static JSONObject parseConfig() throws IOException, ParseException {
    String path = new File(new File(".").getAbsolutePath()).getCanonicalPath() + "/src/main/config/server.json";
    JSONParser parser = new JSONParser();
    Object object = parser.parse(new FileReader(path));
    return (JSONObject) object;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) FileReader(java.io.FileReader) File(java.io.File)

Example 70 with JsonObject

use of org.json.simple.JsonObject in project spatial-portal by AtlasOfLivingAustralia.

the class PhylogeneticDiversityListResults method evalArea.

private void evalArea(SelectedArea sa) {
    try {
        Query sq = QueryUtil.queryFromSelectedArea(selectedQuery, sa, null, false, null);
        CSVReader r = new CSVReader(new StringReader(sq.speciesList()));
        JSONArray ja = new JSONArray();
        for (String[] s : r.readAll()) {
            ja.add(s[1]);
        }
        //call pd with specieslist=ja.toString()
        String url = CommonData.getSettings().getProperty(CommonData.PHYLOLIST_URL) + "/phylo/getPD";
        NameValuePair[] params = new NameValuePair[2];
        params[0] = new NameValuePair("noTreeText", StringConstants.TRUE);
        params[1] = new NameValuePair("speciesList", ja.toString());
        JSONParser jp = new JSONParser();
        JSONArray pds = (JSONArray) jp.parse(Util.readUrlPost(url, params));
        Map<String, String> pdrow = new HashMap<String, String>();
        Map<String, JSONArray> speciesRow = new HashMap<String, JSONArray>();
        for (int j = 0; j < pds.size(); j++) {
            String tree = "" + ((JSONObject) pds.get(j)).get(StringConstants.STUDY_ID);
            pdrow.put(tree, ((JSONObject) pds.get(j)).get("pd").toString());
            speciesRow.put(tree, (JSONArray) ((JSONObject) pds.get(j)).get("taxaRecognised"));
            //maxPD retrieval
            String maxPd = ((JSONObject) pds.get(j)).get("maxPd").toString();
            for (int k = 0; k < selectedTrees.size(); k++) {
                if (((Map<String, String>) selectedTrees.get(k)).get(StringConstants.STUDY_ID).equals(tree)) {
                    ((Map<String, String>) selectedTrees.get(k)).put("maxPd", maxPd);
                }
            }
        }
        areaPds.add(pdrow);
        areaSpeciesMatches.add(speciesRow);
    } catch (Exception e) {
        LOGGER.error("failed processing a pd for a selected area.", e);
    }
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) Query(au.org.ala.spatial.util.Query) CSVReader(au.com.bytecode.opencsv.CSVReader) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) StringReader(java.io.StringReader) JSONParser(org.json.simple.parser.JSONParser)

Aggregations

JSONObject (org.json.simple.JSONObject)961 Test (org.junit.Test)312 JSONArray (org.json.simple.JSONArray)232 JSONParser (org.json.simple.parser.JSONParser)164 Map (java.util.Map)97 HashMap (java.util.HashMap)91 IOException (java.io.IOException)84 ArrayList (java.util.ArrayList)75 ParseException (org.json.simple.parser.ParseException)60 HttpClient (org.apache.commons.httpclient.HttpClient)39 File (java.io.File)38 List (java.util.List)38 BlockchainTest (org.xel.BlockchainTest)34 GetMethod (org.apache.commons.httpclient.methods.GetMethod)30 HttpURLConnection (java.net.HttpURLConnection)27 Tuple (org.apache.storm.tuple.Tuple)23 Transaction (org.xel.Transaction)23 APICall (org.xel.http.APICall)23 InputStreamReader (java.io.InputStreamReader)22 WriterConfiguration (org.apache.metron.common.configuration.writer.WriterConfiguration)22