Search in sources :

Example 1 with JSON

use of net.sf.json.JSON in project head by mifos.

the class DatabaseConfiguration method readVCAPConfiguration.

private void readVCAPConfiguration() throws ConfigurationException {
    final String vcapServicesVar = System.getenv(VCAP_SERVICES_VAR);
    if (vcapServicesVar != null) {
        // use database configuration from the system variable to replace the default config
        final JSONObject json = (JSONObject) JSONSerializer.toJSON(vcapServicesVar);
        String mysqlKey = null;
        @SuppressWarnings("rawtypes") final Iterator iterator = json.keys();
        while (iterator.hasNext()) {
            final String key = (String) iterator.next();
            if (key.startsWith("mysql")) {
                mysqlKey = key;
                break;
            }
        }
        if (mysqlKey == null) {
            throw new ConfigurationException(INVALID_STRUCTURE);
        }
        final JSON mysqlJson = (JSON) json.get(mysqlKey);
        JSONObject dbJson;
        if (mysqlJson.isArray()) {
            final JSONArray mysqlJsonArray = (JSONArray) mysqlJson;
            if (mysqlJsonArray.size() < 1) {
                throw new ConfigurationException(INVALID_STRUCTURE);
            }
            dbJson = (JSONObject) mysqlJsonArray.get(0);
        } else {
            dbJson = (JSONObject) mysqlJson;
        }
        final JSONObject credentialsJson = (JSONObject) dbJson.get("credentials");
        this.dbName = credentialsJson.getString("name");
        this.host = credentialsJson.getString("host");
        this.port = credentialsJson.getString("port");
        this.user = credentialsJson.getString("user");
        this.password = credentialsJson.getString("password");
        this.dbPentahoDW = credentialsJson.getString("dbPentahoDW");
    }
}
Also used : JSONObject(net.sf.json.JSONObject) ConfigurationException(org.mifos.config.exceptions.ConfigurationException) Iterator(java.util.Iterator) JSONArray(net.sf.json.JSONArray) JSON(net.sf.json.JSON)

Example 2 with JSON

use of net.sf.json.JSON in project tdi-studio-se by Talend.

the class Test method main.

/**
     * DOC wanghong Comment method "main".
     * 
     * @param args
     */
