InfoRequestWithVariables, GenerateInspectPage, GenerateAnalysisPage

This commit is contained in:
Rsl1122 2018-01-17 18:09:26 +02:00
parent 7118c67c7e
commit 1b8ccff2f8
35 changed files with 344 additions and 85 deletions

View File

@ -0,0 +1,17 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.api.exceptions.connection;
/**
* Thrown when connection is returned 401 Bad Request.
*
* @author Rsl1122
*/
public class BadRequestException extends WebException {
public BadRequestException(String message) {
super(message);
}
}

View File

@ -9,8 +9,8 @@ package com.djrapitops.plan.api.exceptions.connection;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
public class WebForbiddenException extends WebFailException { public class ForbiddenException extends WebFailException {
public WebForbiddenException(String url) { public ForbiddenException(String url) {
super("Forbidden: " + url); super("Forbidden: " + url);
} }
} }

View File

@ -9,8 +9,8 @@ package com.djrapitops.plan.api.exceptions.connection;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
public class WebInternalErrorException extends WebFailException { public class InternalErrorException extends WebFailException {
public WebInternalErrorException() { public InternalErrorException() {
super("Internal Error occurred on receiving server"); super("Internal Error occurred on receiving server");
} }
} }

View File

@ -9,8 +9,8 @@ package com.djrapitops.plan.api.exceptions.connection;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
public class WebNotFoundException extends WebFailException { public class NotFoundException extends WebFailException {
public WebNotFoundException() { public NotFoundException() {
super("Not Found"); super("Not Found");
} }
} }

View File

@ -9,20 +9,20 @@ package com.djrapitops.plan.api.exceptions.connection;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
public class WebUnauthorizedServerException extends WebFailException { public class UnauthorizedServerException extends WebFailException {
public WebUnauthorizedServerException() { public UnauthorizedServerException() {
} }
public WebUnauthorizedServerException(String message) { public UnauthorizedServerException(String message) {
super(message); super(message);
} }
public WebUnauthorizedServerException(String message, Throwable cause) { public UnauthorizedServerException(String message, Throwable cause) {
super(message, cause); super(message, cause);
} }
public WebUnauthorizedServerException(Throwable cause) { public UnauthorizedServerException(Throwable cause) {
super(cause); super(cause);
} }
} }

View File

@ -4,6 +4,8 @@
*/ */
package com.djrapitops.plan.api.exceptions.connection; package com.djrapitops.plan.api.exceptions.connection;
import com.djrapitops.plan.system.database.databases.Database;
/** /**
* //TODO Class Javadoc Comment * //TODO Class Javadoc Comment
* *
@ -11,10 +13,7 @@ package com.djrapitops.plan.api.exceptions.connection;
*/ */
public class UnsupportedTransferDatabaseException extends WebException { public class UnsupportedTransferDatabaseException extends WebException {
public UnsupportedTransferDatabaseException() { public UnsupportedTransferDatabaseException(Database db) {
} super(db.getName() + " does not support Transfer operations!");
public UnsupportedTransferDatabaseException(String message) {
super(message);
} }
} }

View File

@ -1,8 +1,8 @@
package com.djrapitops.plan.command.commands.manage; package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.connection.ForbiddenException;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.api.exceptions.connection.WebForbiddenException;
import com.djrapitops.plan.settings.locale.Locale; import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.Msg; import com.djrapitops.plan.settings.locale.Msg;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
@ -71,7 +71,7 @@ public class ManageSetupCommand extends SubCommand {
// plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.class).sendRequest(address); // plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.class).sendRequest(address);
plugin.getWebServer().getWebAPI().getAPI(RequestSetupWebAPI.class).sendRequest(address); plugin.getWebServer().getWebAPI().getAPI(RequestSetupWebAPI.class).sendRequest(address);
sender.sendMessage("§eConnection successful, Plan may restart in a few seconds, if it doesn't something has gone wrong."); sender.sendMessage("§eConnection successful, Plan may restart in a few seconds, if it doesn't something has gone wrong.");
} catch (WebForbiddenException e) { } catch (ForbiddenException e) {
sender.sendMessage("§eConnection succeeded, but Bungee has set-up mode disabled - use '/planbungee setup' to enable it."); sender.sendMessage("§eConnection succeeded, but Bungee has set-up mode disabled - use '/planbungee setup' to enable it.");
} catch (WebException e) { } catch (WebException e) {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);

