final Session session = request.getResourceResolver().adaptTo(Session.class);
if(session == null) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "ResourceResolver does not adapt to a Session");
return;
}
final JobStatus j = jobConsole.getJobStatus(session, request.getResource().getPath());
final JobStatus.State oldState = j.getState();
j.requestStateChange(desiredState);
final JobStatus.State newState = j.getState();
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
final JSONWriter w = new JSONWriter(response.getWriter());
try {
w.object();
w.key("info").value("Requested state change");
w.key(PARAM_STATE).value(desiredState.toString());
w.key("path").value(j.getPath());
w.key("currentState").value(newState);
w.key("stateChanged").value(newState != oldState);
w.endObject();
} catch(JSONException je) {
throw new ServletException("JSONException in doPost", je);