From df7d7981b56a4560c95ea7e9b194080e93398ecf Mon Sep 17 00:00:00 2001 From: Matt Windsor Date: Mon, 21 Mar 2011 21:54:31 +0000 Subject: GREAT PACKAGE RESHUFFLE: Everything is now organised into frontend, backend and common (to frontend and backend) packages. Things may have been broken. Doc refresh. --- src/uk/org/ury/backend/server/Server.java | 99 +++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/uk/org/ury/backend/server/Server.java (limited to 'src/uk/org/ury/backend/server/Server.java') diff --git a/src/uk/org/ury/backend/server/Server.java b/src/uk/org/ury/backend/server/Server.java new file mode 100644 index 0000000..57a0030 --- /dev/null +++ b/src/uk/org/ury/backend/server/Server.java @@ -0,0 +1,99 @@ +/* + * Server.java + * ----------- + * + * Part of the URY Server Platform + * + * V0.00 2011/03/20 + * + * (C) 2011 URY Computing + */ + +package uk.org.ury.backend.server; + +import java.io.IOException; + +import uk.org.ury.backend.config.ConfigReader; +import uk.org.ury.backend.database.DatabaseDriver; +import uk.org.ury.backend.database.UserClass; +import uk.org.ury.backend.database.exceptions.ConnectionFailureException; +import uk.org.ury.backend.database.exceptions.MissingCredentialsException; + +/** + * The unified URY server, accepting requests over HTTP. + * + * @author Matt Windsor + * @version 2011.0320 + */ +public class Server { + public static final String SERVER_VERSION = "SLUT 0.0"; + public static final String DOCTYPE = ""; + public static final String INDEX_HTML = "\n" + "\n " + + "\n " + SERVER_VERSION + "" + "\n " + + "\n " + "\n

Welcome to the " + SERVER_VERSION + + " server

" + + "\n

This server exposes a class-based API for accessing" + + "\n the internals of the " + SERVER_VERSION + " system.

" + + "\n

See the documentation for details.

" + "\n " + + "\n"; + + /** + * The main method, which serves to create a server. + * + * @param args + * The argument vector. + */ + public static void main(String[] args) { + Server srv = new Server(); + srv.run(); + } + + /** + * Run the server. + */ + private void run() { + Thread thread = null; + + try { + thread = new HttpListenerThread(8000, this); + } catch (IOException e) { + e.printStackTrace(); + System.exit(-1); + } + + thread.setDaemon(false); + thread.run(); + } + + /** + * Gets a database connection using the given user class. + * + * @param userClass + * The user class to get a connection for. + * + * @return a database connection, which may or may not have been created on + * this call. + * + * @throws MissingCredentialsException + * if the credentials for the given userclass are missing. + * + * @throws ConnectionFailureException + * if the connection failed. + */ + public DatabaseDriver getDatabaseConnection(UserClass userClass) + throws MissingCredentialsException, ConnectionFailureException { + // TODO: Singleton + + ConfigReader config = new ConfigReader("res/conf.xml"); + + return new DatabaseDriver(config, UserClass.READ_ONLY); + } + + /** + * @return the version string of the server. + */ + public String getVersion() { + return SERVER_VERSION; + } +} -- cgit v1.2.3