use of org.json.simple.parser.JSONParser 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.parser.JSONParser 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.parser.JSONParser 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.parser.JSONParser in project spatial-portal by AtlasOfLivingAustralia.
the class BiocacheQuery method retrieveCustomFacets.
/**
* Retrieves a list of custom facets for the supplied query.
*
* @return
*/
private List<QueryField> retrieveCustomFacets() {
List<QueryField> customFacets = new ArrayList<QueryField>();
//custom fields can only be retrieved with specific query types
String full = getFullQ(false);
Matcher match = Pattern.compile("data_resource_uid:\"??dr[t][0-9]+\"??").matcher(full);
if (!match.find()) {
return customFacets;
}
//look up facets
try {
final String jsonUri = biocacheServer + "/upload/dynamicFacets?q=" + URLEncoder.encode(match.group(), "UTF-8");
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(jsonUri);
get.addRequestHeader(StringConstants.CONTENT_TYPE, StringConstants.APPLICATION_JSON);
client.executeMethod(get);
String slist = get.getResponseBodyAsString();
JSONParser jp = new JSONParser();
JSONArray ja = (JSONArray) jp.parse(slist);
for (Object arrayElement : ja) {
JSONObject jsonObject = (JSONObject) arrayElement;
String facetName = jsonObject.get(StringConstants.NAME).toString();
String facetDisplayName = jsonObject.get("displayName").toString();
//TODO: remove this when _RNG fields work in legend &cm= parameter
if (!(facetDisplayName.contains("(Range)") && facetName.endsWith("_RNG"))) {
LOGGER.debug("Adding custom index : " + arrayElement);
customFacets.add(new QueryField(facetName, facetDisplayName, QueryField.GroupType.CUSTOM, QueryField.FieldType.STRING));
}
}
} catch (Exception e) {
LOGGER.error("error loading custom facets for: " + getFullQ(false), e);
}
return customFacets;
}
use of org.json.simple.parser.JSONParser in project spatial-portal by AtlasOfLivingAustralia.
the class BiocacheQuery method getQidDetails.
private JSONObject getQidDetails(String qidTerm) {
HttpClient client = new HttpClient();
String url = biocacheServer + QID_DETAILS + qidTerm.replace("qid:", "");
GetMethod get = new GetMethod(url);
try {
int result = client.executeMethod(get);
String response = get.getResponseBodyAsString();
if (result == 200) {
JSONParser jp = new JSONParser();
JSONObject jo = (JSONObject) jp.parse(response);
return jo;
} else {
LOGGER.debug("error with url:" + url + " getting qid details for " + qidTerm + " > response_code:" + result + " response:" + response);
}
} catch (Exception e) {
LOGGER.error("error getting biocache param details from " + url, e);
}
return null;
}
Aggregations