use of com.serotonin.json.JsonException in project ma-core-public by infiniteautomation.
the class StatusServlet method doGet.
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
IMangoLifecycle lifecycle = Providers.get(IMangoLifecycle.class);
String timeString = request.getParameter("time");
long time = -1;
if (timeString != null) {
try {
time = Long.parseLong(timeString);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
response.setContentType("application/json;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
response.setHeader("Access-Control-Allow-Origin", "*");
// Get the Info and pack it up
Map<String, Object> data = new HashMap<String, Object>();
StringWriter sw = new StringWriter();
JsonWriter writer = new JsonWriter(Common.JSON_CONTEXT, sw);
// Limit to logged in users while running
if ((lifecycle.getLifecycleState() != IMangoLifecycle.RUNNING) || (Common.getHttpUser() != null)) {
data.put("messages", LoggingConsoleRT.instance.getMessagesSince(time));
} else {
data.put("messages", new ArrayList<String>());
}
data.put("startupProgress", lifecycle.getStartupProgress());
data.put("shutdownProgress", lifecycle.getShutdownProgress());
data.put("state", getLifecycleStateMessage(lifecycle.getLifecycleState()));
// Can only get the Startup URI once the database is initalized
if (lifecycle.getLifecycleState() > IMangoLifecycle.DATABASE_INITIALIZE) {
Common.envProps.getBoolean("", false);
Boolean isSsl = Common.envProps.getBoolean("ssl.on", false);
String uri;
if (isSsl) {
int port = Common.envProps.getInt("ssl.port", 443);
uri = "https://" + request.getServerName() + ":" + port + DefaultPagesDefinition.getLoginUri(request, response);
} else {
uri = DefaultPagesDefinition.getLoginUri(request, response);
}
data.put("startupUri", uri);
}
try {
writer.writeObject(data);
response.getWriter().write(sw.toString());
} catch (JsonException e) {
LOG.error(e);
}
}
use of com.serotonin.json.JsonException in project ma-core-public by infiniteautomation.
the class ConvertingRenderer method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
// To ensure we have this property as it is a new one
if (jsonObject.containsKey("useUnitAsSuffix")) {
useUnitAsSuffix = jsonObject.getBoolean("useUnitAsSuffix");
}
String text = jsonObject.getString("unit");
if (text != null) {
try {
unit = UnitUtil.parseUcum(text);
} catch (Exception e) {
throw new TranslatableJsonException("emport.error.parseError", "unit");
}
}
text = jsonObject.getString("renderedUnit");
if (text != null) {
try {
renderedUnit = UnitUtil.parseUcum(text);
} catch (Exception e) {
throw new TranslatableJsonException("emport.error.parseError", "renderedUnit");
}
} else {
renderedUnit = unit;
}
}
use of com.serotonin.json.JsonException in project ma-core-public by infiniteautomation.
the class EmportDwr method export.
public static String export(Map<String, Object> data, int prettyIndent) {
StringWriter stringWriter = new StringWriter();
JsonWriter writer = new JsonWriter(Common.JSON_CONTEXT, stringWriter);
writer.setPrettyIndent(prettyIndent);
writer.setPrettyOutput(true);
try {
writer.writeObject(data);
return stringWriter.toString();
} catch (JsonException e) {
throw new ShouldNeverHappenException(e);
} catch (IOException e) {
throw new ShouldNeverHappenException(e);
}
}
use of com.serotonin.json.JsonException in project ma-core-public by infiniteautomation.
the class JsonDataVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
String json = jsonObject.getString("jsonData");
try {
jsonData = JsonDataDao.instance.readValueFromString(json);
} catch (Exception e) {
throw new TranslatableJsonException("emport.error.parseError", "jsonData");
}
}
use of com.serotonin.json.JsonException in project ma-core-public by infiniteautomation.
the class PopulateTest method main.
public static void main(String[] args) throws Exception {
context = new JsonContext();
context.addFactory(new ObjectFactory() {
@Override
public Object create(JsonValue jsonValue) throws JsonException {
if (jsonValue.toJsonObject().containsKey("sub1Value"))
return new Subclass1();
if (jsonValue.toJsonObject().containsKey("sub2Value"))
return new Subclass2();
throw new JsonException("Unknown BaseClass: " + jsonValue);
}
}, BaseClass.class);
test1();
test2();
}
Aggregations