summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-02-22 15:35:29 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-02-22 15:35:29 +0100
commit7863a228b54722d7b1b42f9e39e2ee115a97aee5 (patch)
tree01576c5e63d15786001d56fcfb3ee76e8082694d /server
parent3134a588789cde591daa6065cf5e5db4b3c82523 (diff)
downloadRustAndDust-7863a228b54722d7b1b42f9e39e2ee115a97aee5.zip
RustAndDust-7863a228b54722d7b1b42f9e39e2ee115a97aee5.tar.gz
Diffstat (limited to 'server')
-rw-r--r--server/build.gradle27
-rw-r--r--server/src/ch/asynk/rustanddust/server/Server.java37
2 files changed, 64 insertions, 0 deletions
diff --git a/server/build.gradle b/server/build.gradle
new file mode 100644
index 0000000..d2c6481
--- /dev/null
+++ b/server/build.gradle
@@ -0,0 +1,27 @@
+apply plugin: "java"
+
+sourceCompatibility = 1.7
+sourceSets.main.java.srcDirs = [ "src/" ]
+
+project.ext.mainClassName = "ch.asynk.rustanddust.server.Server"
+
+task run(dependsOn: classes, type: JavaExec) {
+ main = project.mainClassName
+ classpath = sourceSets.main.runtimeClasspath
+ standardInput = System.in
+ /* workingDir = project.assetsDir */
+ ignoreExitValue = true
+}
+
+task dist(type: Jar) {
+ from files(sourceSets.main.output.classesDir)
+ from files(sourceSets.main.output.resourcesDir)
+ from {configurations.compile.collect {zipTree(it)}}
+ /* from files(project.assetsDir); */
+
+ manifest {
+ attributes 'Main-Class': project.mainClassName
+ }
+}
+
+dist.dependsOn classes
diff --git a/server/src/ch/asynk/rustanddust/server/Server.java b/server/src/ch/asynk/rustanddust/server/Server.java
new file mode 100644
index 0000000..4a2000c
--- /dev/null
+++ b/server/src/ch/asynk/rustanddust/server/Server.java
@@ -0,0 +1,37 @@
+package ch.asynk.rustanddust.server;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+
+public class Server
+{
+
+ public static void main(String[] args) throws Exception
+ {
+ HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
+ server.createContext("/test", new MyHandler());
+ server.setExecutor(null);
+ server.start();
+ // System.exit(0);
+ }
+
+ static class MyHandler implements HttpHandler
+ {
+ @Override
+ public void handle(HttpExchange t) throws IOException
+ {
+ System.err.print("answering ...");
+ String response = "This is the response";
+ t.sendResponseHeaders(200, response.length());
+ OutputStream os = t.getResponseBody();
+ os.write(response.getBytes());
+ os.close();
+ System.err.print("done.");
+ }
+ }
+}