Rudimentary Plugin Export Server

Change-Id: Id0f6c6fc0d4ad90cecb59b2b079b6cc730319990
diff --git a/plugin/pom.xml b/plugin/pom.xml
new file mode 100644
index 0000000..7b4ca63
--- /dev/null
+++ b/plugin/pom.xml
@@ -0,0 +1,110 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>de.ids_mannheim.korap</groupId>
+  <artifactId>KalamarExportPlugin</artifactId>
+  <packaging>jar</packaging>
+  <version>0.1</version>
+  <name>KalamarExportPlugin</name>
+  <url>http://maven.apache.org</url>
+  
+    <properties>
+        <jetty.version>9.2.3.v20140905</jetty.version>
+        <jersey.version>2.27</jersey.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.13</version>
+        </dependency>
+
+        <!-- jetty -->
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-server</artifactId>
+            <version>${jetty.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-servlet</artifactId>
+            <version>${jetty.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.glassfish.jersey.core</groupId>
+            <artifactId>jersey-server</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.core</groupId>
+            <artifactId>jersey-client</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.inject</groupId>
+            <artifactId>jersey-hk2</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.containers</groupId>
+            <artifactId>jersey-container-servlet-core</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+
+        <!-- Jersey test framework -->
+        <dependency>
+            <groupId>org.glassfish.jersey.test-framework</groupId>
+            <artifactId>jersey-test-framework-core</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+            <artifactId>jersey-test-framework-provider-grizzly2</artifactId>
+            <version>${jersey.version}</version>
+            <scope>test</scope>
+        </dependency>    
+    </dependencies>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <version>1.6</version>
+                <configuration>
+                    <filters>
+                        <filter>
+                            <artifact>*:*</artifact>
+                            <excludes>
+                                <exclude>META-INF/*.SF</exclude>
+                                <exclude>META-INF/*.DSA</exclude>
+                                <exclude>META-INF/*.RSA</exclude>
+                            </excludes>
+                        </filter>
+                    </filters>
+                </configuration>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                        <configuration>
+                            <transformers>
+                                <transformer
+                                    implementation='org.apache.maven.plugins.shade.resource.ManifestResourceTransformer'>
+                                    <manifestEntries>
+                                        <Main-Class>de.ids_mannheim.korap.plkexport.PluginServer</Main-Class>
+                                    </manifestEntries>
+                                </transformer>
+                            </transformers>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
+
diff --git a/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java
new file mode 100644
index 0000000..1357971
--- /dev/null
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/IdsExportService.java
@@ -0,0 +1,19 @@
+package de.ids_mannheim.korap.plkexport;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("/ids-export")
+public class IdsExportService {
+
+    @GET
+    @Path("exportHtml")
+    @Produces(MediaType.TEXT_HTML)
+    public String testHtml () {
+        return "Export Web Service under construction";
+    }
+
+
+}
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
new file mode 100644
index 0000000..6d157c9
--- /dev/null
+++ b/plugin/src/main/java/de/ids_mannheim/korap/plkexport/PluginServer.java
@@ -0,0 +1,37 @@
+package de.ids_mannheim.korap.plkexport;
+
+import org.eclipse.jetty.server.Server;
+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 {
+
+
+        ServletContextHandler contextHandler = new ServletContextHandler(
+                ServletContextHandler.NO_SESSIONS);
+        contextHandler.setContextPath("/");
+
+        Server jettyServer = new Server(7777);
+        jettyServer.setHandler(contextHandler);
+
+
+        ServletHolder servletHolder = contextHandler.addServlet(
+                org.glassfish.jersey.servlet.ServletContainer.class, "/*");
+        servletHolder.setInitOrder(0);
+
+        // Tells the Jersey Servlet which REST service/class to load.
+        servletHolder.setInitParameter(
+                "jersey.config.server.provider.classnames",
+                IdsExportService.class.getCanonicalName());
+
+        try {
+            jettyServer.start();
+            jettyServer.join();
+        }
+        finally {
+            jettyServer.destroy();
+        }
+    }
+}
diff --git a/plugin/src/test/java/de/ids_mannheim/korap/pklexport/IdsExportServiceTest.java b/plugin/src/test/java/de/ids_mannheim/korap/pklexport/IdsExportServiceTest.java
new file mode 100644
index 0000000..954a4f0
--- /dev/null
+++ b/plugin/src/test/java/de/ids_mannheim/korap/pklexport/IdsExportServiceTest.java
@@ -0,0 +1,36 @@
+package de.ids_mannheim.korap.pklexport;
+
+import static org.junit.Assert.assertEquals;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.junit.Test;
+
+import de.ids_mannheim.korap.plkexport.IdsExportService;
+
+
+public class IdsExportServiceTest extends JerseyTest {
+	 
+	   @Override
+	    protected Application configure() {
+	        return new ResourceConfig(IdsExportService.class);
+	    }
+
+
+	   @Test
+	   public void testExportWs() {
+		   Response response = target("/ids-export/exportHtml").request().get();
+		   assertEquals("Http Response should be 200: ", Status.OK.getStatusCode(), response.getStatus());
+		   assertEquals("Http Content-Type should be: ", MediaType.TEXT_HTML, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+		   String content = response.readEntity(String.class);
+		   assertEquals("Content of response is: ", "Export Web Service under construction", content);
+	   } 
+
+}
+