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
This commit is contained in:
Rsl1122 2017-09-19 19:46:33 +03:00
parent ccc562913c
commit ad23d1e60d
11 changed files with 54 additions and 27 deletions

View File

@ -102,10 +102,12 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
@Override
public void onDisable() {
List<Processor> processors = processingQueue.stopAndReturnLeftovers();
Log.info("Processing unprocessed processors. (" + processors.size() + ")");
for (Processor processor : processors) {
processor.process();
if (processingQueue != null) {
List<Processor> processors = processingQueue.stopAndReturnLeftovers();
Log.info("Processing unprocessed processors. (" + processors.size() + ")");
for (Processor processor : processors) {
processor.process();
}
}
Log.info(Locale.get(Msg.DISABLED).toString());
}

View File

@ -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);

View File

@ -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<ServerInfo> 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

View File

@ -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());
}

View File

@ -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());

View File

@ -88,7 +88,7 @@ public class ResponseHandler extends APIResponseHandler {
case "server":
if (args.length > 2) {
try {
Optional<UUID> serverUUIDOptional = plugin.getDB().getServerTable().getServerUUID(args[2]);
Optional<UUID> 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) {

View File

@ -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));
}

View File

@ -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<UUID, String> uuidStringMap) {
// TODO
}
}

View File

@ -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<String, String> 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);

View File

@ -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");

View File

@ -53,7 +53,7 @@ public class UUIDUtility {
if (uuid == null) {
uuid = UUIDFetcher.getUUIDOf(playername);
}
} catch (Exception ignored) {
} catch (Exception | NoClassDefFoundError ignored) {
/* Ignored */
}
return uuid;