This commit is contained in:
Fuzzlemann 2017-07-29 21:57:08 +02:00
commit 0064664c9c
2 changed files with 23 additions and 11 deletions

View File

@ -17,10 +17,7 @@ import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import javax.net.ssl.*; import javax.net.ssl.*;
import java.io.FileInputStream; import java.io.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URI; import java.net.URI;
import java.security.*; import java.security.*;
@ -29,7 +26,9 @@ import java.security.cert.CertificateException;
import java.util.Base64; import java.util.Base64;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Executors; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/** /**
* @author Rsl1122 * @author Rsl1122
@ -65,6 +64,7 @@ public class WebServer {
if (enabled) { if (enabled) {
return; return;
} }
Log.info(Phrase.WEBSERVER_INIT.toString()); Log.info(Phrase.WEBSERVER_INIT.toString());
try { try {
usingHttps = startHttpsServer(); usingHttps = startHttpsServer();
@ -97,9 +97,15 @@ public class WebServer {
String content = response.getContent(); String content = response.getContent();
exchange.sendResponseHeaders(response.getCode(), content.length()); exchange.sendResponseHeaders(response.getCode(), content.length());
os = exchange.getResponseBody(); try (BufferedOutputStream out = new BufferedOutputStream(exchange.getResponseBody())) {
try (ByteArrayInputStream bis = new ByteArrayInputStream(content.getBytes())) {
os.write(content.getBytes()); byte[] buffer = new byte[2048];
int count;
while ((count = bis.read(buffer)) != -1) {
out.write(buffer, 0, count);
}
}
}
} catch (Exception e) { } catch (Exception e) {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
throw e; throw e;
@ -109,7 +115,13 @@ public class WebServer {
} }
} }
}); });
server.setExecutor(Executors.newSingleThreadExecutor());
if (startSuccessful) {
context.setAuthenticator(new Authenticator(plugin, "/"));
}
server.setExecutor(new ThreadPoolExecutor(4, 8, 30, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100)));
server.start(); server.start();
enabled = true; enabled = true;

View File

@ -20,7 +20,7 @@ public class PlayersPageResponse extends Response {
} }
public static String buildContent(List<UserData> cached) { public static String buildContent(List<UserData> cached) {
StringBuilder html = new StringBuilder("<h1>Cached Players</h1><p>"); StringBuilder html = new StringBuilder("<!DOCTYPE html><html><body><h1>Cached Players</h1><p>");
int size = cached.size(); int size = cached.size();
html.append(size) html.append(size)
@ -37,7 +37,7 @@ public class PlayersPageResponse extends Response {
} }
i++; i++;
} }
html.append("</tr></table>"); html.append("</tr></table></body></html>");
return html.toString(); return html.toString();
} }
} }