Search in sources :

Example 16 with JSONParser

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;
}
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 17 with JSONParser

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");
}
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 18 with JSONParser

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;
}
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 19 with JSONParser

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;
}
Also used : QueryField(au.org.ala.legend.QueryField) JSONObject(org.json.simple.JSONObject) Matcher(java.util.regex.Matcher) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) LegendObject(au.org.ala.legend.LegendObject)

Example 20 with JSONParser

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;
}
Also used : JSONObject(org.json.simple.JSONObject) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JSONParser(org.json.simple.parser.JSONParser)

Aggregations

JSONParser (org.json.simple.parser.JSONParser)146 JSONObject (org.json.simple.JSONObject)136 JSONArray (org.json.simple.JSONArray)61 HttpClient (org.apache.commons.httpclient.HttpClient)44 ParseException (org.json.simple.parser.ParseException)40 GetMethod (org.apache.commons.httpclient.methods.GetMethod)34 Test (org.junit.Test)18 IOException (java.io.IOException)15 File (java.io.File)13 URL (java.net.URL)13 InputStreamReader (java.io.InputStreamReader)11 PostMethod (org.apache.commons.httpclient.methods.PostMethod)11 HashMap (java.util.HashMap)10 Map (java.util.Map)10 MapLayer (au.org.emii.portal.menu.MapLayer)9 Point (com.vividsolutions.jts.geom.Point)9 FileReader (java.io.FileReader)9 ArrayList (java.util.ArrayList)9 InputStream (java.io.InputStream)7 Facet (au.org.ala.legend.Facet)6