View File

@ -6,6 +6,7 @@ package com.djrapitops.plan.system.database.databases.operation;
import com.djrapitops.plan.api.exceptions.database.DBException; import com.djrapitops.plan.api.exceptions.database.DBException;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
/** /**
@ -14,5 +15,12 @@ import java.util.UUID;
* @author Rsl1122 * @author Rsl1122
*/ */
public interface TransferOperations { public interface TransferOperations {
// Save
void playerHtml(UUID player, String html) throws DBException; void playerHtml(UUID player, String html) throws DBException;
// Get
Map<UUID, String> getPlayerHtml() throws DBException;
} }

View File

@ -4,13 +4,23 @@
*/ */
package com.djrapitops.plan.system.info; package com.djrapitops.plan.system.info;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.request.GenerateAnalysisPageRequest;
import com.djrapitops.plan.system.info.request.GenerateInspectPageRequest;
import com.djrapitops.plan.system.info.request.InfoRequest;
import com.djrapitops.plan.utilities.NullCheck; import com.djrapitops.plan.utilities.NullCheck;
import java.util.UUID;
/** /**
* //TODO Class Javadoc Comment * Information management system.
*
* Subclasses should decide how InfoRequests are run locally if necessary.
* *
* @author Rsl1122 * @author Rsl1122
*/ */
@ -18,7 +28,7 @@ public abstract class InfoSystem implements SubSystem {
protected final ConnectionSystem connectionSystem; protected final ConnectionSystem connectionSystem;
public InfoSystem(ConnectionSystem connectionSystem) { protected InfoSystem(ConnectionSystem connectionSystem) {
this.connectionSystem = connectionSystem; this.connectionSystem = connectionSystem;
} }
@ -28,14 +38,40 @@ public abstract class InfoSystem implements SubSystem {
return infoSystem; return infoSystem;
} }
@Override public void generatePlayerPage(UUID player) throws WebException {
public void enable() { sendRequest(new GenerateInspectPageRequest(player));
}
public void generateAnalysisPageOfThisServer() throws WebException {
generateAnalysisPage(Plan.getServerUUID());
}
public void generateAnalysisPage(UUID serverUUID) throws WebException {
GenerateAnalysisPageRequest request = new GenerateAnalysisPageRequest(serverUUID);
if (Plan.getServerUUID().equals(serverUUID)) {
runLocally(request);
} else {
sendRequest(request);
}
}
public void sendRequest(InfoRequest infoRequest) throws WebException {
if (!connectionSystem.isServerAvailable()) {
runLocally(infoRequest);
}
connectionSystem.sendInfoRequest(infoRequest);
}
protected abstract void runLocally(InfoRequest infoRequest);
@Override
public void enable() throws EnableException {
connectionSystem.enable();
} }
@Override @Override
public void disable() { public void disable() {
connectionSystem.disable();
} }
public ConnectionSystem getConnectionSystem() { public ConnectionSystem getConnectionSystem() {

View File

@ -6,6 +6,7 @@ package com.djrapitops.plan.system.info.connection;
import com.djrapitops.plan.api.exceptions.connection.*; import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plan.system.info.request.InfoRequest; import com.djrapitops.plan.system.info.request.InfoRequest;
import com.djrapitops.plan.system.info.request.InfoRequestWithVariables;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
@ -18,6 +19,7 @@ import java.net.SocketTimeoutException;
import java.net.URL; import java.net.URL;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
/** /**
@ -117,13 +119,13 @@ public class ConnectionOut {
case 400: case 400:
throw new WebFailException("Bad Request: " + url.toString() + "|" + parameters); throw new WebFailException("Bad Request: " + url.toString() + "|" + parameters);
case 403: case 403:
throw new WebForbiddenException(url.toString()); throw new ForbiddenException(url.toString());
case 404: case 404:
throw new WebNotFoundException(); throw new NotFoundException();
case 412: case 412:
throw new WebUnauthorizedServerException(); throw new UnauthorizedServerException();
case 500: case 500:
throw new WebInternalErrorException(); throw new InternalErrorException();
default: default:
throw new WebException(url.toString() + "| Wrong response code " + responseCode); throw new WebException(url.toString() + "| Wrong response code " + responseCode);
} }
@ -138,8 +140,17 @@ public class ConnectionOut {
} }
private String parseVariables() { private String parseVariables() {
return "sender=" + serverUUID + ";&variable;" + StringBuilder parameters = new StringBuilder("sender=" + serverUUID + ";&variable;" +
"type=" + infoRequest.getClass().getSimpleName(); "type=" + infoRequest.getClass().getSimpleName());
if (infoRequest instanceof InfoRequestWithVariables) {
Map<String, String> variables = ((InfoRequestWithVariables) infoRequest).getVariables();
for (Map.Entry<String, String> entry : variables.entrySet()) {
parameters.append(";&variable;").append(entry.getKey()).append("=").append(entry.getValue());
}
}
return parameters.toString();
} }
private SSLSocketFactory getRelaxedSocketFactory() throws NoSuchAlgorithmException, KeyManagementException { private SSLSocketFactory getRelaxedSocketFactory() throws NoSuchAlgorithmException, KeyManagementException {

View File

@ -6,6 +6,7 @@ package com.djrapitops.plan.system.info.connection;
import com.djrapitops.plan.api.exceptions.connection.NoServersException; import com.djrapitops.plan.api.exceptions.connection.NoServersException;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.request.CacheInspectPageRequest; import com.djrapitops.plan.system.info.request.CacheInspectPageRequest;
import com.djrapitops.plan.system.info.request.InfoRequest; import com.djrapitops.plan.system.info.request.InfoRequest;
@ -23,7 +24,7 @@ import java.util.UUID;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
public abstract class ConnectionSystem { public abstract class ConnectionSystem implements SubSystem {
protected final Map<String, InfoRequest> dataRequests; protected final Map<String, InfoRequest> dataRequests;
protected final UUID serverUUID; protected final UUID serverUUID;
@ -60,4 +61,6 @@ public abstract class ConnectionSystem {
new ConnectionOut(address, serverUUID, infoRequest).sendRequest(); new ConnectionOut(address, serverUUID, infoRequest).sendRequest();
} }
public abstract boolean isServerAvailable();
} }

View File

@ -8,7 +8,11 @@ import com.djrapitops.plan.api.exceptions.connection.TransferDatabaseException;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.api.exceptions.database.DBException; import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.webserver.pages.DefaultResponses;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.pages.InspectPageResponse;
import com.djrapitops.plan.utilities.Base64Util; import com.djrapitops.plan.utilities.Base64Util;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
@ -52,7 +56,21 @@ public class CacheInspectPageRequest implements InfoRequest {
} }
@Override @Override
public Response handleRequest(Map<String, String> variables) { public Response handleRequest(Map<String, String> variables) throws WebException {
return null; // Available variables: sender
try {
Map<UUID, String> pages = Database.getActive().transfer().getPlayerHtml();
for (Map.Entry<UUID, String> entry : pages.entrySet()) {
UUID uuid = entry.getKey();
String html = Base64Util.decode(entry.getValue());
ResponseCache.cacheResponse(PageId.PLAYER.of(uuid), () -> new InspectPageResponse(uuid, html));
}
} catch (DBException e) {
throw new TransferDatabaseException(e);
}
return DefaultResponses.SUCCESS.get();
} }
} }

View File

@ -0,0 +1,32 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.system.info.request;
import com.djrapitops.plan.system.webserver.response.Response;
import java.util.Map;
import java.util.UUID;
/**
* InfoRequest to generate Analysis page HTML at the receiving end.
*
* @author Rsl1122
*/
public class GenerateAnalysisPageRequest extends InfoRequestWithVariables {
public GenerateAnalysisPageRequest(UUID serverUUID) {
variables.put("server", serverUUID.toString());
}
@Override
public void placeDataToDatabase() {
}
@Override
public Response handleRequest(Map<String, String> variables) {
return null;
}
}

View File

@ -0,0 +1,45 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.system.info.request;
import com.djrapitops.plan.api.exceptions.connection.BadRequestException;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.webserver.pages.DefaultResponses;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.utilities.NullCheck;
import java.util.Map;
import java.util.UUID;
/**
* InfoRequest for Generating Inspect page on receiving WebServer.
*
* @author Rsl1122
*/
public class GenerateInspectPageRequest extends InfoRequestWithVariables {
public GenerateInspectPageRequest(UUID uuid) {
variables.put("player", uuid.toString());
}
@Override
public void placeDataToDatabase() {
}
@Override
public Response handleRequest(Map<String, String> variables) throws WebException {
// Available variables: sender, player
String player = variables.get("player");
NullCheck.check(player, new BadRequestException("Player UUID 'player' variable not supplied."));
UUID uuid = UUID.fromString(player);
// TODO Generate HTML
// TODO InfoSystem.getInstance().sendRequest(new CacheInspectPageRequest(uuid, html));
return DefaultResponses.SUCCESS.get();
}
}

View File

@ -18,6 +18,6 @@ public interface InfoRequest {
void placeDataToDatabase() throws WebException; void placeDataToDatabase() throws WebException;
Response handleRequest(Map<String, String> variables); Response handleRequest(Map<String, String> variables) throws WebException;
} }

View File

@ -0,0 +1,28 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.system.info.request;
import java.util.HashMap;
import java.util.Map;
/**
* Abstract InfoRequest that contains variables in request body.
* <p>
* Used to send request differently.
*
* @author Rsl1122
*/
public abstract class InfoRequestWithVariables implements InfoRequest {
protected final Map<String, String> variables;
public InfoRequestWithVariables() {
this.variables = new HashMap<>();
}
public Map<String, String> getVariables() {
return variables;
}
}

View File

@ -6,10 +6,10 @@ package com.djrapitops.plan.system.webserver;
import com.djrapitops.plan.api.exceptions.WebUserAuthException; import com.djrapitops.plan.api.exceptions.WebUserAuthException;
import com.djrapitops.plan.system.webserver.auth.Authentication; import com.djrapitops.plan.system.webserver.auth.Authentication;
import com.djrapitops.plan.system.webserver.pagecache.PageId;
import com.djrapitops.plan.system.webserver.pagecache.ResponseCache;
import com.djrapitops.plan.system.webserver.pages.*; import com.djrapitops.plan.system.webserver.pages.*;
import com.djrapitops.plan.system.webserver.response.*; import com.djrapitops.plan.system.webserver.response.*;
import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.errors.ForbiddenResponse; import com.djrapitops.plan.system.webserver.response.errors.ForbiddenResponse;
import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse; import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;

View File

@ -7,7 +7,7 @@ package com.djrapitops.plan.system.webserver;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.webserver.pagecache.ResponseCache; import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.api.Check;
/** /**

View File

@ -6,6 +6,7 @@ package com.djrapitops.plan.system.webserver.pages;
import com.djrapitops.plan.system.webserver.response.PromptAuthorizationResponse; import com.djrapitops.plan.system.webserver.response.PromptAuthorizationResponse;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.api.SuccessResponse;
import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse; import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse;
/** /**
@ -19,7 +20,8 @@ public enum DefaultResponses {
+ "<p>/player/PlayerName<br>" + + "<p>/player/PlayerName<br>" +
"/server/ServerName</p>") "/server/ServerName</p>")
), ),
BASIC_AUTH(PromptAuthorizationResponse.getBasicAuthResponse()); BASIC_AUTH(PromptAuthorizationResponse.getBasicAuthResponse()),
SUCCESS(new SuccessResponse());
private final Response response; private final Response response;

View File

@ -12,9 +12,9 @@ import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.webserver.Request; import com.djrapitops.plan.system.webserver.Request;
import com.djrapitops.plan.system.webserver.auth.Authentication; import com.djrapitops.plan.system.webserver.auth.Authentication;
import com.djrapitops.plan.system.webserver.pagecache.PageId;
import com.djrapitops.plan.system.webserver.pagecache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse; import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse;
import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse; import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse;
import com.djrapitops.plan.system.webserver.response.pages.InspectPageResponse; import com.djrapitops.plan.system.webserver.response.pages.InspectPageResponse;

View File

@ -7,9 +7,9 @@ package com.djrapitops.plan.system.webserver.pages;
import com.djrapitops.plan.api.exceptions.WebUserAuthException; import com.djrapitops.plan.api.exceptions.WebUserAuthException;
import com.djrapitops.plan.system.webserver.Request; import com.djrapitops.plan.system.webserver.Request;
import com.djrapitops.plan.system.webserver.auth.Authentication; import com.djrapitops.plan.system.webserver.auth.Authentication;
import com.djrapitops.plan.system.webserver.pagecache.PageId;
import com.djrapitops.plan.system.webserver.pagecache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.pages.PlayersPageResponse; import com.djrapitops.plan.system.webserver.response.pages.PlayersPageResponse;
import java.util.List; import java.util.List;

View File

@ -9,9 +9,9 @@ import com.djrapitops.plan.api.exceptions.WebUserAuthException;
import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.webserver.Request; import com.djrapitops.plan.system.webserver.Request;
import com.djrapitops.plan.system.webserver.auth.Authentication; import com.djrapitops.plan.system.webserver.auth.Authentication;
import com.djrapitops.plan.system.webserver.pagecache.PageId;
import com.djrapitops.plan.system.webserver.pagecache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.pages.AnalysisPageResponse; import com.djrapitops.plan.system.webserver.response.pages.AnalysisPageResponse;
import java.util.List; import java.util.List;

View File

@ -2,7 +2,7 @@
* Licence is provided in the jar as license.yml also here: * Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/ */
package com.djrapitops.plan.system.webserver.pagecache; package com.djrapitops.plan.system.webserver.response.cache;
import java.util.UUID; import java.util.UUID;
@ -27,7 +27,9 @@ public enum PageId {
CSS("css:"), CSS("css:"),
// //
FAVICON_REDIRECT("Redirect:Favicon"), FAVICON_REDIRECT("Redirect:Favicon"),
AUTH_PROMPT("PromptAuth"); AUTH_PROMPT("PromptAuth"),
//
PLAYER_PLUGINS_TAB("playerPluginsTab:");
private final String id; private final String id;

View File

@ -1,4 +1,4 @@
package com.djrapitops.plan.system.webserver.pagecache; package com.djrapitops.plan.system.webserver.response.cache;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;

View File

@ -1,4 +1,4 @@
package com.djrapitops.plan.system.webserver.pagecache; package com.djrapitops.plan.system.webserver.response.cache;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.pages.InspectPageResponse; import com.djrapitops.plan.system.webserver.response.pages.InspectPageResponse;

View File

@ -1,9 +1,10 @@
package com.djrapitops.plan.system.webserver.response.pages; package com.djrapitops.plan.system.webserver.response.pages;
import com.djrapitops.plan.api.exceptions.ParseException;
import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.systems.info.InformationManager; import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.pages.parts.InspectPagePluginsContent;
import org.apache.commons.lang3.text.StrSubstitutor; import org.apache.commons.lang3.text.StrSubstitutor;
import java.util.HashMap; import java.util.HashMap;
@ -17,19 +18,14 @@ import java.util.UUID;
public class InspectPageResponse extends Response { public class InspectPageResponse extends Response {
private final UUID uuid; private final UUID uuid;
private InspectPagePluginsContent pluginsTab;
public InspectPageResponse(InformationManager infoManager, UUID uuid) throws ParseException { public InspectPageResponse(UUID uuid, String html) {
this.uuid = uuid;
super.setHeader("HTTP/1.1 200 OK");
super.setContent(infoManager.getPlayerHtml(uuid));
setInspectPagePluginsTab(infoManager.getPluginsTabContent(uuid));
}
public InspectPageResponse(InformationManager infoManager, UUID uuid, String html) {
this.uuid = uuid; this.uuid = uuid;
super.setHeader("HTTP/1.1 200 OK"); super.setHeader("HTTP/1.1 200 OK");
super.setContent(Theme.replaceColors(html)); super.setContent(Theme.replaceColors(html));
setInspectPagePluginsTab(infoManager.getPluginsTabContent(uuid)); pluginsTab = (InspectPagePluginsContent)
ResponseCache.loadResponse(PageId.PLAYER_PLUGINS_TAB.of(uuid), InspectPagePluginsContent::new);
} }
private InspectPageResponse(InspectPageResponse response) { private InspectPageResponse(InspectPageResponse response) {
@ -42,11 +38,14 @@ public class InspectPageResponse extends Response {
return new InspectPageResponse(response); return new InspectPageResponse(response);
} }
public void setInspectPagePluginsTab(String[] inspectPagePluginsTab) { @Override
public String getContent() {
Map<String, String> replaceMap = new HashMap<>(); Map<String, String> replaceMap = new HashMap<>();
String[] inspectPagePluginsTab = pluginsTab.getContents();
replaceMap.put("navPluginsTabs", inspectPagePluginsTab[0]); replaceMap.put("navPluginsTabs", inspectPagePluginsTab[0]);
replaceMap.put("pluginsTabs", inspectPagePluginsTab[1]); replaceMap.put("pluginsTabs", inspectPagePluginsTab[1]);
setContent(StrSubstitutor.replace(getContent(), replaceMap)); return StrSubstitutor.replace(super.getContent(), replaceMap);
} }
} }

View File

@ -0,0 +1,59 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.system.webserver.response.pages.parts;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.utilities.html.HtmlStructure;
import java.util.*;
/**
* Represents Plugins tabs on Inspect page.
* <p>
* Extends Response so that it can be stored in ResponseCache.
*
* @author Rsl1122
*/
public class InspectPagePluginsContent extends Response {
// ServerUUID, {nav, html}
private final Map<UUID, String[]> pluginsTab;
public InspectPagePluginsContent() {
pluginsTab = new HashMap<>();
}
public InspectPagePluginsContent(UUID serverUUID, String nav, String html) {
pluginsTab = new HashMap<>();
addTab(serverUUID, nav, html);
}
public void addTab(UUID serverUUID, String nav, String html) {
pluginsTab.put(serverUUID, new String[]{nav, html});
}
public void addTab(InspectPagePluginsContent content) {
pluginsTab.putAll(content.pluginsTab);
}
public String[] getContents() {
if (pluginsTab.isEmpty()) {
return HtmlStructure.createInspectPageTabContentCalculating();
}
List<String[]> order = new ArrayList<>(pluginsTab.values());
// Sort serverNames alphabetically
order.sort(Comparator.comparing(name -> name[0]));
StringBuilder nav = new StringBuilder();
StringBuilder tabs = new StringBuilder();
for (String[] tab : order) {
nav.append(tab[0]);
tabs.append(tab[1]);
}
return new String[]{nav.toString(), tabs.toString()};
}
}

View File

@ -7,11 +7,11 @@ package com.djrapitops.plan.system.webserver.webapi;
import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.*; import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.webserver.pagecache.PageId;
import com.djrapitops.plan.system.webserver.pagecache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.api.BadRequestResponse; import com.djrapitops.plan.system.webserver.response.api.BadRequestResponse;
import com.djrapitops.plan.system.webserver.response.api.SuccessResponse; import com.djrapitops.plan.system.webserver.response.api.SuccessResponse;
import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse; import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify; import com.djrapitops.plugin.utilities.Verify;
@ -141,11 +141,11 @@ public abstract class WebAPI {
case 400: case 400:
throw new WebFailException("Bad Request: " + url.toString() + "|" + parameters); throw new WebFailException("Bad Request: " + url.toString() + "|" + parameters);
case 403: case 403:
throw new WebForbiddenException(url.toString()); throw new ForbiddenException(url.toString());
case 404: case 404:
throw new WebNotFoundException(); throw new NotFoundException();
case 500: case 500:
throw new WebInternalErrorException(); throw new InternalErrorException();
default: default:
throw new WebException(url.toString() + "| Wrong response code " + responseCode); throw new WebException(url.toString() + "| Wrong response code " + responseCode);
} }

View File

@ -5,8 +5,8 @@
package com.djrapitops.plan.system.webserver.webapi.bungee; package com.djrapitops.plan.system.webserver.webapi.bungee;
import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.NotFoundException;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.api.exceptions.connection.WebNotFoundException;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.webapi.WebAPI; import com.djrapitops.plan.system.webserver.webapi.WebAPI;
import com.djrapitops.plan.systems.info.InformationManager; import com.djrapitops.plan.systems.info.InformationManager;
@ -62,7 +62,7 @@ public class IsCachedWebAPI extends WebAPI {
try { try {
super.sendRequest(address); super.sendRequest(address);
return true; return true;
} catch (WebNotFoundException e) { } catch (NotFoundException e) {
return false; return false;
} }
} }
@ -73,7 +73,7 @@ public class IsCachedWebAPI extends WebAPI {
try { try {
super.sendRequest(address); super.sendRequest(address);
return true; return true;
} catch (WebNotFoundException e) { } catch (NotFoundException e) {
return false; return false;
} }
} }

