use of com.serotonin.json.JsonWriter in project ma-core-public by infiniteautomation.
the class EscapeTest method main.
public static void main(String[] args) throws Exception {
JsonContext context = new JsonContext();
context.setEscapeForwardSlash(true);
StringWriter out = new StringWriter();
JsonWriter writer = new JsonWriter(context, out);
writer.writeObject("stream://asdf");
String json = out.toString();
System.out.println(json);
JsonReader reader = new JsonReader(context, json);
String s = reader.read(String.class);
System.out.println(s);
}
use of com.serotonin.json.JsonWriter in project ma-core-public by infiniteautomation.
the class ExceptionTest method main.
public static void main(String[] args) throws Exception {
JsonContext context = new JsonContext();
context.addConverter(new ThrowableSerializingConverter(), Throwable.class);
StringWriter out = new StringWriter();
JsonWriter writer = new JsonWriter(context, out);
writer.setPrettyOutput(true);
writer.writeObject(createException1());
System.out.println(out);
JsonReader reader = new JsonReader(context, out.toString());
Throwable t = reader.read(Throwable.class);
System.out.println("Great success!");
System.out.println(t.getMessage());
t.printStackTrace();
}
use of com.serotonin.json.JsonWriter 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.JsonWriter 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.JsonWriter in project ma-core-public by infiniteautomation.
the class EventDetectorDao method writeValueAsString.
public String writeValueAsString(AbstractEventDetectorVO<?> value) throws JsonException, IOException {
StringWriter stringWriter = new StringWriter();
JsonWriter writer = new JsonWriter(Common.JSON_CONTEXT, stringWriter);
writer.writeObject(value);
return stringWriter.toString();
}
Aggregations