This commit is contained in:
Fuzzlemann 2017-07-28 23:19:55 +02:00
commit afe1679b68
3 changed files with 38 additions and 12 deletions

View File

@ -138,4 +138,13 @@ public class Request implements Closeable {
public void close() throws IOException { public void close() throws IOException {
close.close(); close.close();
} }
@Override
public String toString() {
return "Request{" +
"request='" + request + '\'' +
", target='" + target + '\'' +
", authorization='" + authorization + '\'' +
'}';
}
} }

View File

@ -98,25 +98,25 @@ public class WebSocketServer {
trustManagerFactory.init(keystore); trustManagerFactory.init(keystore);
server = HttpsServer.create(new InetSocketAddress(PORT), 10); server = HttpsServer.create(new InetSocketAddress(PORT), 10);
SSLContext sslContext = SSLContext.getInstance("TLS"); SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); sslContext.init(keyManagerFactory.getKeyManagers(), null/*trustManagerFactory.getTrustManagers()*/, null);
((HttpsServer) server).setHttpsConfigurator(new HttpsConfigurator(sslContext) { ((HttpsServer) server).setHttpsConfigurator(new HttpsConfigurator(sslContext) {
public void configure(HttpsParameters params) { public void configure(HttpsParameters params) {
try { // try {
SSLContext c = SSLContext.getDefault(); // SSLContext c = SSLContext.getDefault();
SSLEngine engine = c.createSSLEngine(); SSLEngine engine = sslContext.createSSLEngine();
params.setNeedClientAuth(false); params.setNeedClientAuth(false);
params.setCipherSuites(engine.getEnabledCipherSuites()); params.setCipherSuites(engine.getEnabledCipherSuites());
params.setProtocols(engine.getEnabledProtocols()); params.setProtocols(engine.getEnabledProtocols());
SSLParameters defaultSSLParameters = c.getDefaultSSLParameters(); SSLParameters defaultSSLParameters = sslContext.getDefaultSSLParameters();
params.setSSLParameters(defaultSSLParameters); params.setSSLParameters(defaultSSLParameters);
} catch (NoSuchAlgorithmException e) { // } catch (NoSuchAlgorithmException e) {
Log.error("WebServer: SSL Engine loading Failed."); // Log.error("WebServer: SSL Engine loading Failed.");
Log.toLog(this.getClass().getName(), e); // Log.toLog(this.getClass().getName(), e);
} // }
} }
}); });
startSuccessful = true; startSuccessful = true;
@ -127,16 +127,21 @@ public class WebSocketServer {
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.error("WebServer: SSL Certificate KeyStore File not Found: " + keyStorePath); Log.error("WebServer: SSL Certificate KeyStore File not Found: " + keyStorePath);
Log.error("!--------!---------!---------!");
} catch (KeyStoreException | CertificateException | UnrecoverableKeyException e) { } catch (KeyStoreException | CertificateException | UnrecoverableKeyException e) {
Log.error("WebServer: SSL Certificate loading Failed."); Log.error("WebServer: SSL Certificate loading Failed.");
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
} }
Log.debug("Start Successful: "+startSuccessful);
if (!startSuccessful) { if (!startSuccessful) {
return; // TODO Http Server return; // TODO Http Server
} }
Log.debug("Create server context");
server.createContext("/", serverResponse(null)); server.createContext("/", serverResponse(null));
HttpContext analysisPage = server.createContext("/server", serverResponse(null)); HttpContext analysisPage = server.createContext("/server", serverResponse(null));
HttpContext playersPage = server.createContext("/players", new PlayersPageResponse(null, plugin)); HttpContext playersPage = server.createContext("/players", new PlayersPageResponse(null, plugin));

View File

@ -1,8 +1,11 @@
package main.java.com.djrapitops.plan.ui.webserver.response; 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.HttpExchange;
import com.sun.net.httpserver.HttpHandler; 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.Log;
import main.java.com.djrapitops.plan.ui.webserver.Request;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@ -57,10 +60,19 @@ public abstract class Response implements HttpHandler {
} }
@Override @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 { 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(); OutputStream os = exchange.getResponseBody();
os.write(content.getBytes()); os.write(content.getBytes());
os.close(); os.close();