diff options
| author | Simon Rettberg | 2015-09-01 19:18:42 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2015-09-01 19:18:42 +0200 |
| commit | cc9c9990466dcbc44070bd4474fef29a505866a6 (patch) | |
| tree | febc32f3a6724c396fc64f48d8cd46c8db2f603c /dozentenmodulserver/src/main/java/org | |
| parent | [*] Clean up pom.xml, add shading to client, clean up .gitignore (diff) | |
| download | tutor-module-cc9c9990466dcbc44070bd4474fef29a505866a6.tar.gz tutor-module-cc9c9990466dcbc44070bd4474fef29a505866a6.tar.xz tutor-module-cc9c9990466dcbc44070bd4474fef29a505866a6.zip | |
[server] Add WebServer, add XML serialization classes (vmchooser list)
Diffstat (limited to 'dozentenmodulserver/src/main/java/org')
5 files changed, 100 insertions, 18 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java index bdbc8b7f..6a7f0e74 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java @@ -3,7 +3,6 @@ package org.openslx.bwlp.sat; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -24,6 +23,7 @@ import org.openslx.bwlp.sat.thrift.cache.OrganizationList; import org.openslx.bwlp.sat.util.Configuration; import org.openslx.bwlp.sat.util.Identity; import org.openslx.bwlp.sat.util.Json; +import org.openslx.bwlp.sat.web.WebServer; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.NetDirection; import org.openslx.bwlp.thrift.iface.NetRule; @@ -37,8 +37,6 @@ public class App { private static Logger LOGGER = Logger.getLogger(App.class); - private static List<Thread> servers = new ArrayList<>(); - public static boolean DEBUG = false; public static void main(String[] args) throws TTransportException, NoSuchAlgorithmException, IOException { @@ -105,11 +103,14 @@ public class App { Thread t; // Plain t = new Thread(new BinaryListener(9090, false)); - servers.add(t); + t.setDaemon(true); t.start(); // SSL t = new Thread(new BinaryListener(9091, true)); - servers.add(t); + t.start(); + // Start httpd + t = new Thread(new WebServer(9080)); + t.setDaemon(true); t.start(); // DEBUG if (DEBUG) { @@ -135,19 +136,12 @@ public class App { LOGGER.info(nn); } - // Wait for servers - for (Thread wait : servers) { - boolean success = false; - while (!success) { - try { - wait.join(); - success = true; - } catch (InterruptedException e) { - // Do nothing... - } + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + QuickTimer.cancel(); + LOGGER.info(new Date() + " - all Servers shut down, exiting...\n"); } - } - QuickTimer.cancel(); - LOGGER.info(new Date() + " - all Servers shut down, exiting...\n"); + }); } } diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserEntryXml.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserEntryXml.java new file mode 100644 index 00000000..b1571e74 --- /dev/null +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserEntryXml.java @@ -0,0 +1,24 @@ +package org.openslx.bwlp.sat.web; + +import org.simpleframework.xml.Attribute; + +public class VmChooserEntryXml { + + @Attribute + private VmChooserParamXml priority; + @Attribute + private VmChooserParamXml image_name; + @Attribute + private VmChooserParamXml creator; + @Attribute + private VmChooserParamXml short_description; + @Attribute + private VmChooserParamXml long_description; + @Attribute + private VmChooserParamXml uuid; + @Attribute + private VmChooserParamXml virtualmachine; + @Attribute + private VmChooserParamXml icon; + +} diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserListXml.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserListXml.java new file mode 100644 index 00000000..f9cfa94d --- /dev/null +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserListXml.java @@ -0,0 +1,14 @@ +package org.openslx.bwlp.sat.web; + +import java.util.List; + +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Root; + +@Root(name = "settings") +public class VmChooserListXml { + + @ElementList(inline = true, name = "eintrag") + private List<VmChooserEntryXml> entries; + +} diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserParamXml.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserParamXml.java new file mode 100644 index 00000000..a1f0425a --- /dev/null +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/VmChooserParamXml.java @@ -0,0 +1,14 @@ +package org.openslx.bwlp.sat.web; + +import org.simpleframework.xml.Attribute; + +public class VmChooserParamXml { + + @Attribute + private String param; + + public VmChooserParamXml(String value) { + this.param = value; + } + +} diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java new file mode 100644 index 00000000..02172616 --- /dev/null +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java @@ -0,0 +1,36 @@ +package org.openslx.bwlp.sat.web; + +import fi.iki.elonen.NanoHTTPD; + +public class WebServer extends NanoHTTPD { + + public WebServer(int port) { + super(port); + } + + @Override + public Response serve(IHTTPSession session) { + String uri = session.getUri(); + + if (uri == null || uri.length() == 0) { + return internalServerError(); + } + + // Our special stuff + if (uri.startsWith("/vmchooser/list")) { + return serveVmChooserList(); + } + + return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, "text/plain", "Nicht gefunden!"); + } + + private Response serveVmChooserList() { + return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, "text/plain", "BLA"); + } + + private Response internalServerError() { + return new NanoHTTPD.Response(NanoHTTPD.Response.Status.INTERNAL_ERROR, "text/plain", + "Internal Server Error"); + } + +} |
