From 686e3a3eae4a93490b111ab196dd5b03bfc17cf8 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 18 Jul 2016 13:59:13 +0200 Subject: [PATCH] Renamed IndexPage --- .../norbipeti/chat/server/IndexPage.java | 2 +- src/io/github/norbipeti/chat/server/Main.java | 27 +------------------ 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/src/io/github/norbipeti/chat/server/IndexPage.java b/src/io/github/norbipeti/chat/server/IndexPage.java index d2ab22e..19994f0 100644 --- a/src/io/github/norbipeti/chat/server/IndexPage.java +++ b/src/io/github/norbipeti/chat/server/IndexPage.java @@ -4,7 +4,7 @@ import java.io.IOException; import com.sun.net.httpserver.HttpExchange; -public class Index extends Page { +public class IndexPage extends Page { @Override public void handle(HttpExchange exchange) throws IOException { diff --git a/src/io/github/norbipeti/chat/server/Main.java b/src/io/github/norbipeti/chat/server/Main.java index 2e3fa64..3b851c5 100644 --- a/src/io/github/norbipeti/chat/server/Main.java +++ b/src/io/github/norbipeti/chat/server/Main.java @@ -31,32 +31,7 @@ public class Main { results.getString(0); System.out.println("Starting webserver..."); HttpServer server = HttpServer.create(new InetSocketAddress(InetAddress.getLocalHost(), 8080), 10); - server.createContext("/").setHandler(new HttpHandler() { - - @Override - public void handle(HttpExchange exchange) { - try { - System.out.println("Received request from " + exchange.getRemoteAddress()); - System.out.println("Body: " + IOUtils.toString(exchange.getRequestBody(), "ASCII")); - System.out.println("Headers: "); - for (Entry> entry : exchange.getRequestHeaders().entrySet()) - System.out.println(entry.getKey() + " - " + entry.getValue()); - System.out.println(exchange.getRequestURI().getPath()); - /* - * String resp = - * Pages.get(exchange.getRequestURI().getPath()).Run( - * exchange); exchange.sendResponseHeaders(200, - * resp.length()); IOUtils.write(resp, - * exchange.getResponseBody()); - * exchange.getResponseBody().close(); - */ - exchange.sendResponseHeaders(404, 0); - exchange.getResponseBody().close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); + server.createContext("/").setHandler(new IndexPage()); server.createContext("/register").setHandler(new RegisterPage()); server.start(); System.out.println("Ready... Press Enter to stop.");