public void print(WebEngine engine, JSONObject request) {
JSONObject response = new JSONObject();
- response.put("msgid", request.get("msgid"));
- response.put("status", "200");
+ response.put("status", 200);
response.put("message", "OK");
try {
- long msgid = request.getLong("msgid");
- response.put("msgid", msgid);
+
+ response.put("clientid", request.getLong("clientid"));
+ response.put("msgid", request.getLong("msgid"));
boolean showDialog = request.optBoolean("showDialog");
if (showDialog) {
if (!job.showPrintDialog(null)) {
job.endJob(); // canceled by user
- response.put("status", "200");
+ response.put("status", 200);
response.put("message", "Print job canceled by user");
RequestHandler.reply(response);
return;
+ je.toString() + " : " + request.toString();
logger.warning(error);
- response.put("status", "400");
+ response.put("status", 400);
response.put("message", error);
} catch(IllegalArgumentException iae) {
+ iae.toString() + " : " + request.toString();
logger.warning(error);
- response.put("status", "400");
+ response.put("status", 400);
response.put("message", error);
}
private boolean dispatchRequest(
JSONObject request, JSONObject response) throws JSONException {
- long msgid = request.getLong("msgid");
String action = request.getString("action");
- response.put("msgid", msgid);
-
- logger.info("Received message id=" + msgid + " action=" + action);
+ logger.info("Received message id=" +
+ response.get("msgid") + " action=" + action);
// init must be called first to set the origin info
if (action.equals("init")) {
boolean skipReply = false;
JSONObject response = new JSONObject();
- // these values are overidden as needed by the dispatch handler.
+ // Status values overidden as needed by the dispatch handler.
response.put("status", 200);
response.put("message", "OK");
try {
- skipReply = dispatchRequest(io.recvMessage(), response);
+ JSONObject request = io.recvMessage();
+
+ response.put("clientid", request.getLong("clientid"));
+ response.put("msgid", request.getLong("msgid"));
+
+ skipReply = dispatchRequest(request, response);
+
} catch (JSONException je) {
response.put("status", 400);
response.put("message", "Bad Request: " + je.toString());
}
public static void doSends() {
- int msgId = 1;
+ int msgid = 1;
+ int clientid = 1;
// initialize connection to set origin info
JSONObject obj = new JSONObject();
- obj.put("msgid", msgId++);
+ obj.put("msgid", msgid++);
+ obj.put("clientid", clientid);
obj.put("action", "init");
obj.put("origin", "https://test.hatch.evergreen-ils.org");
io.sendMessage(obj);
// get a list of stored keys
obj = new JSONObject();
- obj.put("msgid", msgId++);
+ obj.put("msgid", msgid++);
+ obj.put("clientid", clientid);
obj.put("action", "keys");
io.sendMessage(obj);
// store a string
obj = new JSONObject();
- obj.put("msgid", msgId++);
+ obj.put("msgid", msgid++);
+ obj.put("clientid", clientid);
obj.put("action", "set");
obj.put("key", "eg.hatch.test.key1");
obj.put("content", "Rando content, now with cheese");
// store a value
obj = new JSONObject();
- obj.put("msgid", msgId++);
+ obj.put("msgid", msgid++);
+ obj.put("clientid", clientid);
obj.put("action", "get");
obj.put("key", "eg.hatch.test.key1");
io.sendMessage(obj);
// store an array
obj = new JSONObject();
- obj.put("msgid", msgId++);
+ obj.put("msgid", msgid++);
+ obj.put("clientid", clientid);
obj.put("action", "set");
obj.put("key", "eg.hatch.test.key2");
JSONArray arr = new JSONArray();
pause();
obj = new JSONObject();
- obj.put("msgid", msgId++);
+ obj.put("msgid", msgid++);
+ obj.put("clientid", clientid);
obj.put("action", "get");
obj.put("key", "eg.hatch.test.key2");
io.sendMessage(obj);
pause();
obj = new JSONObject();
- obj.put("msgid", msgId++);
+ obj.put("msgid", msgid++);
+ obj.put("clientid", clientid);
obj.put("action", "keys");
io.sendMessage(obj);
// get a list of printers
obj = new JSONObject();
- obj.put("msgid", msgId++);
+ obj.put("msgid", msgid++);
+ obj.put("clientid", clientid);
obj.put("action", "printers");
io.sendMessage(obj);
// Printing tests
obj = new JSONObject();
- obj.put("msgid", msgId++);
+ obj.put("msgid", msgid++);
+ obj.put("clientid", clientid);
obj.put("action", "print");
obj.put("contentType", "text/plain");
obj.put("content", "Hello, World!");
pause();
obj = new JSONObject();
- obj.put("msgid", msgId++);
+ obj.put("msgid", msgid++);
+ obj.put("clientid", clientid);
obj.put("action", "print");
obj.put("contentType", "text/html");
obj.put("content", "<html><body><b>HELLO WORLD</b><img src='" +