<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">
+/* -----------------------------------------------------------------------
+ * 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;
File file = getFile(key);
try {
-
+
// create the file if it doesn's already exist
if (!file.exists() && !file.createNewFile()) {
logger.info(
+/* -----------------------------------------------------------------------
+ * 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;
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>();
/**
/**
* 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.
try {
// take() blocks until a message is available
return requestQueue.take();
- } catch (InterruptedException e) {
+ } catch (InterruptedException e) {
// interrupted, go back and listen
continue;
}
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
- logger.debug("start()");
+ logger.debug("start()");
startMsgTask();
}
}
/**
- * 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) {
@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);
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);
}
}
+/* -----------------------------------------------------------------------
+ * 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;
/**
- * 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) {
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");
if (origin == null) {
logger.warn("No Origin header in request; Dropping connection");
return false;
- }
+ }
logger.info("connection origin is " + origin);
response.put("error", json);
}
+ logger.info("replying with : " + JSON.toString(response));
+
try {
String jsonString = JSON.toString(response);
if (!success) logger.warn(jsonString);
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);
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;
}
+/* -----------------------------------------------------------------------
+ * 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;
}
@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();
- }
+ }
}
+/* -----------------------------------------------------------------------
+ * 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
public List<HashMap> getPrinters() {
List<HashMap> printers = new LinkedList<HashMap>();
- PrintService[] printServices =
+ PrintService[] printServices =
PrintServiceLookup.lookupPrintServices(null, null);
String defaultPrinter = "";
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();