View File

@ -7,9 +7,9 @@ package com.djrapitops.plan.system.webserver.webapi.bungee;
import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.webserver.pagecache.PageId;
import com.djrapitops.plan.system.webserver.pagecache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.pages.AnalysisPageResponse; import com.djrapitops.plan.system.webserver.response.pages.AnalysisPageResponse;
import com.djrapitops.plan.system.webserver.response.pages.InspectPageResponse; import com.djrapitops.plan.system.webserver.response.pages.InspectPageResponse;
import com.djrapitops.plan.system.webserver.webapi.WebAPI; import com.djrapitops.plan.system.webserver.webapi.WebAPI;

View File

@ -7,9 +7,9 @@ package com.djrapitops.plan.systems.info;
import com.djrapitops.plan.Plan; import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.ParseException; import com.djrapitops.plan.api.exceptions.ParseException;
import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException; import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException;
import com.djrapitops.plan.api.exceptions.connection.NotFoundException;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.api.exceptions.connection.WebFailException; import com.djrapitops.plan.api.exceptions.connection.WebFailException;
import com.djrapitops.plan.api.exceptions.connection.WebNotFoundException;
import com.djrapitops.plan.command.commands.AnalyzeCommand; import com.djrapitops.plan.command.commands.AnalyzeCommand;
import com.djrapitops.plan.data.AnalysisData; import com.djrapitops.plan.data.AnalysisData;
import com.djrapitops.plan.data.element.InspectContainer; import com.djrapitops.plan.data.element.InspectContainer;
@ -21,9 +21,9 @@ import com.djrapitops.plan.system.processing.processors.Processor;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.webserver.WebServer; import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.system.webserver.WebServerSystem; import com.djrapitops.plan.system.webserver.WebServerSystem;
import com.djrapitops.plan.system.webserver.pagecache.PageId;
import com.djrapitops.plan.system.webserver.pagecache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse; import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse;
import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse; import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse;
import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse; import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse;
@ -346,7 +346,7 @@ public class BukkitInformationManager extends InformationManager {
return true; return true;
} catch (ConnectionFailException e) { } catch (ConnectionFailException e) {
plugin.getServerInfoManager().markConnectionFail(); plugin.getServerInfoManager().markConnectionFail();
} catch (WebNotFoundException e) { } catch (NotFoundException e) {
Log.info("Bungee reported that UUID of this server is not in the MySQL-database. Try using '/plan m setup " + webServerAddress + "' again"); Log.info("Bungee reported that UUID of this server is not in the MySQL-database. Try using '/plan m setup " + webServerAddress + "' again");
} catch (WebException e) { } catch (WebException e) {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);

