# HG changeset patch # User Mike Becker # Date 1589636706 -7200 # Node ID 6a849829160685ce623b3c956a5db24ea06ca988 # Parent 67a02e79b7a1f75299f8f94086b47f93567cf264 fixes bug where displaying an error page for missing data source would also require that data source (error pages don't try to get database connections now) also improves error pages in general diff -r 67a02e79b7a1 -r 6a8498291606 src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java --- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Sat May 16 15:11:07 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Sat May 16 15:45:06 2020 +0200 @@ -324,13 +324,28 @@ } // set some internal request attributes + final String fullPath = Functions.fullPath(req); req.setAttribute(Constants.REQ_ATTR_BASE_HREF, Functions.baseHref(req)); - req.setAttribute(Constants.REQ_ATTR_PATH, Functions.fullPath(req)); + req.setAttribute(Constants.REQ_ATTR_PATH, fullPath); Optional.ofNullable(moduleInfo).ifPresent((proxy) -> req.setAttribute(Constants.REQ_ATTR_MODULE_INFO, proxy)); + // if this is an error path, bypass the normal flow + if (fullPath.startsWith("/error/")) { + final var mapping = findMapping(method, req); + if (mapping.isPresent()) { + forwardAsSpecified(invokeMapping(mapping.get(), req, resp, null), req, resp); + } + return; + } + // obtain a connection and create the data access objects final var db = (DatabaseFacade) req.getServletContext().getAttribute(DatabaseFacade.SC_ATTR_NAME); - try (final var connection = db.getDataSource().getConnection()) { + final var ds = db.getDataSource(); + if (ds == null) { + resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "JNDI DataSource lookup failed. See log for details."); + return; + } + try (final var connection = ds.getConnection()) { final var dao = createDataAccessObjects(connection); try { connection.setAutoCommit(false); diff -r 67a02e79b7a1 -r 6a8498291606 src/main/java/de/uapcore/lightpit/modules/ErrorModule.java --- a/src/main/java/de/uapcore/lightpit/modules/ErrorModule.java Sat May 16 15:11:07 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/modules/ErrorModule.java Sat May 16 15:45:06 2020 +0200 @@ -32,6 +32,7 @@ import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.Optional; /** @@ -49,13 +50,10 @@ ) public final class ErrorModule extends AbstractLightPITServlet { - public static final String REQ_ATTR_ERROR_CODE = "errorCode"; public static final String REQ_ATTR_RETURN_LINK = "returnLink"; - private ResponseType handle(HttpServletRequest req, int sc) { - - req.setAttribute(REQ_ATTR_ERROR_CODE, sc); - + @RequestMapping(requestPath = "generic", method = HttpMethod.GET) + public ResponseType onError(HttpServletRequest req, HttpServletResponse resp) { Optional.ofNullable(req.getHeader("Referer")).ifPresent( referer -> req.setAttribute(REQ_ATTR_RETURN_LINK, referer) ); @@ -65,19 +63,4 @@ return ResponseType.HTML; } - - @RequestMapping(requestPath = "404.html", method = HttpMethod.GET) - public ResponseType handle404(HttpServletRequest req) { - return handle(req, 404); - } - - @RequestMapping(requestPath = "403.html", method = HttpMethod.GET) - public ResponseType handle403(HttpServletRequest req) { - return handle(req, 403); - } - - @RequestMapping(requestPath = "500.html", method = HttpMethod.GET) - public ResponseType handle500(HttpServletRequest req) { - return handle(req, 500); - } } diff -r 67a02e79b7a1 -r 6a8498291606 src/main/resources/localization/error.properties --- a/src/main/resources/localization/error.properties Sat May 16 15:11:07 2020 +0200 +++ b/src/main/resources/localization/error.properties Sat May 16 15:45:06 2020 +0200 @@ -26,10 +26,11 @@ h1 = The requested page cannot be displayed. errorCode = Code -errorMessage = Message -errorMessage.404 = Page not found -errorMessage.403 = Access denied -errorMessage.500 = Internal error +errorMessage = Server Message +code.404 = Page not found +code.403 = Access denied +code.500 = Internal error +code.503 = Service unavailable errorTimestamp = Timestamp errorExceptionText = Internal Exception diff -r 67a02e79b7a1 -r 6a8498291606 src/main/resources/localization/error_de.properties --- a/src/main/resources/localization/error_de.properties Sat May 16 15:11:07 2020 +0200 +++ b/src/main/resources/localization/error_de.properties Sat May 16 15:45:06 2020 +0200 @@ -26,10 +26,11 @@ h1 = Die angeforderte Seite kann nicht angezeigt werden. errorCode = Fehlercode -errorMessage = Nachricht -errorMessage.404 = Seite nicht gefunden -errorMessage.403 = Zugriff verboten -errorMessage.500 = Interner Fehler +errorMessage = Server Nachricht +code.404 = Seite nicht gefunden +code.403 = Zugriff verboten +code.500 = Interner Fehler +code.503 = Dienst steht derzeit nicht zur Verfügung errorTimestamp = Zeitstempel errorExceptionText = Interne Ausnahme diff -r 67a02e79b7a1 -r 6a8498291606 src/main/webapp/WEB-INF/dynamic_fragments/error.jsp --- a/src/main/webapp/WEB-INF/dynamic_fragments/error.jsp Sat May 16 15:11:07 2020 +0200 +++ b/src/main/webapp/WEB-INF/dynamic_fragments/error.jsp Sat May 16 15:45:06 2020 +0200 @@ -32,7 +32,7 @@ <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> - +
@@ -40,11 +40,11 @@ - + - + diff -r 67a02e79b7a1 -r 6a8498291606 src/main/webapp/WEB-INF/web.xml --- a/src/main/webapp/WEB-INF/web.xml Sat May 16 15:11:07 2020 +0200 +++ b/src/main/webapp/WEB-INF/web.xml Sat May 16 15:45:06 2020 +0200 @@ -17,15 +17,6 @@ java:/jdbc/lightpit/app - 404 - /error/404.html - - - 403 - /error/403.html - - - 500 - /error/500.html + /error/generic diff -r 67a02e79b7a1 -r 6a8498291606 src/main/webapp/error.css --- a/src/main/webapp/error.css Sat May 16 15:11:07 2020 +0200 +++ b/src/main/webapp/error.css Sat May 16 15:45:06 2020 +0200 @@ -48,6 +48,7 @@ #error-page table th { text-align: right; + white-space: nowrap; } #error-page table td {
:${errorCode}${errorCode} -
:
: