From 6bd5faa5582da0a07dfcc52ffb8fc7fc740cc1cd Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 16 Apr 2014 10:48:54 -0400 Subject: [PATCH] Hatch: use jetty XML for all configuration; SSL recovered. Signed-off-by: Bill Erickson --- hatch.xml | 162 ++++++++++++++++++ src/org/evergreen_ils/hatch/Hatch.java | 17 +- .../hatch/HatchWebSocketHandler.java | 60 +++---- 3 files changed, 199 insertions(+), 40 deletions(-) create mode 100644 hatch.xml diff --git a/hatch.xml b/hatch.xml new file mode 100644 index 0000000000..e1ec6eb0d3 --- /dev/null +++ b/hatch.xml @@ -0,0 +1,162 @@ + + + + + + + + + true + + + + + + * + + + + + + + + https + + + + + + + 512 + + + + + + + /jetty-distribution-9.1.4.v20140401/etc/keystore + OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4 + OBF:1u2u1wml1z7s1z7a1wnl1u2g + /jetty-distribution-9.1.4.v20140401/etc/keystore + OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4 + + + + + + + + + + + + + + + + + + + http/1.1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + maxThreads + + + + + + maxConnections + + + + + + idleTimeout + + + + + + timeout + + + + + + + + + + + + + diff --git a/src/org/evergreen_ils/hatch/Hatch.java b/src/org/evergreen_ils/hatch/Hatch.java index c3c29411c2..1ec3bc7068 100644 --- a/src/org/evergreen_ils/hatch/Hatch.java +++ b/src/org/evergreen_ils/hatch/Hatch.java @@ -151,16 +151,17 @@ public class Hatch extends Application { public static void main(String[] args) throws Exception { - Server server = new Server(8080); - ServletHandler handler = new ServletHandler(); - server.setHandler(handler); + // build a server from our hatch.xml configuration file + XmlConfiguration configuration = + new XmlConfiguration(new FileInputStream("hatch.xml")); - // TODO: config file; ditto profileDirectory, logging, etc. - HatchWebSocketHandler.trustedDomainsString = "*"; + Server server = (Server) configuration.configure(); - handler.addServletWithMapping(HatchWebSocketServlet.class, "/hatch"); + // start our server, but do not join(), since we want to server + // to continue running in its own thread + server.start(); - server.start(); // no join() -- let server thread run in parallel - launch(args); // launch the Application + // launch the FX Application thread + launch(args); } } diff --git a/src/org/evergreen_ils/hatch/HatchWebSocketHandler.java b/src/org/evergreen_ils/hatch/HatchWebSocketHandler.java index 661c3d2cf1..4a46b0d928 100644 --- a/src/org/evergreen_ils/hatch/HatchWebSocketHandler.java +++ b/src/org/evergreen_ils/hatch/HatchWebSocketHandler.java @@ -23,12 +23,36 @@ import java.util.Map; public class HatchWebSocketHandler { private Session session; - static String[] trustedDomains; - static String trustedDomainsString = null; - static boolean trustAllDomains = false; - static String profileDirectory; + private static String[] trustedDomains; + private static boolean trustAllDomains = false; + private static String profileDirectory; private static final Logger logger = Log.getLogger("WebSocketHandler"); + public static void setTrustedDomains(String[] domains) { + trustedDomains = domains; + + if (domains.length > 0 ) { + + if ("*".equals(domains[0])) { + logger.info("All domains trusted"); + trustAllDomains = true; + + } else { + + for(String domain : trustedDomains) { + logger.info("Trusted domain: " + domain); + } + } + } else { + logger.warn("No domains are trusted"); + } + } + + public static void setProfileDirectory(String directory) { + profileDirectory = directory; + } + + /** * config is passed in from our WebSocketServlet container, * hence the public+static. Possible to access directly? @@ -37,16 +61,6 @@ public class HatchWebSocketHandler { public static void configure() { logger.info("WebSocketHandler.configure()"); - /* - trustedDomainsString = - config.getServletContext().getInitParameter("trustedDomains"); - - logger.info("trusted domains " + trustedDomainsString); - - profileDirectory = - config.getServletContext().getInitParameter("profileDirectory"); - */ - // default to ~/.evergreen if (profileDirectory == null) { String home = System.getProperty("user.home"); @@ -55,24 +69,6 @@ public class HatchWebSocketHandler { logger.info("Unable to set profile directory"); } } - - if (trustedDomainsString == null) { - logger.info("No trusted domains configured"); - - } else { - - if (trustedDomainsString.equals("*")) { - trustAllDomains = true; - logger.info("All domains trusted"); - - } else { - - trustedDomains = trustedDomainsString.split(","); - for(String domain : trustedDomains) { - logger.info("Trusted domain: " + domain); - } - } - } } protected boolean verifyOriginDomain() { -- 2.43.2