Add configuration file for host and port
Change-Id: I54e3c1af23c440c21a725f1caaad6d65a4fdadaa
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ac75275
--- /dev/null
+++ b/README.md
@@ -0,0 +1,10 @@
+# KalamarExportPlugin
+
+#Setup
+
+The jar file is located in the ```target/``` folder
+
+## Customizing KalamarExportPlugin configuration
+
+Copy the default configuration file ```plugin/src/main/resources/exportPlugin.conf``` to the same folder as the KalamarExportPlugin jar file (```/target```). Please do not change the name of the configuration file.
+
diff --git a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java
index 6d157c9..96fe926 100644
--- a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java
@@ -1,10 +1,15 @@
package de.ids_mannheim.korap.plkexport;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Properties;
+
import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
-//TODO Set port and host through configuration file
public class PluginServer {
public static void main (String[] args) throws Exception {
@@ -13,10 +18,36 @@
ServletContextHandler.NO_SESSIONS);
contextHandler.setContextPath("/");
- Server jettyServer = new Server(7777);
+ Properties properties = new Properties();
+ File f = new File("exportPlugin.conf");
+ InputStream in = null;
+
+ if (!f.exists()) {
+ String rootPath = Thread.currentThread().getContextClassLoader()
+ .getResource("").getPath();
+ String appConfigPath = rootPath + "exportPlugin.conf";
+ in = new FileInputStream(appConfigPath);
+ }
+ else {
+ in = new FileInputStream(f);
+ }
+
+ properties.load(in);
+ in.close();
+
+ //Default: Server is available under http://localhost:7070/
+ String portStr = properties.getProperty("server.port", "7070");
+ String host = properties.getProperty("server.host", "localhost");
+ int port = Integer.parseInt(portStr);
+
+ Server jettyServer = new Server();
+ ServerConnector connector = new ServerConnector(jettyServer);
+ connector.setPort(port);
+ connector.setHost(host);
+ connector.setIdleTimeout(60000);
+ jettyServer.addConnector(connector);
+
jettyServer.setHandler(contextHandler);
-
-
ServletHolder servletHolder = contextHandler.addServlet(
org.glassfish.jersey.servlet.ServletContainer.class, "/*");
servletHolder.setInitOrder(0);
@@ -28,6 +59,7 @@
try {
jettyServer.start();
+ System.out.println("PluginServer available under: http://" + host+ ":" + portStr);
jettyServer.join();
}
finally {
diff --git a/plugin/src/main/resources/exportPlugin.conf b/plugin/src/main/resources/exportPlugin.conf
new file mode 100644
index 0000000..c9d18db
--- /dev/null
+++ b/plugin/src/main/resources/exportPlugin.conf
@@ -0,0 +1,5 @@
+#Configuration file for
+
+#Server Configuration
+server.port=7777
+server.host=localhost
diff --git a/plugin/src/test/java/de/ids_mannheim/korap/pklexport/IdsExportServiceTest.java b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java
similarity index 87%
rename from plugin/src/test/java/de/ids_mannheim/korap/pklexport/IdsExportServiceTest.java
rename to plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java
index 954a4f0..57dd9ec 100644
--- a/plugin/src/test/java/de/ids_mannheim/korap/pklexport/IdsExportServiceTest.java
+++ b/plugin/src/test/java/de/ids_mannheim/korap/plkexport/IdsExportServiceTest.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.korap.pklexport;
+package de.ids_mannheim.korap.plkexport;
import static org.junit.Assert.assertEquals;
@@ -14,6 +14,7 @@
import de.ids_mannheim.korap.plkexport.IdsExportService;
+//TODO Find a way to test efficiently the starting of the PluginServer with host and port of the config-file
public class IdsExportServiceTest extends JerseyTest {