REST-service skeleton
diff --git a/CHANGES b/CHANGES
index e77bbb1..5dd4542 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+0.40 2014-09-03
+ - [feature] Skeleton for standalone REST service (diewald)
+
0.33 2014-09-01
- [feature] SpanSubspanQuery (margaretha)
- [feature] SpanExpansionQuery (margaretha)
diff --git a/pom.xml b/pom.xml
index f163d4f..6558887 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
-->
<groupId>KorAP-modules</groupId>
<artifactId>KorAP-lucene-index</artifactId>
- <version>0.33</version>
+ <version>0.40</version>
<packaging>jar</packaging>
<name>KorAP-lucene-index</name>
@@ -28,12 +28,31 @@
<email>diewald@ids-mannheim.de</email>
<url>http://nils-diewald.de</url>
</developer>
+
+ <developer>
+ <name>Eliza Margaretha</name>
+ <email>margaretha@ids-mannheim.de</email>
+ </developer>
+
</developers>
<properties>
+ <jersey.version>2.4.1</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey</groupId>
+ <artifactId>jersey-bom</artifactId>
+ <version>${jersey.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
<dependencies>
<!-- junit dependency -->
@@ -57,6 +76,7 @@
</dependency>
<!-- solr dependency -->
+ <!--
<dependency>
<artifactId>solr-core</artifactId>
<groupId>org.apache.solr</groupId>
@@ -70,7 +90,7 @@
<groupId>org.apache.solr</groupId>
<version>4.3.1</version>
</dependency>
-
+ -->
<!-- Lucene core dependency -->
<dependency>
@@ -110,21 +130,32 @@
</dependency>
<!-- servlet dependency -->
+ <!--
<dependency>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
<version>2.5</version>
</dependency>
-
- <!-- among others Base4 support -->
- <!--
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- <version>1.4</version>
- </dependency>
-->
+ <!-- Jersey -->
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-grizzly2-http</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.jersey.contribs</groupId>
+ <artifactId>jersey-freemarker</artifactId>
+ <version>1.13-b01</version>
+ </dependency>
+
+ <!-- JSON support -->
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-moxy</artifactId>
+ </dependency>
+
<!-- Jackson -->
<!-- see https://github.com/FasterXML/jackson-core -->
<!-- https://github.com/FasterXML/jackson-databind -->
@@ -151,7 +182,8 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
+ <version>2.5.1</version>
+ <inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
@@ -219,6 +251,23 @@
</excludes>
</configuration>
</plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.2.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <mainClass>de.ids_mannheim.korap.KorapNode</mainClass>
+ </configuration>
+ </plugin>
+
</plugins>
<resources>
diff --git a/src/main/java/de/ids_mannheim/korap/KorapNode.java b/src/main/java/de/ids_mannheim/korap/KorapNode.java
new file mode 100644
index 0000000..1155cae
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/KorapNode.java
@@ -0,0 +1,47 @@
+package de.ids_mannheim.korap;
+
+import org.glassfish.grizzly.http.server.HttpServer;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
+import org.glassfish.jersey.server.ResourceConfig;
+
+import java.io.IOException;
+import java.net.URI;
+
+/**
+ * Standalone REST-Service for the Lucene Search Backend.
+ *
+ * @author Nils Diewald
+ */
+public class KorapNode {
+
+ // Base URI the Grizzly HTTP server will listen on
+ public static final String BASE_URI = "http://localhost:8080/";
+
+ /**
+ * Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
+ * @return Grizzly HTTP server.
+ */
+ public static HttpServer startServer() {
+ // create a resource config that scans for JAX-RS resources and providers
+ // in de.ids_mannheim.korap.server package
+ final ResourceConfig rc = new ResourceConfig().packages("de.ids_mannheim.korap.server");
+
+ // create and start a new instance of grizzly http server
+ // exposing the Jersey application at BASE_URI
+ return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
+ }
+
+ /**
+ * Main method.
+ * @param args
+ * @throws IOException
+ */
+ public static void main(String[] args) throws IOException {
+ final HttpServer server = startServer();
+ System.out.println("KorapNode started\nHit enter to stop it...");
+ // WADL available at BASE_URI + application.wadl
+ System.in.read();
+ server.stop();
+ }
+}
+
diff --git a/src/main/java/de/ids_mannheim/korap/server/Ping.java b/src/main/java/de/ids_mannheim/korap/server/Ping.java
new file mode 100644
index 0000000..ebaba96
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/server/Ping.java
@@ -0,0 +1,20 @@
+package de.ids_mannheim.korap.server;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * A useful ping service.
+ *
+ * @author Nils Diewald
+ */
+@Path("ping")
+public class Ping {
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String getIt() {
+ return "Gimme 5 minutes, please!";
+ };
+};
diff --git a/src/test/java/de/ids_mannheim/korap/server/PingTest.java b/src/test/java/de/ids_mannheim/korap/server/PingTest.java
new file mode 100644
index 0000000..12fad2c
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/server/PingTest.java
@@ -0,0 +1,50 @@
+package de.ids_mannheim.korap.server;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.grizzly.http.server.HttpServer;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+import de.ids_mannheim.korap.KorapNode;
+
+public class PingTest {
+
+ private HttpServer server;
+ private WebTarget target;
+
+ @Before
+ public void setUp() throws Exception {
+ // start the server
+ server = KorapNode.startServer();
+ // create the client
+ Client c = ClientBuilder.newClient();
+
+ // uncomment the following line if you want to enable
+ // support for JSON in the client (you also have to uncomment
+ // dependency on jersey-media-json module in pom.xml and Main.startServer())
+ // --
+ // c.configuration().enable(new org.glassfish.jersey.media.json.JsonJaxbFeature());
+
+ target = c.target(KorapNode.BASE_URI);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ server.stop();
+ }
+
+ /**
+ * Test to see that the message "Gimme 5 minutes, please!" is sent in the response.
+ */
+ @Test
+ public void testPing() {
+ String responseMsg = target.path("ping").request().get(String.class);
+ assertEquals("Gimme 5 minutes, please!", responseMsg);
+ }
+}