use of org.json.simple.parser.ParseException in project OpenGrok by OpenGrok.
the class StatsMessageTest method testGetValidJson.
@Test
public void testGetValidJson() {
testGet();
Message m = new StatsMessage();
m.setText("get");
byte[] out = null;
try {
out = m.apply(env);
} catch (Exception ex) {
Assert.fail("Should not throw any exception");
}
JSONParser p = new JSONParser();
Object o = null;
try {
o = p.parse(new String(out));
} catch (ParseException ex) {
Assert.fail("Should not throw any exception");
}
Assert.assertNotNull(o);
Statistics stat = Statistics.from((JSONObject) o);
Assert.assertTrue(stat instanceof Statistics);
Assert.assertEquals(1, stat.getRequests());
Assert.assertEquals(1, stat.getMinutes());
Assert.assertEquals(0, stat.getRequestCategories().size());
Assert.assertEquals(0, stat.getTiming().size());
}
use of org.json.simple.parser.ParseException in project OpenGrok by OpenGrok.
the class WebappListener method contextInitialized.
/**
* {@inheritDoc}
*/
@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
ServletContext context = servletContextEvent.getServletContext();
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
String config = context.getInitParameter("CONFIGURATION");
if (config == null) {
LOGGER.severe("CONFIGURATION section missing in web.xml");
} else {
try {
env.readConfiguration(new File(config));
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "OpenGrok Configuration error. Failed to read config file: ", ex);
}
}
/**
* Create a new instance of authorization framework. If the code above
* (reading the configuration) failed then the plugin directory is
* possibly {@code null} causing the framework to allow every request.
*/
env.setAuthorizationFramework(new AuthorizationFramework(env.getPluginDirectory(), env.getPluginStack()));
env.getAuthorizationFramework().reload();
String address = context.getInitParameter("ConfigAddress");
if (address != null && address.length() > 0) {
LOGGER.log(Level.CONFIG, "Will listen for configuration on [{0}]", address);
String[] cfg = address.split(":");
if (cfg.length == 2) {
try {
SocketAddress addr = new InetSocketAddress(InetAddress.getByName(cfg[0]), Integer.parseInt(cfg[1]));
if (!RuntimeEnvironment.getInstance().startConfigurationListenerThread(addr)) {
LOGGER.log(Level.SEVERE, "OpenGrok: Failed to start configuration listener thread");
}
} catch (NumberFormatException | UnknownHostException ex) {
LOGGER.log(Level.SEVERE, "OpenGrok: Failed to start configuration listener thread:", ex);
}
} else {
LOGGER.log(Level.SEVERE, "Incorrect format for the configuration address: ");
for (int i = 0; i < cfg.length; ++i) {
LOGGER.log(Level.SEVERE, "[{0}]", cfg[i]);
}
}
}
try {
RuntimeEnvironment.getInstance().loadStatistics();
} catch (IOException ex) {
LOGGER.log(Level.INFO, "Could not load statistics from a file.", ex);
} catch (ParseException ex) {
LOGGER.log(Level.SEVERE, "Could not parse statistics from a file.", ex);
}
if (env.getConfiguration().getPluginDirectory() != null && env.isAuthorizationWatchdog()) {
RuntimeEnvironment.getInstance().startWatchDogService(new File(env.getConfiguration().getPluginDirectory()));
}
RuntimeEnvironment.getInstance().startExpirationTimer();
try {
RuntimeEnvironment.getInstance().loadStatistics();
} catch (IOException ex) {
LOGGER.log(Level.INFO, "Could not load statistics from a file.", ex);
} catch (ParseException ex) {
LOGGER.log(Level.SEVERE, "Could not parse statistics from a file.", ex);
}
}
use of org.json.simple.parser.ParseException in project scheduling by ow2-proactive.
the class JobKeyValueTransformer method transformVariablesToMap.
public Map<String, String> transformVariablesToMap(String jsonVariables) {
Map<String, String> jobVariables = Maps.newHashMap();
if (jsonVariables != null) {
try {
jobVariables = (JSONObject) new JSONParser().parse(jsonVariables);
validateJSONVariables(jobVariables);
} catch (ParseException | IllegalArgumentException e) {
throw new CLIException(REASON_INVALID_ARGUMENTS, e.getMessage() + USAGE);
}
}
return jobVariables;
}
use of org.json.simple.parser.ParseException in project Rubicon by Rubicon-Bot.
the class MojangUtil method fromName.
public MinecraftPlayer fromName(String name) {
HashMap<String, Date> history = new HashMap<>();
try {
JSONArray data = (JSONArray) new JSONParser().parse(fetchNameHistory(fetchUUID(name)));
if (data.size() != 0) {
data.remove(0);
data.forEach(d -> {
JSONObject object = (JSONObject) d;
history.put(object.get("name").toString(), new Date(Long.parseLong(object.get("changedToAt").toString())));
});
}
} catch (ParseException e) {
Logger.error(e);
}
return new MinecraftPlayer(fetchUUID(name), fetchName(name), history, fetchFirstNamme(fetchUUID(name)));
}
use of org.json.simple.parser.ParseException in project Rubicon by Rubicon-Bot.
the class MojangUtil method fromUUID.
public MinecraftPlayer fromUUID(String uuid) {
try {
JSONArray data = (JSONArray) new JSONParser().parse(fetchNameHistory(uuid));
String name = ((JSONObject) data.get(data.size() - 1)).get("name").toString();
return fromName(name);
} catch (ParseException e) {
Logger.error(e);
return null;
}
}
Aggregations