View File

@ -8,13 +8,13 @@ import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.ParseException; import com.djrapitops.plan.api.exceptions.ParseException;
import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException; import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException;
import com.djrapitops.plan.api.exceptions.connection.NotFoundException;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.api.exceptions.connection.WebNotFoundException;
import com.djrapitops.plan.system.cache.DataCache; import com.djrapitops.plan.system.cache.DataCache;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.webserver.pagecache.PageId;
import com.djrapitops.plan.system.webserver.pagecache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse; import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse;
import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse; import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse;
import com.djrapitops.plan.system.webserver.response.pages.AnalysisPageResponse; import com.djrapitops.plan.system.webserver.response.pages.AnalysisPageResponse;
@ -183,7 +183,7 @@ public class BungeeInformationManager extends InformationManager {
return server; return server;
} catch (ConnectionFailException e) { } catch (ConnectionFailException e) {
serverInfoManager.serverHasGoneOffline(server.getUuid()); serverInfoManager.serverHasGoneOffline(server.getUuid());
} catch (WebNotFoundException ignored) { } catch (NotFoundException ignored) {
/*continue*/ /*continue*/
} catch (WebException e) { } catch (WebException e) {
Log.toLog(this.getClass().getName(), e); Log.toLog(this.getClass().getName(), e);
@ -291,7 +291,7 @@ public class BungeeInformationManager extends InformationManager {
order.sort(new Comparator<String[]>() { order.sort(new Comparator<String[]>() {
@Override @Override
public int compare(String[] o1, String[] o2) { public int compare(String[] o1, String[] o2) {
return o1[0].compareTo(o2[1]); return o1[0].compareTo(o2[0]);
} }
}); });

View File

@ -7,8 +7,8 @@ package com.djrapitops.plan.systems.info;
import com.djrapitops.plan.api.exceptions.ParseException; import com.djrapitops.plan.api.exceptions.ParseException;
import com.djrapitops.plan.system.cache.DataCache; import com.djrapitops.plan.system.cache.DataCache;
import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.webserver.pagecache.PageId; import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.pagecache.ResponseCache; import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.command.ISender;
import java.io.IOException; import java.io.IOException;

View File

@ -6,9 +6,9 @@ package com.djrapitops.plan.utilities.file.export;
import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.webserver.pagecache.PageId;
import com.djrapitops.plan.system.webserver.pagecache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plugin.api.Check; import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.AbsRunnable; import com.djrapitops.plugin.task.AbsRunnable;

View File

@ -1,8 +1,8 @@
package com.djrapitops.plan.data.cache; package com.djrapitops.plan.data.cache;
import com.djrapitops.plan.system.webserver.pagecache.ResponseCache;
import com.djrapitops.plan.system.webserver.pagecache.PageLoader;
import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.cache.PageLoader;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import org.junit.Test; import org.junit.Test;
import test.utilities.RandomData; import test.utilities.RandomData;