Search in sources :

Example 51 with ParseException

use of org.json.simple.parser.ParseException in project opennms by OpenNMS.

the class ElasticSearchInitialiser method init.

public void init() {
    if (getTemplateFiles().isEmpty()) {
        LOG.info("ElasticSearcInitialiser started with no default template files");
        initialised.set(true);
        return;
    }
    // load all files and test if JSON is OK
    for (String templateName : getTemplateFiles().keySet()) {
        String fileName = getTemplateFiles().get(templateName);
        LOG.info("   elasticsearch intialiser loading index template '" + templateName + "' from file " + fileName);
        try {
            StringBuffer body = new StringBuffer();
            BufferedReader is = new BufferedReader(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(fileName)));
            String l;
            while ((l = is.readLine()) != null) {
                body.append(l);
            }
            JSONParser parser = new JSONParser();
            JSONObject jsonObject = null;
            try {
                Object obj = parser.parse(body.toString());
                jsonObject = (JSONObject) obj;
                loadedFiles.put(templateName, body);
                LOG.debug("Loaded Template File" + "\n     fileName: '" + fileName + "'\n     templateName: '" + templateName + "'\n     contents: " + jsonObject.toJSONString());
            } catch (ParseException e1) {
                throw new RuntimeException("cannot parse json Elasticsearch template mapping from file " + fileName, e1);
            }
        } catch (Exception e) {
            throw new RuntimeException("Problem reading Elasticsearch template mapping fileName=" + fileName, e);
        }
    }
    LOG.debug("ElasticSearcInitialiser loaded template files. Trying to send templates to to ES");
    // start initialiser thread
    initialiserIsRunning.set(true);
    esInitialiserThread.start();
}
Also used : InputStreamReader(java.io.InputStreamReader) JSONObject(org.json.simple.JSONObject) BufferedReader(java.io.BufferedReader) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) ParseException(org.json.simple.parser.ParseException) ParseException(org.json.simple.parser.ParseException)

Example 52 with ParseException

use of org.json.simple.parser.ParseException in project opennms by OpenNMS.

the class MattermostNotificationStrategyTestServlet method doPost.

@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
    if (!"application/json".equals(req.getContentType())) {
        squawk(resp, "Invalid content type " + req.getContentType());
    }
    m_inputJson = null;
    JSONParser jp = new JSONParser();
    try {
        Object inStuff = jp.parse(req.getReader());
        if (inStuff instanceof JSONObject) {
            m_inputJson = (JSONObject) inStuff;
        }
    } catch (ParseException e1) {
        squawk(resp, "Input is not well-formed JSON");
        return;
    }
    if ((!m_inputJson.containsKey("text")) || "".equals(m_inputJson.get("text"))) {
        squawk(resp, "No text specified");
        return;
    }
    if ((!m_inputJson.containsKey("username")) || "".equals(m_inputJson.get("username"))) {
        squawk(resp, "No username specified");
        return;
    }
    final String responseText = "ok";
    final ServletOutputStream os = resp.getOutputStream();
    os.print(responseText);
    os.close();
    resp.setContentType("text/plain");
    resp.setContentLength(responseText.length());
}
Also used : JSONObject(org.json.simple.JSONObject) ServletOutputStream(javax.servlet.ServletOutputStream) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) ParseException(org.json.simple.parser.ParseException)

Example 53 with ParseException

use of org.json.simple.parser.ParseException in project local-data-aragopedia by aragonopendata.

the class EldaTest method testJSONURI.

private boolean testJSONURI(String URI, String test) {
    String content = null;
    String next = null;
    JSONParser parser = new JSONParser();
    try {
        content = Utils.processURLGet(URI);
    } catch (IOException e) {
        log.error("Error in URL " + URI, e);
        return false;
    }
    try {
        parser.parse(content);
        JSONObject json = (JSONObject) parser.parse(content);
        if (!validateJSON(json, test)) {
            log.error("Error in URI " + URI);
            return false;
        }
        JSONObject result = (JSONObject) json.get("result");
        //        	JSONArray items = (JSONArray) result.get("items");
        //        	for(int h=0;h<items.size();h++){
        //        		JSONObject item=(JSONObject) items.get(h);
        //				String about=(String)item.get(search);
        //				if(Utils.validValue(about)){
        //					listResult.add(replaceURI(about)+".json");
        //				}
        //			}
        next = (String) result.get("next");
        if (next != null) {
            testJSONURI(next, test);
        }
    } catch (ParseException e) {
        log.error("Error in URI " + next, e);
        return false;
    }
    return true;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) IOException(java.io.IOException) ParseException(org.json.simple.parser.ParseException)

