From ad23d1e60d4f8be0a29ce39269fd1534fb7c630c Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 19 Sep 2017 19:46:33 +0300 Subject: [PATCH] More BugFixing: - Fixed error when viewing inspect page with 0 bukkit servers - Fixed html caching with PostHtmlWebAPI - Fixed css serving on API mode WebServer - Fixed UUIDFetcher NoClassDefFoundError on Bungee Notable bugs that need fixing: - PostHtmlWebAPI html is cut short because of & or = signs --- .../java/com/djrapitops/plan/PlanBungee.java | 10 ++++++---- .../systems/info/BukkitInformationManager.java | 6 +++--- .../systems/info/BungeeInformationManager.java | 18 +++++++++++++++--- .../info/server/BungeeServerInfoManager.java | 7 ++++--- .../systems/webserver/APIResponseHandler.java | 14 ++++++++------ .../systems/webserver/ResponseHandler.java | 4 ++-- .../plan/systems/webserver/WebServer.java | 2 +- .../response/InspectPageResponse.java | 5 +++++ .../plan/systems/webserver/webapi/WebAPI.java | 9 +++++++-- .../webapi/bungee/PostHtmlWebAPI.java | 4 ++-- .../plan/utilities/uuid/UUIDUtility.java | 2 +- 11 files changed, 54 insertions(+), 27 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java index c6ddd558b..5049ce78d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java @@ -102,10 +102,12 @@ public class PlanBungee extends BungeePlugin implements IPlan { @Override public void onDisable() { - List processors = processingQueue.stopAndReturnLeftovers(); - Log.info("Processing unprocessed processors. (" + processors.size() + ")"); - for (Processor processor : processors) { - processor.process(); + if (processingQueue != null) { + List processors = processingQueue.stopAndReturnLeftovers(); + Log.info("Processing unprocessed processors. (" + processors.size() + ")"); + for (Processor processor : processors) { + processor.process(); + } } Log.info(Locale.get(Msg.DISABLED).toString()); } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java index 1460db343..63a94cc06 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java @@ -160,7 +160,7 @@ public class BukkitInformationManager extends InformationManager { Log.toLog(this.getClass().getName(), e); } } - return PageCache.isCached("analysisPage"); + return PageCache.isCached("analysisPage:" + serverUUID); } private WebAPIManager getWebAPI() { @@ -208,7 +208,7 @@ public class BukkitInformationManager extends InformationManager { Log.toLog(this.getClass().getName(), e); } } else { - PageCache.cachePage("analysisPage", () -> new AnalysisPageResponse(this)); + PageCache.cachePage("analysisPage:" + Plan.getServerUUID(), () -> new AnalysisPageResponse(this)); } } @@ -222,7 +222,7 @@ public class BukkitInformationManager extends InformationManager { @Override public boolean attemptConnection() { - Log.info("Attempting Bungee Connection.. ("+webServerAddress+")"); + Log.info("Attempting Bungee Connection.. (" + webServerAddress + ")"); PingWebAPI api = getWebAPI().getAPI(PingWebAPI.class); try { api.sendRequest(webServerAddress); diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/BungeeInformationManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/BungeeInformationManager.java index e16619dcf..051a5ed69 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/BungeeInformationManager.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/BungeeInformationManager.java @@ -12,6 +12,9 @@ import main.java.com.djrapitops.plan.api.exceptions.WebAPINotFoundException; import main.java.com.djrapitops.plan.systems.cache.DataCache; import main.java.com.djrapitops.plan.systems.info.server.ServerInfo; import main.java.com.djrapitops.plan.systems.webserver.PageCache; +import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse; +import main.java.com.djrapitops.plan.systems.webserver.response.NotFoundResponse; +import main.java.com.djrapitops.plan.systems.webserver.response.Response; import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager; import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.AnalyzeWebAPI; import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.InspectWebAPI; @@ -111,7 +114,11 @@ public class BungeeInformationManager extends InformationManager { } } - return bukkitServers.stream().findAny().get(); + Optional bukkitServer = bukkitServers.stream().findAny(); + if (bukkitServer.isPresent()) { + return bukkitServer.get(); + } + throw new IllegalStateException("No Bukkit servers online"); } @Override @@ -143,12 +150,17 @@ public class BungeeInformationManager extends InformationManager { @Override public String getPlayerHtml(UUID uuid) { - return null; + Response response = PageCache.loadPage("inspectPage:" + uuid, + () -> new NotFoundResponse("No Bukkit Servers were online to process this request")); + if (response instanceof InspectPageResponse) { + ((InspectPageResponse) response).setInspectPagePluginsTab(pluginsTabContent.get(uuid)); + } + return response.getContent(); } @Override public String getAnalysisHtml() { - return null; + return new NotFoundResponse("Network page not yet created").getContent(); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/server/BungeeServerInfoManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/server/BungeeServerInfoManager.java index f7ff81165..afea5e839 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/server/BungeeServerInfoManager.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/server/BungeeServerInfoManager.java @@ -83,8 +83,9 @@ public class BungeeServerInfoManager { return; } try { - Log.info("Attempting to connect to Bukkit server.. (" + server.getWebAddress() + ")"); - plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.class).sendRequest(server.getWebAddress()); + String webAddress = server.getWebAddress(); + Log.info("Attempting to connect to Bukkit server.. (" + webAddress + ")"); + plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.class).sendRequest(webAddress); connectedToServer(server); } catch (WebAPIException e) { serverHasGoneOffline(server.getUuid()); @@ -92,7 +93,7 @@ public class BungeeServerInfoManager { } public void connectedToServer(ServerInfo server) { - Log.info("Connection to Bukkit (" + server.getWebAddress() + ") succeeded."); + Log.info("Connection to Bukkit (" + server.getWebAddress() + ") OK"); bukkitServers.put(server.getUuid(), server); onlineServers.add(server.getUuid()); } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/APIResponseHandler.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/APIResponseHandler.java index 008b2d5fb..e4be680bc 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/APIResponseHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/APIResponseHandler.java @@ -5,9 +5,7 @@ package main.java.com.djrapitops.plan.systems.webserver; import main.java.com.djrapitops.plan.Log; -import main.java.com.djrapitops.plan.systems.webserver.response.ForbiddenResponse; -import main.java.com.djrapitops.plan.systems.webserver.response.NotFoundResponse; -import main.java.com.djrapitops.plan.systems.webserver.response.Response; +import main.java.com.djrapitops.plan.systems.webserver.response.*; import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse; import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI; import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager; @@ -42,6 +40,13 @@ public class APIResponseHandler { String target = request.getTarget(); String[] args = target.split("/"); + if ("/favicon.ico".equals(target)) { + return PageCache.loadPage("Redirect: favicon", () -> new RedirectResponse("https://puu.sh/tK0KL/6aa2ba141b.ico")); + } + if (target.endsWith(".css")) { + return PageCache.loadPage(target + "css", () -> new CSSResponse("main.css")); + } + if (args.length < 2 || !"api".equals(args[1])) { String address = MiscUtils.getIPlan().getInfoManager().getWebServerAddress() + target; String link = Html.LINK.parse(address, address); @@ -85,9 +90,6 @@ public class APIResponseHandler { return PageCache.loadPage(error, () -> new BadRequestResponse(error)); } - Log.debug(request.toString()); - Log.debug(requestBody); - Response response = api.processRequest(MiscUtils.getIPlan(), variables); Log.debug(response.toString()); diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/ResponseHandler.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/ResponseHandler.java index 88d40b0ef..d55050441 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/ResponseHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/ResponseHandler.java @@ -88,7 +88,7 @@ public class ResponseHandler extends APIResponseHandler { case "server": if (args.length > 2) { try { - Optional serverUUIDOptional = plugin.getDB().getServerTable().getServerUUID(args[2]); + Optional serverUUIDOptional = plugin.getDB().getServerTable().getServerUUID(args[2].replace("%20", " ")); if (serverUUIDOptional.isPresent()) { serverUUID = serverUUIDOptional.get(); } @@ -195,7 +195,7 @@ public class ResponseHandler extends APIResponseHandler { PageCache.loadPage("notFound: " + error, () -> new NotFoundResponse(error)); } - return PageCache.loadPage("analysisPage", () -> new AnalysisPageResponse(plugin.getInfoManager())); + return PageCache.loadPage("analysisPage:" + serverUUID, () -> new AnalysisPageResponse(plugin.getInfoManager())); } private Response playerResponse(String[] args) { diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/WebServer.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/WebServer.java index 4a8d404a0..beb17f3c9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/WebServer.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/WebServer.java @@ -89,9 +89,9 @@ public class WebServer { Log.infoColor("§eUser Authorization Disabled! (Not possible over http)"); server = HttpServer.create(new InetSocketAddress(port), 10); } - if (plugin.getInfoManager().isUsingAnotherWebServer()) { server.createContext("/", new APIRequestHandler(getWebAPI())); + Log.infoColor("§aWebServer Running in WebAPI-only Mode"); } else { server.createContext("/", new RequestHandler(plugin, this)); } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/InspectPageResponse.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/InspectPageResponse.java index f1039190c..f13e62e1a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/InspectPageResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/response/InspectPageResponse.java @@ -3,6 +3,7 @@ package main.java.com.djrapitops.plan.systems.webserver.response; import main.java.com.djrapitops.plan.systems.info.InformationManager; import main.java.com.djrapitops.plan.systems.webserver.theme.Theme; +import java.util.Map; import java.util.UUID; /** @@ -33,4 +34,8 @@ public class InspectPageResponse extends Response { } this.inspectPagePluginsTab = inspectPagePluginsTab; } + + public void setInspectPagePluginsTab(Map uuidStringMap) { + // TODO + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/WebAPI.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/WebAPI.java index 0c4397b7f..966a9e9a9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/WebAPI.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/WebAPI.java @@ -90,6 +90,7 @@ public abstract class WebAPI { connection.setInstanceFollowRedirects(false); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + connection.setRequestProperty("charset", "ISO-8859-1"); StringBuilder parameters = new StringBuilder(); @@ -98,10 +99,14 @@ public abstract class WebAPI { for (Map.Entry entry : variables.entrySet()) { parameters.append("&").append(entry.getKey()).append("=").append(entry.getValue()); } - byte[] toSend = parameters.toString().getBytes(); + String params = parameters.toString(); + + connection.setRequestProperty("Content-Length", Integer.toString(params.length())); + + byte[] toSend = params.getBytes(); int length = toSend.length; - connection.setRequestProperty("Content-Length", Integer.toString(length)); +// connection.setRequestProperty("Content-Length", Integer.toString(length)); connection.setUseCaches(false); Log.debug("Sending WebAPI Request: " + this.getClass().getSimpleName() + " to " + address); diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/bungee/PostHtmlWebAPI.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/bungee/PostHtmlWebAPI.java index 25db9c40f..a3efab2c2 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/bungee/PostHtmlWebAPI.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/bungee/PostHtmlWebAPI.java @@ -32,10 +32,10 @@ public class PostHtmlWebAPI extends WebAPI { switch (target) { case "inspectPage": String uuid = variables.get("uuid"); - PageCache.loadPage("inspectPage:" + uuid, () -> new InspectPageResponse(infoManager, UUID.fromString(uuid), html)); + PageCache.cachePage("inspectPage:" + uuid, () -> new InspectPageResponse(infoManager, UUID.fromString(uuid), html)); break; case "analysisPage": - PageCache.loadPage("analysisPage:" + variables.get("sender"), () -> new AnalysisPageResponse(html)); + PageCache.cachePage("analysisPage:" + variables.get("sender"), () -> new AnalysisPageResponse(html)); break; default: return badRequest("Faulty Target"); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java b/Plan/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java index d3ccb4e11..54219de2a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java @@ -53,7 +53,7 @@ public class UUIDUtility { if (uuid == null) { uuid = UUIDFetcher.getUUIDOf(playername); } - } catch (Exception ignored) { + } catch (Exception | NoClassDefFoundError ignored) { /* Ignored */ } return uuid;