From ae38d747e0ddd6401dc4e256d3f24b666cab2036 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 16 Apr 2014 12:47:50 -0400 Subject: [PATCH] hatch minor fixes; copyright Signed-off-by: Bill Erickson --- hatch.xml | 3 +- src/org/evergreen_ils/hatch/FileIO.java | 19 +++++++++-- src/org/evergreen_ils/hatch/Hatch.java | 37 +++++++++++++++------- .../evergreen_ils/hatch/HatchWebSocketHandler.java | 35 +++++++++++++++----- .../evergreen_ils/hatch/HatchWebSocketServlet.java | 20 ++++++++++-- src/org/evergreen_ils/hatch/PrintManager.java | 19 +++++++++-- 6 files changed, 105 insertions(+), 28 deletions(-) diff --git a/hatch.xml b/hatch.xml index e1ec6eb0d3..ac25f1b998 100644 --- a/hatch.xml +++ b/hatch.xml @@ -4,12 +4,11 @@ true + --> diff --git a/src/org/evergreen_ils/hatch/FileIO.java b/src/org/evergreen_ils/hatch/FileIO.java index 95fc012c1e..3d23c7f8c1 100644 --- a/src/org/evergreen_ils/hatch/FileIO.java +++ b/src/org/evergreen_ils/hatch/FileIO.java @@ -1,5 +1,20 @@ +/* ----------------------------------------------------------------------- + * Copyright 2014 Equinox Software, Inc. + * Bill Erickson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * ----------------------------------------------------------------------- + */ package org.evergreen_ils.hatch; - + import java.io.*; import java.util.LinkedList; import org.eclipse.jetty.util.log.Log; @@ -59,7 +74,7 @@ public class FileIO { File file = getFile(key); try { - + // create the file if it doesn's already exist if (!file.exists() && !file.createNewFile()) { logger.info( diff --git a/src/org/evergreen_ils/hatch/Hatch.java b/src/org/evergreen_ils/hatch/Hatch.java index 1ec3bc7068..d50e5b8017 100644 --- a/src/org/evergreen_ils/hatch/Hatch.java +++ b/src/org/evergreen_ils/hatch/Hatch.java @@ -1,3 +1,18 @@ +/* ----------------------------------------------------------------------- + * Copyright 2014 Equinox Software, Inc. + * Bill Erickson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * ----------------------------------------------------------------------- + */ package org.evergreen_ils.hatch; import org.eclipse.jetty.util.log.Log; @@ -35,14 +50,14 @@ import org.eclipse.jetty.util.ajax.JSON; import java.util.Map; import java.io.FileInputStream; - + public class Hatch extends Application { private BrowserView browser; private Stage primaryStage; static final Logger logger = Log.getLogger("Hatch"); - private static LinkedBlockingQueue requestQueue = + private static LinkedBlockingQueue requestQueue = new LinkedBlockingQueue(); /** @@ -58,7 +73,7 @@ public class Hatch extends Application { /** * Service task which listens for inbound messages from the - * servlet. + * servlet. * * The code blocks on the concurrent queue, so it must be * run in a separate thread to avoid locking the main FX thread. @@ -71,7 +86,7 @@ public class Hatch extends Application { try { // take() blocks until a message is available return requestQueue.take(); - } catch (InterruptedException e) { + } catch (InterruptedException e) { // interrupted, go back and listen continue; } @@ -85,7 +100,7 @@ public class Hatch extends Application { @Override public void start(Stage primaryStage) { this.primaryStage = primaryStage; - logger.debug("start()"); + logger.debug("start()"); startMsgTask(); } @@ -95,7 +110,7 @@ public class Hatch extends Application { } /** - * Build a browser view from the print content, tell the + * Build a browser view from the print content, tell the * browser to print itself. */ private void handlePrint(Map params) { @@ -135,7 +150,7 @@ public class Hatch extends Application { @Override public void handle(WorkerStateEvent t) { - Map message = + Map message = (Map) t.getSource().getValue(); if (message != null) handlePrint(message); @@ -148,20 +163,20 @@ public class Hatch extends Application { service.start(); } - + public static void main(String[] args) throws Exception { // build a server from our hatch.xml configuration file - XmlConfiguration configuration = + XmlConfiguration configuration = new XmlConfiguration(new FileInputStream("hatch.xml")); Server server = (Server) configuration.configure(); // start our server, but do not join(), since we want to server // to continue running in its own thread - server.start(); + server.start(); // launch the FX Application thread - launch(args); + launch(args); } } diff --git a/src/org/evergreen_ils/hatch/HatchWebSocketHandler.java b/src/org/evergreen_ils/hatch/HatchWebSocketHandler.java index 4a46b0d928..5a1e8eac39 100644 --- a/src/org/evergreen_ils/hatch/HatchWebSocketHandler.java +++ b/src/org/evergreen_ils/hatch/HatchWebSocketHandler.java @@ -1,3 +1,18 @@ +/* ----------------------------------------------------------------------- + * Copyright 2014 Equinox Software, Inc. + * Bill Erickson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * ----------------------------------------------------------------------- + */ package org.evergreen_ils.hatch; import java.io.IOException; @@ -54,7 +69,7 @@ public class HatchWebSocketHandler { /** - * config is passed in from our WebSocketServlet container, + * config is passed in from our WebSocketServlet container, * hence the public+static. Possible to access directly? */ //public static void configure(ServletConfig config) { @@ -68,11 +83,11 @@ public class HatchWebSocketHandler { if (profileDirectory == null) { logger.info("Unable to set profile directory"); } - } - } + } + } protected boolean verifyOriginDomain() { - logger.info("received connection from IP " + + logger.info("received connection from IP " + session.getRemoteAddress().getAddress()); String origin = session.getUpgradeRequest().getHeader("Origin"); @@ -80,7 +95,7 @@ public class HatchWebSocketHandler { if (origin == null) { logger.warn("No Origin header in request; Dropping connection"); return false; - } + } logger.info("connection origin is " + origin); @@ -121,6 +136,8 @@ public class HatchWebSocketHandler { response.put("error", json); } + logger.info("replying with : " + JSON.toString(response)); + try { String jsonString = JSON.toString(response); if (!success) logger.warn(jsonString); @@ -151,6 +168,8 @@ public class HatchWebSocketHandler { String value = params.get("value"); String mime = params.get("mime"); + logger.info("Received request for action " + action); + // all requets require a message ID if (msgid == null || msgid.equals("")) { reply("No msgid specified in request", msgid, false); @@ -219,12 +238,12 @@ public class HatchWebSocketHandler { return; } - if (action.equals("delete")) { + if (action.equals("remove")) { io = new FileIO(profileDirectory); if (io.delete(key)) { - reply("Delete of " + key + " successful", msgid); + reply("Removal of " + key + " successful", msgid); } else { - reply("Delete of " + key + " failed", msgid, false); + reply("Removal of " + key + " failed", msgid, false); } return; } diff --git a/src/org/evergreen_ils/hatch/HatchWebSocketServlet.java b/src/org/evergreen_ils/hatch/HatchWebSocketServlet.java index 17e523f2b8..2d6a68616c 100644 --- a/src/org/evergreen_ils/hatch/HatchWebSocketServlet.java +++ b/src/org/evergreen_ils/hatch/HatchWebSocketServlet.java @@ -1,3 +1,18 @@ +/* ----------------------------------------------------------------------- + * Copyright 2014 Equinox Software, Inc. + * Bill Erickson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * ----------------------------------------------------------------------- + */ package org.evergreen_ils.hatch; import org.eclipse.jetty.util.log.Log; @@ -19,10 +34,9 @@ public class HatchWebSocketServlet extends WebSocketServlet { } @Override - public void init(ServletConfig config) throws ServletException { + public void init(ServletConfig config) throws ServletException { super.init(config); // required for WS - //HatchWebSocketHandler.configure(config); HatchWebSocketHandler.configure(); - } + } } diff --git a/src/org/evergreen_ils/hatch/PrintManager.java b/src/org/evergreen_ils/hatch/PrintManager.java index 3407929ba4..c0624ab51b 100644 --- a/src/org/evergreen_ils/hatch/PrintManager.java +++ b/src/org/evergreen_ils/hatch/PrintManager.java @@ -1,3 +1,18 @@ +/* ----------------------------------------------------------------------- + * Copyright 2014 Equinox Software, Inc. + * Bill Erickson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * ----------------------------------------------------------------------- + */ package org.evergreen_ils.hatch; // logging @@ -63,7 +78,7 @@ public class PrintManager { public List getPrinters() { List printers = new LinkedList(); - PrintService[] printServices = + PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); String defaultPrinter = ""; @@ -74,7 +89,7 @@ public class PrintManager { HashMap printer = new HashMap(); printers.add(printer); - if (service.getName().equals(defaultPrinter)) + if (service.getName().equals(defaultPrinter)) printer.put("is-default", new Boolean(true)); AttributeSet attributes = service.getAttributes(); -- 2.11.0