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