}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
ListChanges impl = factory.get();
if (acceptsJson(req)) {
impl.setFormat(OutputFormat.JSON_COMPACT);
}
if (paramParser.parse(impl, req, res)) {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
if (impl.getFormat().isJson()) {
buf.write(JSON_MAGIC);
}
Writer out = new BufferedWriter(new OutputStreamWriter(buf, "UTF-8"));
try {
impl.query(out);
} catch (QueryParseException e) {
res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
sendText(req, res, e.getMessage());
return;
} catch (OrmException e) {
log.error("Error querying /changes/", e);
res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
out.flush();
res.setContentType(impl.getFormat().isJson() ? JSON_TYPE : "text/plain");
res.setCharacterEncoding("UTF-8");
send(req, res, buf.toByteArray());
}
}