hatch minor fixes; copyright
authorBill Erickson <berick@esilibrary.com>
Wed, 16 Apr 2014 16:47:50 +0000 (12:47 -0400)
committerJeff Godin <jgodin@tadl.org>
Fri, 3 Jun 2016 20:38:46 +0000 (16:38 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
hatch.xml
src/org/evergreen_ils/hatch/FileIO.java
src/org/evergreen_ils/hatch/Hatch.java
src/org/evergreen_ils/hatch/HatchWebSocketHandler.java
src/org/evergreen_ils/hatch/HatchWebSocketServlet.java
src/org/evergreen_ils/hatch/PrintManager.java

index e1ec6eb..ac25f1b 100644 (file)
--- a/hatch.xml
+++ b/hatch.xml
@@ -4,12 +4,11 @@
 <Configure id="Server" class="org.eclipse.jetty.server.Server">
 
   <!--
-  <Set class="org.eclipse.jetty.util.log.StdErrLog" name="level">LEVEL_DEBUG</Set>
-  -->
   <Get id="Logger" class="org.eclipse.jetty.util.log.Log" name="log"/>
   <Ref id="Logger">
     <Set name="debugEnabled">true</Set>
   </Ref>
+  -->
 
   <Set class="org.evergreen_ils.hatch.HatchWebSocketHandler" name="trustedDomains">
     <Array type="String">
index 95fc012..3d23c7f 100644 (file)
@@ -1,5 +1,20 @@
+/* -----------------------------------------------------------------------
+ * Copyright 2014 Equinox Software, Inc.
+ * Bill Erickson <berick@esilibrary.com>
+ *
+ * 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(
index 1ec3bc7..d50e5b8 100644 (file)
@@ -1,3 +1,18 @@
+/* -----------------------------------------------------------------------
+ * Copyright 2014 Equinox Software, Inc.
+ * Bill Erickson <berick@esilibrary.com>
+ *
+ * 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<Map> requestQueue = 
+    private static LinkedBlockingQueue<Map> requestQueue =
         new LinkedBlockingQueue<Map>();
 
     /**
@@ -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<String,String> params) {
@@ -135,7 +150,7 @@ public class Hatch extends Application {
 
             @Override
             public void handle(WorkerStateEvent t) {
-                Map<String,String> message = 
+                Map<String,String> message =
                     (Map<String,String>) 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);
     }
 }
index 4a46b0d..5a1e8ea 100644 (file)
@@ -1,3 +1,18 @@
+/* -----------------------------------------------------------------------
+ * Copyright 2014 Equinox Software, Inc.
+ * Bill Erickson <berick@esilibrary.com>
+ *
+ * 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;
         }
index 17e523f..2d6a686 100644 (file)
@@ -1,3 +1,18 @@
+/* -----------------------------------------------------------------------
+ * Copyright 2014 Equinox Software, Inc.
+ * Bill Erickson <berick@esilibrary.com>
+ *
+ * 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();
-    }  
+    }
 }
 
index 3407929..c0624ab 100644 (file)
@@ -1,3 +1,18 @@
+/* -----------------------------------------------------------------------
+ * Copyright 2014 Equinox Software, Inc.
+ * Bill Erickson <berick@esilibrary.com>
+ *
+ * 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<HashMap> getPrinters() {
 
         List<HashMap> printers = new LinkedList<HashMap>();
-        PrintService[] printServices = 
+        PrintService[] printServices =
             PrintServiceLookup.lookupPrintServices(null, null);
 
         String defaultPrinter = "";
@@ -74,7 +89,7 @@ public class PrintManager {
             HashMap<String, Object> printer = new HashMap<String, Object>();
             printers.add(printer);
 
-            if (service.getName().equals(defaultPrinter)) 
+            if (service.getName().equals(defaultPrinter))
                 printer.put("is-default", new Boolean(true));
 
             AttributeSet attributes = service.getAttributes();