From ce4bb0836d76176e24ee2b9cb4c83567bc5cdb28 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 28 Jul 2017 23:58:09 +0300 Subject: [PATCH] Got something working on Edge. --- .../djrapitops/plan/ui/webserver/Request.java | 9 +++++++ .../plan/ui/webserver/WebSocketServer.java | 25 +++++++++++-------- .../plan/ui/webserver/response/Response.java | 16 ++++++++++-- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java index be42d1d0e..31686ec47 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java @@ -138,4 +138,13 @@ public class Request implements Closeable { public void close() throws IOException { close.close(); } + + @Override + public String toString() { + return "Request{" + + "request='" + request + '\'' + + ", target='" + target + '\'' + + ", authorization='" + authorization + '\'' + + '}'; + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebSocketServer.java b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebSocketServer.java index c05e1c46c..7a42449b6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebSocketServer.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebSocketServer.java @@ -98,25 +98,25 @@ public class WebSocketServer { trustManagerFactory.init(keystore); server = HttpsServer.create(new InetSocketAddress(PORT), 10); - SSLContext sslContext = SSLContext.getInstance("TLS"); - sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); + SSLContext sslContext = SSLContext.getInstance("SSL"); + sslContext.init(keyManagerFactory.getKeyManagers(), null/*trustManagerFactory.getTrustManagers()*/, null); ((HttpsServer) server).setHttpsConfigurator(new HttpsConfigurator(sslContext) { public void configure(HttpsParameters params) { - try { - SSLContext c = SSLContext.getDefault(); - SSLEngine engine = c.createSSLEngine(); +// try { +// SSLContext c = SSLContext.getDefault(); + SSLEngine engine = sslContext.createSSLEngine(); params.setNeedClientAuth(false); params.setCipherSuites(engine.getEnabledCipherSuites()); params.setProtocols(engine.getEnabledProtocols()); - SSLParameters defaultSSLParameters = c.getDefaultSSLParameters(); + SSLParameters defaultSSLParameters = sslContext.getDefaultSSLParameters(); params.setSSLParameters(defaultSSLParameters); - } catch (NoSuchAlgorithmException e) { - Log.error("WebServer: SSL Engine loading Failed."); - Log.toLog(this.getClass().getName(), e); - } +// } catch (NoSuchAlgorithmException e) { +// Log.error("WebServer: SSL Engine loading Failed."); +// Log.toLog(this.getClass().getName(), e); +// } } }); startSuccessful = true; @@ -127,16 +127,21 @@ public class WebSocketServer { Log.error("WebServer: SSL Context Initialization Failed."); Log.toLog(this.getClass().getName(), e); } catch (FileNotFoundException e) { + Log.error("!--------!---------!---------!"); Log.error("WebServer: SSL Certificate KeyStore File not Found: " + keyStorePath); + Log.error("!--------!---------!---------!"); } catch (KeyStoreException | CertificateException | UnrecoverableKeyException e) { Log.error("WebServer: SSL Certificate loading Failed."); Log.toLog(this.getClass().getName(), e); } + Log.debug("Start Successful: "+startSuccessful); + if (!startSuccessful) { return; // TODO Http Server } + Log.debug("Create server context"); server.createContext("/", serverResponse(null)); HttpContext analysisPage = server.createContext("/server", serverResponse(null)); HttpContext playersPage = server.createContext("/players", new PlayersPageResponse(null, plugin)); diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/response/Response.java b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/response/Response.java index e4305393c..be489e140 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/response/Response.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/response/Response.java @@ -1,8 +1,11 @@ package main.java.com.djrapitops.plan.ui.webserver.response; +import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpsExchange; import main.java.com.djrapitops.plan.Log; +import main.java.com.djrapitops.plan.ui.webserver.Request; import java.io.IOException; import java.io.OutputStream; @@ -57,10 +60,19 @@ public abstract class Response implements HttpHandler { } @Override - public void handle(HttpExchange exchange) throws IOException { + public void handle(HttpExchange xghng) throws IOException { + Log.debug("Recieved HTTP Exchange"); + Log.debug(xghng.toString()); + HttpsExchange exchange = (HttpsExchange) xghng; try { - exchange.sendResponseHeaders(getCode(), content.length()); + Headers headers = exchange.getRequestHeaders(); + Request req = new Request(exchange.getRequestBody()); + Log.debug(req.toString()); +// headers.set("Content-Type", "text/html"); + exchange.sendResponseHeaders(getCode(), content.length()); + Log.debug("Content:"); + Log.debug(content); OutputStream os = exchange.getResponseBody(); os.write(content.getBytes()); os.close();