public static void main(String[] args) {
    try {
        File file = new File("D:/CLOUD_BPM_EE_MPX_generated.json");
        FileInputStream input = new FileInputStream(file);
        String jsonData = IOUtils.toString(input);
        XMLSerializer serializer = new XMLSerializer();
        JSON json = JSONSerializer.toJSON(jsonData);
        serializer.setRootName("JSONRoot");
        serializer.setTypeHintsEnabled(false);
        String xml = serializer.write(json);
        // System.out.println(xml);
        FileWriter writer = new FileWriter("D:/CLOUD.xml");
        writer.write(xml);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : XMLSerializer(net.sf.json.xml.XMLSerializer) FileWriter(java.io.FileWriter) JSON(net.sf.json.JSON) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with JSON

use of net.sf.json.JSON in project jmeter-plugins-manager by undera.

the class RepoTest method testAll.

public void testAll() throws IOException {
    Map<String, String> env = System.getenv();
    if (env.containsKey("TRAVIS")) {
        System.out.println("Not running test inside Travis CI");
        return;
    }
    List<String> problems = new ArrayList<>();
    File[] files = getRepoFiles();
    JSONArray merged = new JSONArray();
    for (File repoFile : files) {
        System.out.println("Checking repo: " + repoFile.getCanonicalPath());
        String content = new String(Files.readAllBytes(Paths.get(repoFile.getAbsolutePath())), "UTF-8");
        JSON json = JSONSerializer.toJSON(content, new JsonConfig());
        JSONArray list = (JSONArray) json;
        for (Object item : list) {
            JSONObject spec = (JSONObject) item;
            checkPlugin(problems, repoFile, spec);
            merged.add(spec);
        }
    }
    if (problems.size() > 0) {
        throw new AssertionFailedError(problems.toString());
    }
    try (PrintWriter out = new PrintWriter(new File(repo.getAbsolutePath() + s + "all.json"))) {
        out.print(merged.toString(1));
    }
}
Also used : JsonConfig(net.sf.json.JsonConfig) ArrayList(java.util.ArrayList) JSONArray(net.sf.json.JSONArray) JSON(net.sf.json.JSON) JSONObject(net.sf.json.JSONObject) JSONObject(net.sf.json.JSONObject) AssertionFailedError(junit.framework.AssertionFailedError) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 4 with JSON

use of net.sf.json.JSON in project jmeter-plugins-manager by undera.

the class PluginManager method load.

public synchronized void load() throws Throwable {
    detectJARConflicts();
    if (hasPlugins()) {
        return;
    }
    JSON json = jarSource.getRepo();
    if (!(json instanceof JSONArray)) {
        throw new RuntimeException("Result is not array");
    }
    for (Object elm : (JSONArray) json) {
        if (elm instanceof JSONObject) {
            Plugin plugin = Plugin.fromJSON((JSONObject) elm);
            if (plugin.getName().isEmpty()) {
                log.debug("Skip empty name: " + plugin);
                continue;
            }
            if (!plugin.isVirtual()) {
                plugin.detectInstalled(getInstalledPlugins());
            }
            allPlugins.put(plugin, plugin.isInstalled());
        } else {
            log.warn("Invalid array element: " + elm);
        }
    }
    // after all usual plugins detected, detect virtual sets
    for (Plugin plugin : allPlugins.keySet()) {
        if (plugin.isVirtual()) {
            plugin.detectInstalled(getInstalledPlugins());
            allPlugins.put(plugin, plugin.isInstalled());
        }
    }
    if (JMeterUtils.getPropDefault("jpgc.repo.sendstats", "true").equals("true")) {
        try {
            jarSource.reportStats(getUsageStats());
        } catch (Exception e) {
            log.debug("Failed to report usage stats", e);
        }
    }
    log.info("Plugins Status: " + getAllPluginsStatusString());
}
Also used : JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray) JSON(net.sf.json.JSON) JSONObject(net.sf.json.JSONObject) DownloadException(org.jmeterplugins.repository.exception.DownloadException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AccessDeniedException(java.nio.file.AccessDeniedException)

Example 5 with JSON

use of net.sf.json.JSON in project selenium_java by sergueik.

the class Comment method update.

/**
 * Updates the comment body with limited visibility.
 *
 * @param issue associated issue record
 * @param body Comment text
 * @param visType Target audience type (role or group)
 * @param visName Name of the role or group to limit visibility to
 *
 * @throws JiraException when the comment update fails
 */
public void update(String body, String visType, String visName) throws JiraException {
    JSONObject req = new JSONObject();
    req.put("body", body);
    if (visType != null && visName != null) {
        JSONObject vis = new JSONObject();
        vis.put("type", visType);
        vis.put("value", visName);
        req.put("visibility", vis);
    }
    JSON result = null;
    try {
        String issueUri = getBaseUri() + "issue/" + issueKey;
        result = restclient.put(issueUri + "/comment/" + id, req);
    } catch (Exception ex) {
        throw new JiraException("Failed add update comment " + id, ex);
    }
    if (!(result instanceof JSONObject)) {
        throw new JiraException("JSON payload is malformed");
    }
    deserialise((JSONObject) result);
}
Also used : JSONObject(net.sf.json.JSONObject) JSON(net.sf.json.JSON)

Aggregations

JSON (net.sf.json.JSON)50 JSONObject (net.sf.json.JSONObject)28 URISyntaxException (java.net.URISyntaxException)15 URI (java.net.URI)14 JSONArray (net.sf.json.JSONArray)14 IOException (java.io.IOException)9 XMLSerializer (net.sf.json.xml.XMLSerializer)8 ArrayList (java.util.ArrayList)6 PrintWriter (java.io.PrintWriter)5 JsonConfig (net.sf.json.JsonConfig)5 Writer (java.io.Writer)4 JiraException (net.rcarz.jiraclient.JiraException)4 File (java.io.File)3 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)2 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 FileWriter (java.io.FileWriter)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2