From 759eee5884ee51b20d8e3f48aea7d43952621360 Mon Sep 17 00:00:00 2001 From: skoulouzis Date: Mon, 22 May 2017 17:15:45 +0200 Subject: [PATCH] Fixed bug with properties path --- rest/nbactions.xml | 6 +- .../eu/edisonproject/rest/ECO2Server.java | 200 +++++++++--------- .../utility/file/ConfigHelper.java | 1 + 3 files changed, 104 insertions(+), 103 deletions(-) diff --git a/rest/nbactions.xml b/rest/nbactions.xml index cf168a7..3b43401 100644 --- a/rest/nbactions.xml +++ b/rest/nbactions.xml @@ -10,7 +10,7 @@ org.codehaus.mojo:exec-maven-plugin:1.2.1:exec - -classpath %classpath eu.edisonproject.rest.ECO2Server /home/alogo/workspace/E-CO-2/etc/configure.properties + -classpath %classpath eu.edisonproject.rest.ECO2Server /home/alogo/Downloads/E-CO-2-0.0.1/etc/configure.properties java @@ -24,7 +24,7 @@ org.codehaus.mojo:exec-maven-plugin:1.2.1:exec - -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath eu.edisonproject.rest.ECO2Server /home/alogo/workspace/E-CO-2/etc/configure.properties + -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath eu.edisonproject.rest.ECO2Server /home/alogo/Downloads/E-CO-2-0.0.1/etc/configure.properties java true @@ -39,7 +39,7 @@ org.codehaus.mojo:exec-maven-plugin:1.2.1:exec - -classpath %classpath eu.edisonproject.rest.ECO2Server /home/alogo/workspace/E-CO-2/etc/configure.properties + -classpath %classpath eu.edisonproject.rest.ECO2Server /home/alogo/Downloads/E-CO-2-0.0.1/etc/configure.properties java diff --git a/rest/src/main/java/eu/edisonproject/rest/ECO2Server.java b/rest/src/main/java/eu/edisonproject/rest/ECO2Server.java index 695ee7c..a390d23 100644 --- a/rest/src/main/java/eu/edisonproject/rest/ECO2Server.java +++ b/rest/src/main/java/eu/edisonproject/rest/ECO2Server.java @@ -3,7 +3,6 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ - package eu.edisonproject.rest; import static eu.edisonproject.rest.ECO2Controller.courseAverageFolder; @@ -15,6 +14,7 @@ import static eu.edisonproject.rest.ECO2Controller.jobAverageFolder; import static eu.edisonproject.rest.ECO2Controller.jobClassisifcationFolder; import static eu.edisonproject.rest.ECO2Controller.jobProfileFolder; +import static eu.edisonproject.rest.ECO2Controller.propertiesFile; import eu.edisonproject.utility.file.ConfigHelper; import eu.edisonproject.utility.file.MyProperties; @@ -34,114 +34,114 @@ */ public class ECO2Server { - public static void main(String[] args) { - Thread jobWatcher, jobAvgWatcher, cvWatcher, courseWatcher, jobProfileWatcher, cvAvgWatcher, cvProfileWatcher, courseAvgWatcher, courseProfileWatcher; - Server server = null; - try { - ECO2Controller.initPaths(); - jobWatcher = startTaskWatcher(jobClassisifcationFolder.getAbsolutePath()); - jobWatcher.start(); - - jobAvgWatcher = startTaskWatcher(jobAverageFolder.getAbsolutePath()); - jobAvgWatcher.start(); - - jobProfileWatcher = startTaskWatcher(jobProfileFolder.getAbsolutePath()); - jobProfileWatcher.start(); - - cvWatcher = startTaskWatcher(cvClassisifcationFolder.getAbsolutePath()); - cvWatcher.start(); - - cvAvgWatcher = startTaskWatcher(cvAverageFolder.getAbsolutePath()); - cvAvgWatcher.start(); - - cvProfileWatcher = startTaskWatcher(cvProfileFolder.getAbsolutePath()); - cvProfileWatcher.start(); - - courseWatcher = startTaskWatcher(courseClassisifcationFolder.getAbsolutePath()); - courseWatcher.start(); - - courseAvgWatcher = startTaskWatcher(courseAverageFolder.getAbsolutePath()); - courseAvgWatcher.start(); - - courseProfileWatcher = startTaskWatcher(courseProfileFolder.getAbsolutePath()); - courseProfileWatcher.start(); - - server = startServer(args); - server.start(); - jobWatcher.join(); - cvWatcher.join(); - courseWatcher.join(); - jobAvgWatcher.join(); - jobProfileWatcher.join(); - server.join(); - } catch (IOException ex) { - Logger.getLogger(ECO2Server.class.getName()).log(Level.SEVERE, null, ex); - } catch (InterruptedException ex) { - Logger.getLogger(ECO2Server.class.getName()).log(Level.SEVERE, null, ex); - } catch (Exception ex) { - Logger.getLogger(ECO2Server.class.getName()).log(Level.SEVERE, null, ex); - } finally { - if (server != null) { - server.destroy(); - } - } - } - - private static Server startServer(String[] args) throws IOException { - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); - context.setContextPath("/"); - MyProperties props = null; - Integer port; - String path; - if (args != null) { - path = args[0]; - } else { - path = System.getProperty("user.home") + File.separator + "workspace" - + File.separator + "E-CO-2" + File.separator + "etc" + File.separator + "configure.properties"; + public static void main(String[] args) { + Thread jobWatcher, jobAvgWatcher, cvWatcher, courseWatcher, jobProfileWatcher, cvAvgWatcher, cvProfileWatcher, courseAvgWatcher, courseProfileWatcher; + Server server = null; + try { + ECO2Controller.initPaths(); + jobWatcher = startTaskWatcher(jobClassisifcationFolder.getAbsolutePath()); + jobWatcher.start(); + + jobAvgWatcher = startTaskWatcher(jobAverageFolder.getAbsolutePath()); + jobAvgWatcher.start(); + + jobProfileWatcher = startTaskWatcher(jobProfileFolder.getAbsolutePath()); + jobProfileWatcher.start(); + + cvWatcher = startTaskWatcher(cvClassisifcationFolder.getAbsolutePath()); + cvWatcher.start(); + + cvAvgWatcher = startTaskWatcher(cvAverageFolder.getAbsolutePath()); + cvAvgWatcher.start(); + + cvProfileWatcher = startTaskWatcher(cvProfileFolder.getAbsolutePath()); + cvProfileWatcher.start(); + + courseWatcher = startTaskWatcher(courseClassisifcationFolder.getAbsolutePath()); + courseWatcher.start(); + + courseAvgWatcher = startTaskWatcher(courseAverageFolder.getAbsolutePath()); + courseAvgWatcher.start(); + + courseProfileWatcher = startTaskWatcher(courseProfileFolder.getAbsolutePath()); + courseProfileWatcher.start(); + + server = startServer(args); + server.start(); + jobWatcher.join(); + cvWatcher.join(); + courseWatcher.join(); + jobAvgWatcher.join(); + jobProfileWatcher.join(); + server.join(); + } catch (IOException ex) { + Logger.getLogger(ECO2Server.class.getName()).log(Level.SEVERE, null, ex); + } catch (InterruptedException ex) { + Logger.getLogger(ECO2Server.class.getName()).log(Level.SEVERE, null, ex); + } catch (Exception ex) { + Logger.getLogger(ECO2Server.class.getName()).log(Level.SEVERE, null, ex); + } finally { + if (server != null) { + server.destroy(); + } + } } - props = ConfigHelper.getProperties(path); - port = Integer.valueOf(props.getProperty("e-co-2.server.port", "9999")); - - Server jettyServer = new Server(port); - jettyServer.setHandler(context); - - ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*"); - jerseyServlet.setInitOrder(0); - jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "eu.edisonproject.rest"); - - // The filesystem paths we will map - String docPath = System.getProperty("user.home") + File.separator + "workspace" - + File.separator + "E-CO-2" + File.separator + "rest" + File.separator + "target" + File.separator + "docs" + File.separator + "apidocs"; + private static Server startServer(String[] args) throws IOException { + ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); + context.setContextPath("/"); + MyProperties props = null; + Integer port; + String path; + if (args != null) { + path = args[0]; + } else { + path = System.getProperty("user.home") + File.separator + "workspace" + + File.separator + "E-CO-2" + File.separator + "etc" + File.separator + "configure.properties"; + } + propertiesFile = new File(path); + props = ConfigHelper.getProperties(path); + port = Integer.valueOf(props.getProperty("e-co-2.server.port", "9999")); + + Server jettyServer = new Server(port); + jettyServer.setHandler(context); + + ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*"); + jerseyServlet.setInitOrder(0); + jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "eu.edisonproject.rest"); + + // The filesystem paths we will map + String docPath = System.getProperty("user.home") + File.separator + "workspace" + + File.separator + "E-CO-2" + File.separator + "rest" + File.separator + "target" + File.separator + "docs" + File.separator + "apidocs"; // String pwdPath = System.getProperty("user.dir"); // // Setup the basic application "context" for this application at "/" // // This is also known as the handler tree (in jetty speak) - context.setResourceBase(docPath); - context.setContextPath("/"); - jettyServer.setHandler(context); - // add special pathspec of "/home/" content mapped to the homePath - ServletHolder holderHome = new ServletHolder("static-home", DefaultServlet.class); - jerseyServlet.setInitParameter("resourceBase", docPath); - holderHome.setInitParameter("dirAllowed", "true"); - holderHome.setInitParameter("pathInfoOnly", "true"); - context.addServlet(holderHome, "/doc/*"); - - // Lastly, the default servlet for root content (always needed, to satisfy servlet spec) - // It is important that this is last. - ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class); - holderPwd.setInitParameter("dirAllowed", "true"); - context.addServlet(holderPwd, "/"); - - return jettyServer; - } + context.setResourceBase(docPath); + context.setContextPath("/"); + jettyServer.setHandler(context); + // add special pathspec of "/home/" content mapped to the homePath + ServletHolder holderHome = new ServletHolder("static-home", DefaultServlet.class); + jerseyServlet.setInitParameter("resourceBase", docPath); + holderHome.setInitParameter("dirAllowed", "true"); + holderHome.setInitParameter("pathInfoOnly", "true"); + context.addServlet(holderHome, "/doc/*"); + + // Lastly, the default servlet for root content (always needed, to satisfy servlet spec) + // It is important that this is last. + ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class); + holderPwd.setInitParameter("dirAllowed", "true"); + context.addServlet(holderPwd, "/"); + + return jettyServer; + } - private static Thread startTaskWatcher(String dir) throws IOException, InterruptedException { + private static Thread startTaskWatcher(String dir) throws IOException, InterruptedException { - Runnable folderWatcherRunnable = new FolderWatcherRunnable(dir); + Runnable folderWatcherRunnable = new FolderWatcherRunnable(dir); - return new Thread(folderWatcherRunnable); + return new Thread(folderWatcherRunnable); - } + } } diff --git a/utility/src/main/java/eu/edisonproject/utility/file/ConfigHelper.java b/utility/src/main/java/eu/edisonproject/utility/file/ConfigHelper.java index 5ead73e..a33bbfb 100644 --- a/utility/src/main/java/eu/edisonproject/utility/file/ConfigHelper.java +++ b/utility/src/main/java/eu/edisonproject/utility/file/ConfigHelper.java @@ -65,6 +65,7 @@ public static MyProperties getProperties(String propertiesPath) throws IOExcepti ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); in = classLoader.getResourceAsStream(propertiesPath); } + MyProperties properties = new MyProperties(); properties.load(in); return properties;