Example 54 with ParseException

use of org.json.simple.parser.ParseException in project local-data-aragopedia by aragonopendata.

the class EldaTest method getDataJSONURI.

//	http://alzir.dia.fi.upm.es/recurso/iaest/dsd.json
private ArrayList<String> getDataJSONURI(String URI, String search, ArrayList<String> listResult) {
    if (listResult == null) {
        listResult = new ArrayList<String>();
    }
    String content = null;
    String next = null;
    JSONParser parser = new JSONParser();
    try {
        content = Utils.processURLGet(URI);
    } catch (IOException e) {
        log.error("Error process URL " + URI, e);
        return null;
    }
    try {
        JSONObject json = (JSONObject) parser.parse(content);
        JSONObject result = (JSONObject) json.get("result");
        JSONArray items = (JSONArray) result.get("items");
        for (int h = 0; h < items.size(); h++) {
            JSONObject item = (JSONObject) items.get(h);
            String about = (String) item.get(search);
            if (Utils.v(about)) {
                listResult.add(replaceURI(about) + ".json");
            }
        }
        next = (String) result.get("next");
        if (next != null) {
            getDataJSONURI(next, search, listResult);
        }
    } catch (ParseException e) {
        log.error("Error in data " + next, e);
        return null;
    }
    return listResult;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) IOException(java.io.IOException) ParseException(org.json.simple.parser.ParseException)

Example 55 with ParseException

use of org.json.simple.parser.ParseException in project Gargoyle by callakrsos.

the class SVNInitLoader method load.

@Override
public <T extends SVNItem> List<T> load() {
    String jsonArray = ResourceLoader.getInstance().get(ResourceLoader.SVN_REPOSITORIES);
    if (jsonArray == null || jsonArray.length() == 0)
        return null;
    JSONArray parse = null;
    try {
        parse = (JSONArray) new JSONParser().parse(jsonArray);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    List<SVNRepository> repositorys = new ArrayList<>();
    int size = parse.size();
    for (int i = 0; i < size; i++) {
        Object obj = parse.get(i);
        JSONObject jsonObject = (JSONObject) obj;
        Object url = jsonObject.get(SVNTreeView.SVN_URL);
        Object id = jsonObject.get(SVNTreeView.SVN_USER_ID);
        Object pass = jsonObject.get(SVNTreeView.SVN_USER_PASS);
        if (url == null)
            continue;
        Properties properties = new Properties();
        properties.put(SVNTreeView.SVN_URL, url.toString());
        if (id != null && !id.toString().isEmpty())
            properties.put(SVNTreeView.SVN_USER_ID, id.toString());
        if (pass != null && !pass.toString().isEmpty()) {
            try {
                properties.put(SVNTreeView.SVN_USER_PASS, EncrypUtil.decryp(pass.toString()));
            } catch (Exception e) {
                properties.put(SVNTreeView.SVN_USER_PASS, pass.toString());
                ValueUtil.toString(e);
            }
        }
        JavaSVNManager manager = new JavaSVNManager(properties);
        SVNRepository svnRepository = new SVNRepository("", url.toString(), manager);
        repositorys.add(svnRepository);
    }
    return (List<T>) repositorys;
}
Also used : JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ParseException(org.json.simple.parser.ParseException) JavaSVNManager(com.kyj.scm.manager.svn.java.JavaSVNManager) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) SVNRepository(com.kyj.fx.voeditor.visual.component.scm.SVNRepository) JSONObject(org.json.simple.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(org.json.simple.parser.ParseException)

Aggregations

ParseException (org.json.simple.parser.ParseException)64 JSONObject (org.json.simple.JSONObject)41 JSONParser (org.json.simple.parser.JSONParser)39 HashMap (java.util.HashMap)18 JSONArray (org.json.simple.JSONArray)18 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 List (java.util.List)7 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)7 InputStreamReader (java.io.InputStreamReader)6 File (java.io.File)5 MapLayer (au.org.emii.portal.menu.MapLayer)4 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)4 MapLayerMetadata (au.org.emii.portal.menu.MapLayerMetadata)3 BufferedReader (java.io.BufferedReader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 URL (java.net.URL)3 LocalDateTime (java.time.LocalDateTime)3