mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-05 10:20:23 +01:00
[Debt] Delegated Exception logs to ResponseFactory
ErrorResponse caught an IOException for reading a file from the jar, but this error should be moved further up stream - thus catching it was delegated to ResponseFactory, where the error can be parsed into InternalErrorResponse and dealt with accordingly.
This commit is contained in:
parent
7f53fb4c80
commit
a48b660a05
@ -8,12 +8,11 @@ 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.system.database.databases.Database;
|
import com.djrapitops.plan.system.database.databases.Database;
|
||||||
import com.djrapitops.plan.system.info.request.InfoRequest;
|
import com.djrapitops.plan.system.info.request.InfoRequest;
|
||||||
import com.djrapitops.plan.system.locale.lang.ErrorPageLang;
|
|
||||||
import com.djrapitops.plan.system.webserver.Request;
|
import com.djrapitops.plan.system.webserver.Request;
|
||||||
import com.djrapitops.plan.system.webserver.pages.PageHandler;
|
import com.djrapitops.plan.system.webserver.pages.PageHandler;
|
||||||
import com.djrapitops.plan.system.webserver.response.Response;
|
import com.djrapitops.plan.system.webserver.response.Response;
|
||||||
|
import com.djrapitops.plan.system.webserver.response.ResponseFactory;
|
||||||
import com.djrapitops.plan.system.webserver.response.errors.BadRequestResponse;
|
import com.djrapitops.plan.system.webserver.response.errors.BadRequestResponse;
|
||||||
import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse;
|
|
||||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
@ -35,16 +34,18 @@ public class InfoRequestPageHandler implements PageHandler {
|
|||||||
|
|
||||||
private final Database database;
|
private final Database database;
|
||||||
private final ConnectionSystem connectionSystem;
|
private final ConnectionSystem connectionSystem;
|
||||||
|
private final ResponseFactory responseFactory;
|
||||||
private final PluginLogger logger;
|
private final PluginLogger logger;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public InfoRequestPageHandler(
|
public InfoRequestPageHandler(
|
||||||
Database database,
|
Database database,
|
||||||
ConnectionSystem connectionSystem,
|
ConnectionSystem connectionSystem,
|
||||||
PluginLogger logger
|
ResponseFactory responseFactory, PluginLogger logger
|
||||||
) {
|
) {
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.connectionSystem = connectionSystem;
|
this.connectionSystem = connectionSystem;
|
||||||
|
this.responseFactory = responseFactory;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ public class InfoRequestPageHandler implements PageHandler {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (target.isEmpty()) {
|
if (target.isEmpty()) {
|
||||||
return new NotFoundResponse(request.getLocale().getString(ErrorPageLang.UNKNOWN_PAGE_404));
|
return responseFactory.pageNotFound404();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!request.getRequestMethod().equals("POST")) {
|
if (!request.getRequestMethod().equals("POST")) {
|
||||||
|
@ -10,7 +10,7 @@ import com.djrapitops.plan.api.exceptions.database.DBException;
|
|||||||
import com.djrapitops.plan.system.info.InfoSystem;
|
import com.djrapitops.plan.system.info.InfoSystem;
|
||||||
import com.djrapitops.plan.system.webserver.response.DefaultResponses;
|
import com.djrapitops.plan.system.webserver.response.DefaultResponses;
|
||||||
import com.djrapitops.plan.system.webserver.response.Response;
|
import com.djrapitops.plan.system.webserver.response.Response;
|
||||||
import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse;
|
import com.djrapitops.plan.system.webserver.response.ResponseFactory;
|
||||||
import com.djrapitops.plan.utilities.html.pages.PageFactory;
|
import com.djrapitops.plan.utilities.html.pages.PageFactory;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
@ -25,6 +25,7 @@ import java.util.UUID;
|
|||||||
public class GenerateInspectPageRequest extends InfoRequestWithVariables implements GenerateRequest {
|
public class GenerateInspectPageRequest extends InfoRequestWithVariables implements GenerateRequest {
|
||||||
|
|
||||||
private final InfoRequestFactory infoRequestFactory;
|
private final InfoRequestFactory infoRequestFactory;
|
||||||
|
private final ResponseFactory responseFactory;
|
||||||
private final PageFactory pageFactory;
|
private final PageFactory pageFactory;
|
||||||
private final InfoSystem infoSystem;
|
private final InfoSystem infoSystem;
|
||||||
|
|
||||||
@ -32,21 +33,23 @@ public class GenerateInspectPageRequest extends InfoRequestWithVariables impleme
|
|||||||
|
|
||||||
GenerateInspectPageRequest(
|
GenerateInspectPageRequest(
|
||||||
InfoRequestFactory infoRequestFactory,
|
InfoRequestFactory infoRequestFactory,
|
||||||
PageFactory pageFactory,
|
ResponseFactory responseFactory, PageFactory pageFactory,
|
||||||
InfoSystem infoSystem
|
InfoSystem infoSystem
|
||||||
) {
|
) {
|
||||||
this.infoRequestFactory = infoRequestFactory;
|
this.infoRequestFactory = infoRequestFactory;
|
||||||
|
this.responseFactory = responseFactory;
|
||||||
this.pageFactory = pageFactory;
|
this.pageFactory = pageFactory;
|
||||||
this.infoSystem = infoSystem;
|
this.infoSystem = infoSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenerateInspectPageRequest(
|
GenerateInspectPageRequest(
|
||||||
UUID uuid,
|
UUID uuid,
|
||||||
InfoRequestFactory infoRequestFactory,
|
InfoRequestFactory infoRequestFactory,
|
||||||
PageFactory pageFactory,
|
ResponseFactory responseFactory, PageFactory pageFactory,
|
||||||
InfoSystem infoSystem
|
InfoSystem infoSystem
|
||||||
) {
|
) {
|
||||||
this.infoRequestFactory = infoRequestFactory;
|
this.infoRequestFactory = infoRequestFactory;
|
||||||
|
this.responseFactory = responseFactory;
|
||||||
this.pageFactory = pageFactory;
|
this.pageFactory = pageFactory;
|
||||||
this.infoSystem = infoSystem;
|
this.infoSystem = infoSystem;
|
||||||
|
|
||||||
@ -75,7 +78,7 @@ public class GenerateInspectPageRequest extends InfoRequestWithVariables impleme
|
|||||||
html = getHtml(uuid);
|
html = getHtml(uuid);
|
||||||
infoSystem.getConnectionSystem().sendWideInfoRequest(infoRequestFactory.generateInspectPluginsTabRequest(uuid));
|
infoSystem.getConnectionSystem().sendWideInfoRequest(infoRequestFactory.generateInspectPluginsTabRequest(uuid));
|
||||||
} catch (NotFoundException e) {
|
} catch (NotFoundException e) {
|
||||||
html = new NotFoundResponse(e.getMessage()).getContent();
|
html = responseFactory.notFound404(e.getMessage()).getContent();
|
||||||
}
|
}
|
||||||
infoSystem.sendRequest(infoRequestFactory.cacheInspectPageRequest(uuid, html));
|
infoSystem.sendRequest(infoRequestFactory.cacheInspectPageRequest(uuid, html));
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
|||||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||||
import com.djrapitops.plan.system.processing.Processing;
|
import com.djrapitops.plan.system.processing.Processing;
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
|
import com.djrapitops.plan.system.webserver.response.ResponseFactory;
|
||||||
import com.djrapitops.plan.utilities.file.export.HtmlExport;
|
import com.djrapitops.plan.utilities.file.export.HtmlExport;
|
||||||
import com.djrapitops.plan.utilities.html.pages.PageFactory;
|
import com.djrapitops.plan.utilities.html.pages.PageFactory;
|
||||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
@ -31,6 +32,7 @@ public class InfoRequestFactory {
|
|||||||
private final Lazy<ConnectionSystem> connectionSystem;
|
private final Lazy<ConnectionSystem> connectionSystem;
|
||||||
private final Lazy<ServerInfo> serverInfo;
|
private final Lazy<ServerInfo> serverInfo;
|
||||||
private final Lazy<InfoRequestFactory> infoRequestFactory;
|
private final Lazy<InfoRequestFactory> infoRequestFactory;
|
||||||
|
private final Lazy<ResponseFactory> responseFactory;
|
||||||
private final Lazy<PageFactory> pageFactory;
|
private final Lazy<PageFactory> pageFactory;
|
||||||
private final Lazy<HtmlExport> htmlExport;
|
private final Lazy<HtmlExport> htmlExport;
|
||||||
private final Lazy<PluginLogger> logger;
|
private final Lazy<PluginLogger> logger;
|
||||||
@ -45,6 +47,7 @@ public class InfoRequestFactory {
|
|||||||
Lazy<ConnectionSystem> connectionSystem,
|
Lazy<ConnectionSystem> connectionSystem,
|
||||||
Lazy<ServerInfo> serverInfo,
|
Lazy<ServerInfo> serverInfo,
|
||||||
Lazy<InfoRequestFactory> infoRequestFactory,
|
Lazy<InfoRequestFactory> infoRequestFactory,
|
||||||
|
Lazy<ResponseFactory> responseFactory,
|
||||||
Lazy<PageFactory> pageFactory,
|
Lazy<PageFactory> pageFactory,
|
||||||
Lazy<HtmlExport> htmlExport,
|
Lazy<HtmlExport> htmlExport,
|
||||||
Lazy<PluginLogger> logger,
|
Lazy<PluginLogger> logger,
|
||||||
@ -57,6 +60,7 @@ public class InfoRequestFactory {
|
|||||||
this.connectionSystem = connectionSystem;
|
this.connectionSystem = connectionSystem;
|
||||||
this.serverInfo = serverInfo;
|
this.serverInfo = serverInfo;
|
||||||
this.infoRequestFactory = infoRequestFactory;
|
this.infoRequestFactory = infoRequestFactory;
|
||||||
|
this.responseFactory = responseFactory;
|
||||||
this.pageFactory = pageFactory;
|
this.pageFactory = pageFactory;
|
||||||
this.htmlExport = htmlExport;
|
this.htmlExport = htmlExport;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
@ -84,7 +88,7 @@ public class InfoRequestFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GenerateRequest generateInspectPageRequest(UUID uuid) {
|
public GenerateRequest generateInspectPageRequest(UUID uuid) {
|
||||||
return new GenerateInspectPageRequest(uuid, this, pageFactory.get(), infoSystem.get());
|
return new GenerateInspectPageRequest(uuid, this, responseFactory.get(), pageFactory.get(), infoSystem.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenerateInspectPluginsTabRequest generateInspectPluginsTabRequest(UUID uuid) {
|
public GenerateInspectPluginsTabRequest generateInspectPluginsTabRequest(UUID uuid) {
|
||||||
|
@ -6,6 +6,7 @@ import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
|||||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||||
import com.djrapitops.plan.system.processing.Processing;
|
import com.djrapitops.plan.system.processing.Processing;
|
||||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||||
|
import com.djrapitops.plan.system.webserver.response.ResponseFactory;
|
||||||
import com.djrapitops.plan.utilities.file.export.HtmlExport;
|
import com.djrapitops.plan.utilities.file.export.HtmlExport;
|
||||||
import com.djrapitops.plan.utilities.html.pages.PageFactory;
|
import com.djrapitops.plan.utilities.html.pages.PageFactory;
|
||||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
@ -30,6 +31,7 @@ public class InfoRequestHandlerFactory {
|
|||||||
private final Lazy<ConnectionSystem> connectionSystem;
|
private final Lazy<ConnectionSystem> connectionSystem;
|
||||||
private final Lazy<ServerInfo> serverInfo;
|
private final Lazy<ServerInfo> serverInfo;
|
||||||
private final Lazy<InfoRequestFactory> infoRequestFactory;
|
private final Lazy<InfoRequestFactory> infoRequestFactory;
|
||||||
|
private final Lazy<ResponseFactory> responseFactory;
|
||||||
private final Lazy<PageFactory> pageFactory;
|
private final Lazy<PageFactory> pageFactory;
|
||||||
private final Lazy<HtmlExport> htmlExport;
|
private final Lazy<HtmlExport> htmlExport;
|
||||||
private final Lazy<PluginLogger> logger;
|
private final Lazy<PluginLogger> logger;
|
||||||
@ -44,6 +46,7 @@ public class InfoRequestHandlerFactory {
|
|||||||
Lazy<ConnectionSystem> connectionSystem,
|
Lazy<ConnectionSystem> connectionSystem,
|
||||||
Lazy<ServerInfo> serverInfo,
|
Lazy<ServerInfo> serverInfo,
|
||||||
Lazy<InfoRequestFactory> infoRequestFactory,
|
Lazy<InfoRequestFactory> infoRequestFactory,
|
||||||
|
Lazy<ResponseFactory> responseFactory,
|
||||||
Lazy<PageFactory> pageFactory,
|
Lazy<PageFactory> pageFactory,
|
||||||
Lazy<HtmlExport> htmlExport,
|
Lazy<HtmlExport> htmlExport,
|
||||||
Lazy<PluginLogger> logger,
|
Lazy<PluginLogger> logger,
|
||||||
@ -56,6 +59,7 @@ public class InfoRequestHandlerFactory {
|
|||||||
this.connectionSystem = connectionSystem;
|
this.connectionSystem = connectionSystem;
|
||||||
this.serverInfo = serverInfo;
|
this.serverInfo = serverInfo;
|
||||||
this.infoRequestFactory = infoRequestFactory;
|
this.infoRequestFactory = infoRequestFactory;
|
||||||
|
this.responseFactory = responseFactory;
|
||||||
this.pageFactory = pageFactory;
|
this.pageFactory = pageFactory;
|
||||||
this.htmlExport = htmlExport;
|
this.htmlExport = htmlExport;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
@ -87,7 +91,7 @@ public class InfoRequestHandlerFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GenerateRequest generateInspectPageRequest() {
|
GenerateRequest generateInspectPageRequest() {
|
||||||
return new GenerateInspectPageRequest(infoRequestFactory.get(), pageFactory.get(), infoSystem.get());
|
return new GenerateInspectPageRequest(infoRequestFactory.get(), responseFactory.get(), pageFactory.get(), infoSystem.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
GenerateRequest generateInspectPluginsTabRequest() {
|
GenerateRequest generateInspectPluginsTabRequest() {
|
||||||
|
@ -11,11 +11,9 @@ import com.djrapitops.plan.system.webserver.auth.Authentication;
|
|||||||
import com.djrapitops.plan.system.webserver.cache.PageId;
|
import com.djrapitops.plan.system.webserver.cache.PageId;
|
||||||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||||
import com.djrapitops.plan.system.webserver.pages.*;
|
import com.djrapitops.plan.system.webserver.pages.*;
|
||||||
import com.djrapitops.plan.system.webserver.response.DefaultResponses;
|
|
||||||
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.ResponseFactory;
|
import com.djrapitops.plan.system.webserver.response.ResponseFactory;
|
||||||
import com.djrapitops.plan.system.webserver.response.errors.*;
|
import com.djrapitops.plan.system.webserver.response.errors.BadRequestResponse;
|
||||||
import com.djrapitops.plugin.logging.L;
|
import com.djrapitops.plugin.logging.L;
|
||||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import dagger.Lazy;
|
import dagger.Lazy;
|
||||||
@ -35,8 +33,6 @@ import java.util.Optional;
|
|||||||
@Singleton
|
@Singleton
|
||||||
public class ResponseHandler extends TreePageHandler {
|
public class ResponseHandler extends TreePageHandler {
|
||||||
|
|
||||||
private final ResponseFactory responseFactory;
|
|
||||||
|
|
||||||
private final DebugPageHandler debugPageHandler;
|
private final DebugPageHandler debugPageHandler;
|
||||||
private final PlayersPageHandler playersPageHandler;
|
private final PlayersPageHandler playersPageHandler;
|
||||||
private final PlayerPageHandler playerPageHandler;
|
private final PlayerPageHandler playerPageHandler;
|
||||||
@ -59,8 +55,8 @@ public class ResponseHandler extends TreePageHandler {
|
|||||||
|
|
||||||
ErrorHandler errorHandler
|
ErrorHandler errorHandler
|
||||||
) {
|
) {
|
||||||
|
super(responseFactory);
|
||||||
this.webServer = webServer;
|
this.webServer = webServer;
|
||||||
this.responseFactory = responseFactory;
|
|
||||||
this.debugPageHandler = debugPageHandler;
|
this.debugPageHandler = debugPageHandler;
|
||||||
this.playersPageHandler = playersPageHandler;
|
this.playersPageHandler = playersPageHandler;
|
||||||
this.playerPageHandler = playerPageHandler;
|
this.playerPageHandler = playerPageHandler;
|
||||||
@ -79,7 +75,7 @@ public class ResponseHandler extends TreePageHandler {
|
|||||||
registerPage("server", serverPageHandler);
|
registerPage("server", serverPageHandler);
|
||||||
|
|
||||||
if (webServer.get().isAuthRequired()) {
|
if (webServer.get().isAuthRequired()) {
|
||||||
registerPage("", new RootPageHandler());
|
registerPage("", new RootPageHandler(responseFactory));
|
||||||
} else {
|
} else {
|
||||||
registerPage("", responseFactory.redirectResponse("/server"), 5);
|
registerPage("", responseFactory.redirectResponse("/server"), 5);
|
||||||
}
|
}
|
||||||
@ -96,26 +92,26 @@ public class ResponseHandler extends TreePageHandler {
|
|||||||
try {
|
try {
|
||||||
return getResponse(request, targetString, target);
|
return getResponse(request, targetString, target);
|
||||||
} catch (NoServersException | NotFoundException e) {
|
} catch (NoServersException | NotFoundException e) {
|
||||||
return new NotFoundResponse(e.getMessage());
|
return responseFactory.notFound404(e.getMessage());
|
||||||
} catch (WebUserAuthException e) {
|
} catch (WebUserAuthException e) {
|
||||||
return PromptAuthorizationResponse.getBasicAuthResponse(e);
|
return responseFactory.basicAuthFail(e);
|
||||||
} catch (ForbiddenException e) {
|
} catch (ForbiddenException e) {
|
||||||
return new ForbiddenResponse(e.getMessage());
|
return responseFactory.forbidden403(e.getMessage());
|
||||||
} catch (BadRequestException e) {
|
} catch (BadRequestException e) {
|
||||||
return new BadRequestResponse(e.getMessage());
|
return new BadRequestResponse(e.getMessage());
|
||||||
} catch (UnauthorizedServerException e) {
|
} catch (UnauthorizedServerException e) {
|
||||||
return new UnauthorizedServerResponse(e.getMessage());
|
return responseFactory.unauthorizedServer(e.getMessage());
|
||||||
} catch (GatewayException e) {
|
} catch (GatewayException e) {
|
||||||
return new GatewayErrorResponse(e.getMessage());
|
return responseFactory.gatewayError504(e.getMessage());
|
||||||
} catch (InternalErrorException e) {
|
} catch (InternalErrorException e) {
|
||||||
if (e.getCause() != null) {
|
if (e.getCause() != null) {
|
||||||
return new InternalErrorResponse(request.getTarget(), e.getCause());
|
return responseFactory.internalErrorResponse(e.getCause(), request.getTarget());
|
||||||
} else {
|
} else {
|
||||||
return new InternalErrorResponse(request.getTarget(), e);
|
return responseFactory.internalErrorResponse(e, request.getTarget());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||||
return new InternalErrorResponse(request.getTarget(), e);
|
return responseFactory.internalErrorResponse(e, request.getTarget());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,9 +130,9 @@ public class ResponseHandler extends TreePageHandler {
|
|||||||
authentication = request.getAuth();
|
authentication = request.getAuth();
|
||||||
if (!authentication.isPresent()) {
|
if (!authentication.isPresent()) {
|
||||||
if (webServer.get().isUsingHTTPS()) {
|
if (webServer.get().isUsingHTTPS()) {
|
||||||
return DefaultResponses.BASIC_AUTH.get();
|
return responseFactory.basicAuth();
|
||||||
} else {
|
} else {
|
||||||
return DefaultResponses.FORBIDDEN.get();
|
return responseFactory.forbidden403();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,7 +144,7 @@ public class ResponseHandler extends TreePageHandler {
|
|||||||
if (!isAuthRequired || isAuthorized) {
|
if (!isAuthRequired || isAuthorized) {
|
||||||
return pageHandler.getResponse(request, target);
|
return pageHandler.getResponse(request, target);
|
||||||
}
|
}
|
||||||
return DefaultResponses.FORBIDDEN.get();
|
return responseFactory.forbidden403();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ import com.djrapitops.plan.system.webserver.cache.PageId;
|
|||||||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||||
import com.djrapitops.plan.system.webserver.response.Response;
|
import com.djrapitops.plan.system.webserver.response.Response;
|
||||||
import com.djrapitops.plan.system.webserver.response.ResponseFactory;
|
import com.djrapitops.plan.system.webserver.response.ResponseFactory;
|
||||||
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;
|
||||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||||
|
|
||||||
@ -76,9 +75,9 @@ public class PlayerPageHandler implements PageHandler {
|
|||||||
return responseFactory.playerNotFound404();
|
return responseFactory.playerNotFound404();
|
||||||
}
|
}
|
||||||
} catch (NoServersException e) {
|
} catch (NoServersException e) {
|
||||||
ResponseCache.loadResponse(PageId.PLAYER.of(uuid), () -> new NotFoundResponse(e.getMessage()));
|
ResponseCache.loadResponse(PageId.PLAYER.of(uuid), () -> responseFactory.notFound404(e.getMessage()));
|
||||||
}
|
}
|
||||||
return InspectPageResponse.getRefreshing();
|
return responseFactory.serverNotFound404();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response playerResponseOrNotFound(UUID uuid) throws WebException {
|
private Response playerResponseOrNotFound(UUID uuid) throws WebException {
|
||||||
|
@ -8,9 +8,9 @@ import com.djrapitops.plan.api.exceptions.connection.WebException;
|
|||||||
import com.djrapitops.plan.data.WebUser;
|
import com.djrapitops.plan.data.WebUser;
|
||||||
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.response.DefaultResponses;
|
|
||||||
import com.djrapitops.plan.system.webserver.response.RedirectResponse;
|
import com.djrapitops.plan.system.webserver.response.RedirectResponse;
|
||||||
import com.djrapitops.plan.system.webserver.response.Response;
|
import com.djrapitops.plan.system.webserver.response.Response;
|
||||||
|
import com.djrapitops.plan.system.webserver.response.ResponseFactory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -24,11 +24,17 @@ import java.util.Optional;
|
|||||||
*/
|
*/
|
||||||
public class RootPageHandler implements PageHandler {
|
public class RootPageHandler implements PageHandler {
|
||||||
|
|
||||||
|
private final ResponseFactory responseFactory;
|
||||||
|
|
||||||
|
public RootPageHandler(ResponseFactory responseFactory) {
|
||||||
|
this.responseFactory = responseFactory;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response getResponse(Request request, List<String> target) throws WebException {
|
public Response getResponse(Request request, List<String> target) throws WebException {
|
||||||
Optional<Authentication> auth = request.getAuth();
|
Optional<Authentication> auth = request.getAuth();
|
||||||
if (!auth.isPresent()) {
|
if (!auth.isPresent()) {
|
||||||
return DefaultResponses.BASIC_AUTH.get();
|
return responseFactory.basicAuth();
|
||||||
}
|
}
|
||||||
|
|
||||||
WebUser webUser = auth.get().getWebUser();
|
WebUser webUser = auth.get().getWebUser();
|
||||||
@ -42,7 +48,7 @@ public class RootPageHandler implements PageHandler {
|
|||||||
case 2:
|
case 2:
|
||||||
return new RedirectResponse("/player/" + webUser.getName());
|
return new RedirectResponse("/player/" + webUser.getName());
|
||||||
default:
|
default:
|
||||||
return DefaultResponses.FORBIDDEN.get();
|
return responseFactory.forbidden403();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,11 +6,10 @@ 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.api.exceptions.connection.WebException;
|
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||||
import com.djrapitops.plan.system.locale.lang.ErrorPageLang;
|
|
||||||
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.response.Response;
|
import com.djrapitops.plan.system.webserver.response.Response;
|
||||||
import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse;
|
import com.djrapitops.plan.system.webserver.response.ResponseFactory;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -23,9 +22,12 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public abstract class TreePageHandler implements PageHandler {
|
public abstract class TreePageHandler implements PageHandler {
|
||||||
|
|
||||||
|
protected final ResponseFactory responseFactory;
|
||||||
|
|
||||||
private Map<String, PageHandler> pages;
|
private Map<String, PageHandler> pages;
|
||||||
|
|
||||||
public TreePageHandler() {
|
public TreePageHandler(ResponseFactory responseFactory) {
|
||||||
|
this.responseFactory = responseFactory;
|
||||||
pages = new HashMap<>();
|
pages = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +54,7 @@ public abstract class TreePageHandler implements PageHandler {
|
|||||||
PageHandler pageHandler = getPageHandler(target);
|
PageHandler pageHandler = getPageHandler(target);
|
||||||
return pageHandler != null
|
return pageHandler != null
|
||||||
? pageHandler.getResponse(request, target)
|
? pageHandler.getResponse(request, target)
|
||||||
: new NotFoundResponse(request.getLocale().getString(ErrorPageLang.UNKNOWN_PAGE_404));
|
: responseFactory.pageNotFound404();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PageHandler getPageHandler(List<String> target) {
|
public PageHandler getPageHandler(List<String> target) {
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package com.djrapitops.plan.system.webserver.response;
|
package com.djrapitops.plan.system.webserver.response;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
*/
|
*/
|
||||||
public class CSSResponse extends FileResponse {
|
public class CSSResponse extends FileResponse {
|
||||||
|
|
||||||
public CSSResponse(String fileName) {
|
public CSSResponse(String fileName) throws IOException {
|
||||||
super(format(fileName));
|
super(format(fileName));
|
||||||
super.setType(ResponseType.CSS);
|
super.setType(ResponseType.CSS);
|
||||||
setContent(getContent());
|
setContent(getContent());
|
||||||
|
@ -4,18 +4,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.system.webserver.response;
|
package com.djrapitops.plan.system.webserver.response;
|
||||||
|
|
||||||
import com.djrapitops.plan.system.webserver.response.errors.ForbiddenResponse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum containing default responses that don't need to be cached because they're always the same.
|
* Enum containing default responses that don't need to be cached because they're always the same.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public enum DefaultResponses {
|
public enum DefaultResponses {
|
||||||
BASIC_AUTH(PromptAuthorizationResponse.getBasicAuthResponse()),
|
SUCCESS(new TextResponse("Success"));
|
||||||
SUCCESS(new TextResponse("Success")),
|
|
||||||
FORBIDDEN(new ForbiddenResponse("Your user is not authorized to view this page.<br>"
|
|
||||||
+ "If you believe this is an error contact staff to change your access level."));
|
|
||||||
|
|
||||||
private final Response response;
|
private final Response response;
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package com.djrapitops.plan.system.webserver.response;
|
package com.djrapitops.plan.system.webserver.response;
|
||||||
|
|
||||||
import com.djrapitops.plan.system.file.PlanFiles;
|
import com.djrapitops.plan.system.file.PlanFiles;
|
||||||
import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse;
|
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -23,13 +22,9 @@ public class FileResponse extends Response {
|
|||||||
// TODO
|
// TODO
|
||||||
private PlanFiles planFiles;
|
private PlanFiles planFiles;
|
||||||
|
|
||||||
public FileResponse(String fileName) {
|
public FileResponse(String fileName) throws IOException {
|
||||||
super.setHeader("HTTP/1.1 200 OK");
|
super.setHeader("HTTP/1.1 200 OK");
|
||||||
try {
|
|
||||||
super.setContent(planFiles.readCustomizableResourceFlat(fileName));
|
super.setContent(planFiles.readCustomizableResourceFlat(fileName));
|
||||||
} catch (IOException e) {
|
|
||||||
super.setContent(new NotFoundResponse(fileName + " was not found inside the .jar or /plugins/Plan/ folder").getContent());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String format(String fileName) {
|
public static String format(String fileName) {
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package com.djrapitops.plan.system.webserver.response;
|
package com.djrapitops.plan.system.webserver.response;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 3.5.2
|
* @since 3.5.2
|
||||||
*/
|
*/
|
||||||
public class JavaScriptResponse extends FileResponse {
|
public class JavaScriptResponse extends FileResponse {
|
||||||
|
|
||||||
JavaScriptResponse(String fileName) {
|
JavaScriptResponse(String fileName) throws IOException {
|
||||||
super(format(fileName));
|
super(format(fileName));
|
||||||
super.setType(ResponseType.JAVASCRIPT);
|
super.setType(ResponseType.JAVASCRIPT);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package com.djrapitops.plan.system.webserver.response;
|
package com.djrapitops.plan.system.webserver.response;
|
||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.WebUserAuthException;
|
import com.djrapitops.plan.api.exceptions.WebUserAuthException;
|
||||||
|
import com.djrapitops.plan.system.file.PlanFiles;
|
||||||
import com.djrapitops.plan.system.webserver.auth.FailReason;
|
import com.djrapitops.plan.system.webserver.auth.FailReason;
|
||||||
import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse;
|
import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse;
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -19,12 +21,13 @@ public class PromptAuthorizationResponse extends ErrorResponse {
|
|||||||
+ "- Username and password are case-sensitive<br>"
|
+ "- Username and password are case-sensitive<br>"
|
||||||
+ "<br>If you have forgotten your password, ask a staff member to delete your old user and re-register.";
|
+ "<br>If you have forgotten your password, ask a staff member to delete your old user and re-register.";
|
||||||
|
|
||||||
private PromptAuthorizationResponse() {
|
private PromptAuthorizationResponse(String version, PlanFiles files) throws IOException {
|
||||||
|
super(version, files);
|
||||||
super.setTitle(Icon.called("lock").build() + " 401 Unauthorized");
|
super.setTitle(Icon.called("lock").build() + " 401 Unauthorized");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PromptAuthorizationResponse getBasicAuthResponse() {
|
public static PromptAuthorizationResponse getBasicAuthResponse(String version, PlanFiles files) throws IOException {
|
||||||
PromptAuthorizationResponse response = new PromptAuthorizationResponse();
|
PromptAuthorizationResponse response = new PromptAuthorizationResponse(version, files);
|
||||||
response.setHeader("HTTP/1.1 401 Access Denied\r\n"
|
response.setHeader("HTTP/1.1 401 Access Denied\r\n"
|
||||||
+ "WWW-Authenticate: Basic realm=\"/\";");
|
+ "WWW-Authenticate: Basic realm=\"/\";");
|
||||||
|
|
||||||
@ -33,8 +36,8 @@ public class PromptAuthorizationResponse extends ErrorResponse {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PromptAuthorizationResponse getBasicAuthResponse(WebUserAuthException e) {
|
public static PromptAuthorizationResponse getBasicAuthResponse(WebUserAuthException e, String version, PlanFiles files) throws IOException {
|
||||||
PromptAuthorizationResponse response = new PromptAuthorizationResponse();
|
PromptAuthorizationResponse response = new PromptAuthorizationResponse(version, files);
|
||||||
response.setHeader("HTTP/1.1 401 Access Denied\r\n"
|
response.setHeader("HTTP/1.1 401 Access Denied\r\n"
|
||||||
+ "WWW-Authenticate: Basic realm=\"/\";");
|
+ "WWW-Authenticate: Basic realm=\"/\";");
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@ public abstract class Response {
|
|||||||
exchange.sendResponseHeaders(getCode(), 0);
|
exchange.sendResponseHeaders(getCode(), 0);
|
||||||
|
|
||||||
String sentContent = getContent();
|
String sentContent = getContent();
|
||||||
|
// TODO Smell
|
||||||
if (!(this instanceof JavaScriptResponse)) {
|
if (!(this instanceof JavaScriptResponse)) {
|
||||||
sentContent = locale.replaceMatchingLanguage(sentContent);
|
sentContent = locale.replaceMatchingLanguage(sentContent);
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,21 @@
|
|||||||
package com.djrapitops.plan.system.webserver.response;
|
package com.djrapitops.plan.system.webserver.response;
|
||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.ParseException;
|
import com.djrapitops.plan.api.exceptions.ParseException;
|
||||||
|
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.file.PlanFiles;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.ErrorPageLang;
|
import com.djrapitops.plan.system.locale.lang.ErrorPageLang;
|
||||||
import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse;
|
import com.djrapitops.plan.system.webserver.response.errors.*;
|
||||||
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.pages.*;
|
import com.djrapitops.plan.system.webserver.response.pages.*;
|
||||||
import com.djrapitops.plan.utilities.html.pages.PageFactory;
|
import com.djrapitops.plan.utilities.html.pages.PageFactory;
|
||||||
|
import com.djrapitops.plugin.logging.L;
|
||||||
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,30 +26,56 @@ import java.util.UUID;
|
|||||||
@Singleton
|
@Singleton
|
||||||
public class ResponseFactory {
|
public class ResponseFactory {
|
||||||
|
|
||||||
|
private final String version;
|
||||||
|
private final PlanFiles files;
|
||||||
private final PageFactory pageFactory;
|
private final PageFactory pageFactory;
|
||||||
private final Locale locale;
|
private final Locale locale;
|
||||||
private final Database database;
|
private final Database database;
|
||||||
|
private final ErrorHandler errorHandler;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ResponseFactory(
|
public ResponseFactory(
|
||||||
|
@Named("currentVersion") String version,
|
||||||
|
PlanFiles files,
|
||||||
PageFactory pageFactory,
|
PageFactory pageFactory,
|
||||||
Locale locale,
|
Locale locale,
|
||||||
Database database
|
Database database,
|
||||||
|
ErrorHandler errorHandler
|
||||||
) {
|
) {
|
||||||
|
this.version = version;
|
||||||
|
this.files = files;
|
||||||
this.pageFactory = pageFactory;
|
this.pageFactory = pageFactory;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
|
this.errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response debugPageResponse() {
|
public Response debugPageResponse() {
|
||||||
return new DebugPageResponse(pageFactory.debugPage());
|
try {
|
||||||
|
return new DebugPageResponse(pageFactory.debugPage(), version, files);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return internalErrorResponse(e, "Failed to parse debug page");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response playersPageResponse() {
|
public Response playersPageResponse() {
|
||||||
try {
|
try {
|
||||||
return new PlayersPageResponse(pageFactory.playersPage());
|
return new PlayersPageResponse(pageFactory.playersPage());
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
return new InternalErrorResponse("Failed to parse players page", e);
|
return internalErrorResponse(e, "Failed to parse players page");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponse internalErrorResponse(Throwable e, String s) {
|
||||||
|
try {
|
||||||
|
errorHandler.log(L.WARN, this.getClass(), e);
|
||||||
|
return new InternalErrorResponse(s, e, version, files);
|
||||||
|
} catch (IOException improperRestartException) {
|
||||||
|
return new ErrorResponse(
|
||||||
|
"Error occurred: " + e.toString() +
|
||||||
|
", additional error occurred when attempting to send error page to user: " +
|
||||||
|
improperRestartException.toString()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +83,7 @@ public class ResponseFactory {
|
|||||||
try {
|
try {
|
||||||
return new NetworkPageResponse(pageFactory.networkPage());
|
return new NetworkPageResponse(pageFactory.networkPage());
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
return new InternalErrorResponse("Failed to parse network page", e);
|
return internalErrorResponse(e, "Failed to parse network page");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,11 +96,19 @@ public class ResponseFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Response javaScriptResponse(String fileName) {
|
public Response javaScriptResponse(String fileName) {
|
||||||
|
try {
|
||||||
return new JavaScriptResponse(fileName);
|
return new JavaScriptResponse(fileName);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return notFound404("JS File not found from jar: " + fileName + ", " + e.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response cssResponse(String fileName) {
|
public Response cssResponse(String fileName) {
|
||||||
|
try {
|
||||||
return new CSSResponse(fileName);
|
return new CSSResponse(fileName);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return notFound404("CSS File not found from jar: " + fileName + ", " + e.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response redirectResponse(String location) {
|
public Response redirectResponse(String location) {
|
||||||
@ -78,18 +116,71 @@ public class ResponseFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ErrorResponse pageNotFound404() {
|
public ErrorResponse pageNotFound404() {
|
||||||
return new NotFoundResponse(locale.getString(ErrorPageLang.UNKNOWN_PAGE_404));
|
return notFound404(locale.getString(ErrorPageLang.UNKNOWN_PAGE_404));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErrorResponse uuidNotFound404() {
|
public ErrorResponse uuidNotFound404() {
|
||||||
return new NotFoundResponse(locale.getString(ErrorPageLang.UUID_404));
|
return notFound404(locale.getString(ErrorPageLang.UUID_404));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErrorResponse playerNotFound404() {
|
public ErrorResponse playerNotFound404() {
|
||||||
return new NotFoundResponse(locale.getString(ErrorPageLang.NOT_PLAYED_404));
|
return notFound404(locale.getString(ErrorPageLang.NOT_PLAYED_404));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErrorResponse serverNotFound404() {
|
public ErrorResponse serverNotFound404() {
|
||||||
return new NotFoundResponse(locale.getString(ErrorPageLang.NO_SERVERS_404));
|
return notFound404(locale.getString(ErrorPageLang.NO_SERVERS_404));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponse notFound404(String message) {
|
||||||
|
try {
|
||||||
|
return new NotFoundResponse(message, version, files);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return internalErrorResponse(e, "Failed to parse 404 page");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponse basicAuthFail(WebUserAuthException e) {
|
||||||
|
try {
|
||||||
|
return PromptAuthorizationResponse.getBasicAuthResponse(e, version, files);
|
||||||
|
} catch (IOException e1) {
|
||||||
|
return internalErrorResponse(e, "Failed to parse PromptAuthorizationResponse");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponse forbidden403() {
|
||||||
|
return forbidden403("Your user is not authorized to view this page.<br>"
|
||||||
|
+ "If you believe this is an error contact staff to change your access level.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponse forbidden403(String message) {
|
||||||
|
try {
|
||||||
|
return new ForbiddenResponse(message, version, files);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return internalErrorResponse(e, "Failed to parse ForbiddenResponse");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponse unauthorizedServer(String message) {
|
||||||
|
try {
|
||||||
|
return new UnauthorizedServerResponse(message, version, files);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return internalErrorResponse(e, "Failed to parse UnauthorizedServerResponse");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponse gatewayError504(String message) {
|
||||||
|
try {
|
||||||
|
return new GatewayErrorResponse(message, version, files);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return internalErrorResponse(e, "Failed to parse GatewayErrorResponse");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponse basicAuth() {
|
||||||
|
try {
|
||||||
|
return PromptAuthorizationResponse.getBasicAuthResponse(version, files);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return internalErrorResponse(e, "Failed to parse PromptAuthorizationResponse");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,8 +6,6 @@ package com.djrapitops.plan.system.webserver.response.errors;
|
|||||||
|
|
||||||
import com.djrapitops.plan.system.file.PlanFiles;
|
import com.djrapitops.plan.system.file.PlanFiles;
|
||||||
import com.djrapitops.plan.system.webserver.response.Response;
|
import com.djrapitops.plan.system.webserver.response.Response;
|
||||||
import com.djrapitops.plugin.logging.L;
|
|
||||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
|
||||||
import org.apache.commons.text.StringSubstitutor;
|
import org.apache.commons.text.StringSubstitutor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -24,17 +22,15 @@ public class ErrorResponse extends Response {
|
|||||||
private String title;
|
private String title;
|
||||||
private String paragraph;
|
private String paragraph;
|
||||||
|
|
||||||
// TODO
|
|
||||||
private String version;
|
private String version;
|
||||||
private PlanFiles planFiles;
|
|
||||||
private ErrorHandler errorHandler;
|
|
||||||
|
|
||||||
public ErrorResponse() {
|
public ErrorResponse(String version, PlanFiles planFiles) throws IOException {
|
||||||
try {
|
this.version = version;
|
||||||
setContent(planFiles.readCustomizableResourceFlat("web/error.html"));
|
setContent(planFiles.readCustomizableResourceFlat("web/error.html"));
|
||||||
} catch (IOException e) {
|
|
||||||
errorHandler.log(L.WARN, this.getClass(), e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ErrorResponse(String message) {
|
||||||
|
setContent(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replacePlaceholders() {
|
public void replacePlaceholders() {
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
package com.djrapitops.plan.system.webserver.response.errors;
|
package com.djrapitops.plan.system.webserver.response.errors;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.file.PlanFiles;
|
||||||
import com.djrapitops.plan.utilities.html.icon.Family;
|
import com.djrapitops.plan.utilities.html.icon.Family;
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 3.5.2
|
* @since 3.5.2
|
||||||
*/
|
*/
|
||||||
public class ForbiddenResponse extends ErrorResponse {
|
public class ForbiddenResponse extends ErrorResponse {
|
||||||
|
public ForbiddenResponse(String msg, String version, PlanFiles files) throws IOException {
|
||||||
public ForbiddenResponse(String msg) {
|
super(version, files);
|
||||||
super.setHeader("HTTP/1.1 403 Forbidden");
|
super.setHeader("HTTP/1.1 403 Forbidden");
|
||||||
super.setTitle(Icon.called("hand-paper").of(Family.REGULAR) + " 403 Forbidden - Access Denied");
|
super.setTitle(Icon.called("hand-paper").of(Family.REGULAR) + " 403 Forbidden - Access Denied");
|
||||||
super.setParagraph(msg);
|
super.setParagraph(msg);
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.system.webserver.response.errors;
|
package com.djrapitops.plan.system.webserver.response.errors;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.file.PlanFiles;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ErrorResponse for GatewayException.
|
* ErrorResponse for GatewayException.
|
||||||
*
|
*
|
||||||
@ -11,7 +15,8 @@ package com.djrapitops.plan.system.webserver.response.errors;
|
|||||||
*/
|
*/
|
||||||
public class GatewayErrorResponse extends ErrorResponse {
|
public class GatewayErrorResponse extends ErrorResponse {
|
||||||
|
|
||||||
public GatewayErrorResponse(String message) {
|
public GatewayErrorResponse(String message, String version, PlanFiles files) throws IOException {
|
||||||
|
super(version, files);
|
||||||
super.setHeader("HTTP/1.1 504 Gateway Error");
|
super.setHeader("HTTP/1.1 504 Gateway Error");
|
||||||
super.setTitle("Failed to Connect (Gateway Error)");
|
super.setTitle("Failed to Connect (Gateway Error)");
|
||||||
super.setParagraph(message);
|
super.setParagraph(message);
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
package com.djrapitops.plan.system.webserver.response.errors;
|
package com.djrapitops.plan.system.webserver.response.errors;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.file.PlanFiles;
|
||||||
import com.djrapitops.plan.utilities.html.Html;
|
import com.djrapitops.plan.utilities.html.Html;
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 3.5.2
|
* @since 3.5.2
|
||||||
*/
|
*/
|
||||||
public class InternalErrorResponse extends ErrorResponse {
|
public class InternalErrorResponse extends ErrorResponse {
|
||||||
|
|
||||||
public InternalErrorResponse(String cause, Throwable e) {
|
public InternalErrorResponse(String cause, Throwable e, String version, PlanFiles files) throws IOException {
|
||||||
|
super(version, files);
|
||||||
super.setHeader("HTTP/1.1 500 Internal Error");
|
super.setHeader("HTTP/1.1 500 Internal Error");
|
||||||
|
|
||||||
super.setTitle(Icon.called("bug") + " 500 Internal Error occurred");
|
super.setTitle(Icon.called("bug") + " 500 Internal Error occurred");
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
package com.djrapitops.plan.system.webserver.response.errors;
|
package com.djrapitops.plan.system.webserver.response.errors;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.file.PlanFiles;
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Generic 404 response.
|
||||||
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
* @since 3.5.2
|
* @since 3.5.2
|
||||||
*/
|
*/
|
||||||
public class NotFoundResponse extends ErrorResponse {
|
public class NotFoundResponse extends ErrorResponse {
|
||||||
|
|
||||||
public NotFoundResponse() {
|
public NotFoundResponse(String msg, String version, PlanFiles files) throws IOException {
|
||||||
super.setHeader("HTTP/1.1 404 Not Found");
|
super(version, files);
|
||||||
super.setTitle(Icon.called("map-signs") + " 404 Not Found");
|
|
||||||
super.setParagraph("Page does not exist.");
|
|
||||||
super.replacePlaceholders();
|
|
||||||
}
|
|
||||||
|
|
||||||
public NotFoundResponse(String msg) {
|
|
||||||
super.setHeader("HTTP/1.1 404 Not Found");
|
super.setHeader("HTTP/1.1 404 Not Found");
|
||||||
super.setTitle(Icon.called("map-signs") + " 404 Not Found");
|
super.setTitle(Icon.called("map-signs") + " 404 Not Found");
|
||||||
super.setParagraph(msg);
|
super.setParagraph(msg);
|
||||||
super.replacePlaceholders();
|
super.replacePlaceholders();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,14 +4,18 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.system.webserver.response.errors;
|
package com.djrapitops.plan.system.webserver.response.errors;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.file.PlanFiles;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response when Server is not found in database when attempting to InfoRequest.
|
* Response when Server is not found in database when attempting to InfoRequest.
|
||||||
*
|
*
|
||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class UnauthorizedServerResponse extends ErrorResponse {
|
public class UnauthorizedServerResponse extends ErrorResponse {
|
||||||
|
public UnauthorizedServerResponse(String message, String version, PlanFiles files) throws IOException {
|
||||||
public UnauthorizedServerResponse(String message) {
|
super(version, files);
|
||||||
super.setHeader("HTTP/1.1 412 Unauthorized");
|
super.setHeader("HTTP/1.1 412 Unauthorized");
|
||||||
super.setTitle("Unauthorized Server");
|
super.setTitle("Unauthorized Server");
|
||||||
super.setParagraph(message);
|
super.setParagraph(message);
|
||||||
|
@ -8,7 +8,7 @@ import com.djrapitops.plan.system.processing.Processing;
|
|||||||
import com.djrapitops.plan.system.webserver.cache.PageId;
|
import com.djrapitops.plan.system.webserver.cache.PageId;
|
||||||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||||
import com.djrapitops.plan.system.webserver.response.Response;
|
import com.djrapitops.plan.system.webserver.response.Response;
|
||||||
import com.djrapitops.plan.system.webserver.response.errors.NotFoundResponse;
|
import com.djrapitops.plan.system.webserver.response.ResponseFactory;
|
||||||
import com.djrapitops.plan.utilities.html.pages.AnalysisPage;
|
import com.djrapitops.plan.utilities.html.pages.AnalysisPage;
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
import com.djrapitops.plugin.api.utility.log.Log;
|
||||||
|
|
||||||
@ -23,11 +23,12 @@ public class AnalysisPageResponse extends Response {
|
|||||||
// TODO Split responsibility so that this method does not call system to refresh and also render a refresh page.
|
// TODO Split responsibility so that this method does not call system to refresh and also render a refresh page.
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static AnalysisPageResponse refreshNow(UUID serverUUID, Processing processing, InfoSystem infoSystem) {
|
public static AnalysisPageResponse refreshNow(UUID serverUUID, Processing processing, InfoSystem infoSystem) {
|
||||||
|
ResponseFactory responseFactory = null; // TODO
|
||||||
processing.submitNonCritical(() -> {
|
processing.submitNonCritical(() -> {
|
||||||
try {
|
try {
|
||||||
infoSystem.generateAnalysisPage(serverUUID);
|
infoSystem.generateAnalysisPage(serverUUID);
|
||||||
} catch (NoServersException | ConnectionFailException e) {
|
} catch (NoServersException | ConnectionFailException e) {
|
||||||
ResponseCache.cacheResponse(PageId.SERVER.of(serverUUID), () -> new NotFoundResponse(e.getMessage()));
|
ResponseCache.cacheResponse(PageId.SERVER.of(serverUUID), () -> responseFactory.notFound404(e.getMessage()));
|
||||||
} catch (WebException e) {
|
} catch (WebException e) {
|
||||||
Log.toLog(AnalysisPageResponse.class.getName(), e);
|
Log.toLog(AnalysisPageResponse.class.getName(), e);
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.system.webserver.response.pages;
|
package com.djrapitops.plan.system.webserver.response.pages;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.system.file.PlanFiles;
|
||||||
import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse;
|
import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse;
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||||
import com.djrapitops.plan.utilities.html.pages.DebugPage;
|
import com.djrapitops.plan.utilities.html.pages.DebugPage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebServer response for /debug-page used for easing issue reporting.
|
* WebServer response for /debug-page used for easing issue reporting.
|
||||||
*
|
*
|
||||||
@ -15,7 +18,8 @@ import com.djrapitops.plan.utilities.html.pages.DebugPage;
|
|||||||
*/
|
*/
|
||||||
public class DebugPageResponse extends ErrorResponse {
|
public class DebugPageResponse extends ErrorResponse {
|
||||||
|
|
||||||
public DebugPageResponse(DebugPage debugPage) {
|
public DebugPageResponse(DebugPage debugPage, String version, PlanFiles files) throws IOException {
|
||||||
|
super(version, files);
|
||||||
super.setHeader("HTTP/1.1 200 OK");
|
super.setHeader("HTTP/1.1 200 OK");
|
||||||
super.setTitle(Icon.called("bug") + " Debug Information");
|
super.setTitle(Icon.called("bug") + " Debug Information");
|
||||||
super.setParagraph(debugPage.toHtml());
|
super.setParagraph(debugPage.toHtml());
|
||||||
|
@ -3,7 +3,6 @@ package com.djrapitops.plan.system.webserver.response.pages;
|
|||||||
import com.djrapitops.plan.system.webserver.cache.PageId;
|
import com.djrapitops.plan.system.webserver.cache.PageId;
|
||||||
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
|
||||||
import com.djrapitops.plan.system.webserver.response.Response;
|
import com.djrapitops.plan.system.webserver.response.Response;
|
||||||
import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse;
|
|
||||||
import com.djrapitops.plan.system.webserver.response.pages.parts.InspectPagePluginsContent;
|
import com.djrapitops.plan.system.webserver.response.pages.parts.InspectPagePluginsContent;
|
||||||
import org.apache.commons.text.StringSubstitutor;
|
import org.apache.commons.text.StringSubstitutor;
|
||||||
|
|
||||||
@ -40,12 +39,4 @@ public class InspectPageResponse extends Response {
|
|||||||
private String[] getCalculating() {
|
private String[] getCalculating() {
|
||||||
return new String[]{"<li><i class=\"fa fa-spin fa-refresh\"></i><a> Calculating...</a></li>", ""};
|
return new String[]{"<li><i class=\"fa fa-spin fa-refresh\"></i><a> Calculating...</a></li>", ""};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InspectPageResponse getRefreshing() {
|
|
||||||
ErrorResponse refreshPage = new ErrorResponse();
|
|
||||||
refreshPage.setTitle("Player page request is being processed..");
|
|
||||||
refreshPage.setParagraph("<meta http-equiv=\"refresh\" content=\"2\" /><i class=\"fa fa-refresh fa-spin\" aria-hidden=\"true\"></i> Page will refresh automatically..");
|
|
||||||
refreshPage.replacePlaceholders();
|
|
||||||
return new InspectPageResponse(null, refreshPage.getContent());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,13 @@ public class AnalysisPage implements Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getRefreshingHtml() {
|
public static String getRefreshingHtml() {
|
||||||
ErrorResponse refreshPage = new ErrorResponse();
|
// TODO Work this out
|
||||||
|
ErrorResponse refreshPage = null;
|
||||||
|
try {
|
||||||
|
refreshPage = new ErrorResponse("", null);
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
}
|
||||||
refreshPage.setTitle("Analysis is being refreshed..");
|
refreshPage.setTitle("Analysis is being refreshed..");
|
||||||
refreshPage.setParagraph("<meta http-equiv=\"refresh\" content=\"5\" /><i class=\"fa fa-refresh fa-spin\" aria-hidden=\"true\"></i> Analysis is being run, refresh the page after a few seconds.. (F5)");
|
refreshPage.setParagraph("<meta http-equiv=\"refresh\" content=\"5\" /><i class=\"fa fa-refresh fa-spin\" aria-hidden=\"true\"></i> Analysis is being run, refresh the page after a few seconds.. (F5)");
|
||||||
refreshPage.replacePlaceholders();
|
refreshPage.replacePlaceholders();
|
||||||
|
Loading…
Reference in New Issue
Block a user