From dd299cd8ee722cafb887ffb6a88b377e7f798f9c Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 29 Jul 2017 21:36:30 +0300 Subject: [PATCH] Fix Http Server Start when Certificate is not found. --- .../com/djrapitops/plan/ui/webserver/WebServer.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebServer.java b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebServer.java index bec2ec0e3..27606aab3 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebServer.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebServer.java @@ -72,15 +72,14 @@ public class WebServer { Log.debug(usingHttps ? "Https Start Successful." : "Https Start Failed."); if (!usingHttps) { - server = HttpServer.create(); + server = HttpServer.create(new InetSocketAddress(port), 10); } server.createContext("/", new HttpHandler() { @Override - public void handle(HttpExchange xchange) throws IOException { + public void handle(HttpExchange exchange) throws IOException { OutputStream os = null; try { - HttpsExchange exchange = (HttpsExchange) xchange; URI uri = exchange.getRequestURI(); String target = uri.toString(); @@ -106,13 +105,13 @@ public class WebServer { throw e; } finally { MiscUtils.close(os); - xchange.close(); + exchange.close(); } } }); server.setExecutor(Executors.newSingleThreadExecutor()); - server.start(); + enabled = true; Log.info(Phrase.WEBSERVER_RUNNING.parse(String.valueOf(server.getAddress().getPort()))); @@ -210,9 +209,7 @@ public class WebServer { 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("!--------!---------!---------!"); + Log.infoColor(ChatColor.YELLOW + "WebServer: SSL Certificate KeyStore File not Found: " + keyStorePath); Log.info("No Certificate -> Using Http server for Visualization."); Log.infoColor(ChatColor.YELLOW + "User Authorization Disabled! (Not possible over http)"); } catch (KeyStoreException | CertificateException | UnrecoverableKeyException e) {