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;
}
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;
}
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");
}
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;
}
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);
}
}
Aggregations