Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #27 from skoulouzis/deploy2
Browse files Browse the repository at this point in the history
Fixed bug with properties path
  • Loading branch information
skoulouzis authored May 22, 2017
2 parents ed58a82 + 759eee5 commit 0d7710e
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 103 deletions.
6 changes: 3 additions & 3 deletions rest/nbactions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath eu.edisonproject.rest.ECO2Server /home/alogo/workspace/E-CO-2/etc/configure.properties</exec.args>
<exec.args>-classpath %classpath eu.edisonproject.rest.ECO2Server /home/alogo/Downloads/E-CO-2-0.0.1/etc/configure.properties</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
Expand All @@ -24,7 +24,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-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</exec.args>
<exec.args>-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</exec.args>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
</properties>
Expand All @@ -39,7 +39,7 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath eu.edisonproject.rest.ECO2Server /home/alogo/workspace/E-CO-2/etc/configure.properties</exec.args>
<exec.args>-classpath %classpath eu.edisonproject.rest.ECO2Server /home/alogo/Downloads/E-CO-2-0.0.1/etc/configure.properties</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
Expand Down
200 changes: 100 additions & 100 deletions rest/src/main/java/eu/edisonproject/rest/ECO2Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0d7710e

Please sign in to comment.