Fix Http Server Start when Certificate is not found.

This commit is contained in:
Rsl1122 2017-07-29 21:36:30 +03:00
parent 0b0ef2941d
commit dd299cd8ee

View File

@ -72,15 +72,14 @@ public class WebServer {
Log.debug(usingHttps ? "Https Start Successful." : "Https Start Failed."); Log.debug(usingHttps ? "Https Start Successful." : "Https Start Failed.");
if (!usingHttps) { if (!usingHttps) {
server = HttpServer.create(); server = HttpServer.create(new InetSocketAddress(port), 10);
} }
server.createContext("/", new HttpHandler() { server.createContext("/", new HttpHandler() {
@Override @Override
public void handle(HttpExchange xchange) throws IOException { public void handle(HttpExchange exchange) throws IOException {
OutputStream os = null; OutputStream os = null;
try { try {
HttpsExchange exchange = (HttpsExchange) xchange;
URI uri = exchange.getRequestURI(); URI uri = exchange.getRequestURI();
String target = uri.toString(); String target = uri.toString();
@ -106,13 +105,13 @@ public class WebServer {
throw e; throw e;
} finally { } finally {
MiscUtils.close(os); MiscUtils.close(os);
xchange.close(); exchange.close();
} }
} }
}); });
server.setExecutor(Executors.newSingleThreadExecutor()); server.setExecutor(Executors.newSingleThreadExecutor());
server.start(); server.start();
enabled = true; enabled = true;
Log.info(Phrase.WEBSERVER_RUNNING.parse(String.valueOf(server.getAddress().getPort()))); 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.error("WebServer: SSL Context Initialization Failed.");
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.error("!--------!---------!---------!"); Log.infoColor(ChatColor.YELLOW + "WebServer: SSL Certificate KeyStore File not Found: " + keyStorePath);
Log.error("WebServer: SSL Certificate KeyStore File not Found: " + keyStorePath);
Log.error("!--------!---------!---------!");
Log.info("No Certificate -> Using Http server for Visualization."); Log.info("No Certificate -> Using Http server for Visualization.");
Log.infoColor(ChatColor.YELLOW + "User Authorization Disabled! (Not possible over http)"); Log.infoColor(ChatColor.YELLOW + "User Authorization Disabled! (Not possible over http)");
} catch (KeyStoreException | CertificateException | UnrecoverableKeyException e) { } catch (KeyStoreException | CertificateException | UnrecoverableKeyException e) {