# HG changeset patch # User Mike Becker # Date 1589313780 -7200 # Node ID e722861558bbaa6e43676b236e5d7d8ea13c4f67 # Parent cf85ef18f23142b099893b281dce0ec979d0fd44 fixes minor issues that were reported by default inspection diff -r cf85ef18f231 -r e722861558bb src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java --- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Mon May 11 19:09:06 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Tue May 12 22:03:00 2020 +0200 @@ -60,12 +60,6 @@ */ private LightPITModule.ELProxy moduleInfo = null; - - @FunctionalInterface - private interface HandlerMethod { - ResponseType apply(HttpServletRequest request, HttpServletResponse response, DataAccessObjects dao) throws IOException, SQLException; - } - /** * Invocation mapping gathered from the {@link RequestMapping} annotations. *

@@ -75,7 +69,7 @@ * The reason for this is the different handling of empty paths in * {@link HttpServletRequest#getPathInfo()}. */ - private final Map> mappings = new HashMap<>(); + private final Map> mappings = new HashMap<>(); /** * Gives implementing modules access to the {@link ModuleManager}. @@ -95,12 +89,10 @@ */ private DataAccessObjects createDataAccessObjects(Connection connection) throws SQLException { final var df = (DatabaseFacade) getServletContext().getAttribute(DatabaseFacade.SC_ATTR_NAME); - switch (df.getSQLDialect()) { - case Postgres: - return new PGDataAccessObjects(connection); - default: - throw new AssertionError("Non-exhaustive switch - this is a bug."); + if (df.getSQLDialect() == DatabaseFacade.Dialect.Postgres) { + return new PGDataAccessObjects(connection); } + throw new AssertionError("Non-exhaustive if-else - this is a bug."); } private ResponseType invokeMapping(Method method, HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { @@ -160,9 +152,9 @@ final String requestPath = "/" + mapping.get().requestPath(); - if (mappings.computeIfAbsent(mapping.get().method(), k -> new HashMap<>()). - putIfAbsent(requestPath, - (req, resp, dao) -> invokeMapping(method, req, resp, dao)) != null) { + if (mappings + .computeIfAbsent(mapping.get().method(), k -> new HashMap<>()) + .putIfAbsent(requestPath, method) != null) { LOG.warn("{} {} has multiple mappings", mapping.get().method(), mapping.get().requestPath() @@ -232,10 +224,10 @@ req.getRequestDispatcher(HTML_FULL_DISPATCHER).forward(req, resp); } - private Optional findMapping(HttpMethod method, HttpServletRequest req) { - return Optional.ofNullable(mappings.get(method)).map( - (rm) -> rm.get(Optional.ofNullable(req.getPathInfo()).orElse("/")) - ); + private Optional findMapping(HttpMethod method, HttpServletRequest req) { + return Optional.ofNullable(mappings.get(method)) + .map(rm -> rm.get(Optional.ofNullable(req.getPathInfo()).orElse("/")) + ); } private void forwardAsSpecified(ResponseType type, HttpServletRequest req, HttpServletResponse resp) @@ -277,15 +269,24 @@ final var db = (DatabaseFacade) req.getServletContext().getAttribute(DatabaseFacade.SC_ATTR_NAME); try (final var connection = db.getDataSource().getConnection()) { final var dao = createDataAccessObjects(connection); - // call the handler, if available, or send an HTTP 404 error - final var mapping = findMapping(method, req); - if (mapping.isPresent()) { - forwardAsSpecified(mapping.get().apply(req, resp, dao), req, resp); - } else { - resp.sendError(HttpServletResponse.SC_NOT_FOUND); + try { + connection.setAutoCommit(false); + // call the handler, if available, or send an HTTP 404 error + final var mapping = findMapping(method, req); + if (mapping.isPresent()) { + forwardAsSpecified(invokeMapping(mapping.get(), req, resp, dao), req, resp); + } else { + resp.sendError(HttpServletResponse.SC_NOT_FOUND); + } + connection.commit(); + } catch (SQLException ex) { + LOG.warn("Database transaction failed (Code {}): {}", ex.getErrorCode(), ex.getMessage()); + LOG.debug("Details: ", ex); + resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unhandled Transaction Error - Code:" + ex.getErrorCode()); + connection.rollback(); } } catch (SQLException ex) { - LOG.error("Database exception (Code {}): {}", ex.getErrorCode(), ex.getMessage()); + LOG.error("Severe Database Exception (Code {}): {}", ex.getErrorCode(), ex.getMessage()); LOG.debug("Details: ", ex); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Database Error - Code:" + ex.getErrorCode()); } diff -r cf85ef18f231 -r e722861558bb src/main/java/de/uapcore/lightpit/dao/AbstractDao.java --- a/src/main/java/de/uapcore/lightpit/dao/AbstractDao.java Mon May 11 19:09:06 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/dao/AbstractDao.java Tue May 12 22:03:00 2020 +0200 @@ -74,7 +74,7 @@ } } - protected final void setForeignKeyOrNull(PreparedStatement stmt, int index, T instance, Function keyGetter) throws SQLException { + protected final void setForeignKeyOrNull(PreparedStatement stmt, int index, Object instance, Function keyGetter) throws SQLException { Integer key = Optional.ofNullable(instance).map(keyGetter).orElse(null); if (key == null) { stmt.setNull(index, Types.INTEGER); diff -r cf85ef18f231 -r e722861558bb src/main/java/de/uapcore/lightpit/modules/LanguageModule.java --- a/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java Mon May 11 19:09:06 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java Tue May 12 22:03:00 2020 +0200 @@ -68,13 +68,13 @@ } languages.add(locale); } catch (IllformedLocaleException ex) { - LOG.warn("Specified lanaguge {} in context parameter cannot be mapped to an existing locale - skipping.", lang); + LOG.warn("Specified language {} in context parameter cannot be mapped to an existing locale - skipping.", lang); } } } else { languages.add(Locale.ENGLISH); - LOG.warn("Context parameter 'available-languges' not found. Only english will be available."); + LOG.warn("Context parameter 'available-languages' not found. Only english will be available."); } } diff -r cf85ef18f231 -r e722861558bb src/main/webapp/WEB-INF/dynamic_fragments/error.jsp --- a/src/main/webapp/WEB-INF/dynamic_fragments/error.jsp Mon May 11 19:09:06 2020 +0200 +++ b/src/main/webapp/WEB-INF/dynamic_fragments/error.jsp Tue May 12 22:03:00 2020 +0200 @@ -24,18 +24,20 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --%> -<%@page pageEncoding="UTF-8" session="true" %> +<%@page pageEncoding="UTF-8" %> <%@page import="de.uapcore.lightpit.modules.ErrorModule" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> + +

- + diff -r cf85ef18f231 -r e722861558bb src/main/webapp/WEB-INF/dynamic_fragments/language.jsp --- a/src/main/webapp/WEB-INF/dynamic_fragments/language.jsp Mon May 11 19:09:06 2020 +0200 +++ b/src/main/webapp/WEB-INF/dynamic_fragments/language.jsp Tue May 12 22:03:00 2020 +0200 @@ -24,20 +24,25 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --%> -<%@page pageEncoding="UTF-8" session="true" %> +<%@page pageEncoding="UTF-8" %> <%@page import="de.uapcore.lightpit.Constants" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> - + + -
+ + + diff -r cf85ef18f231 -r e722861558bb src/main/webapp/WEB-INF/jsp/html_full.jsp --- a/src/main/webapp/WEB-INF/jsp/html_full.jsp Mon May 11 19:09:06 2020 +0200 +++ b/src/main/webapp/WEB-INF/jsp/html_full.jsp Tue May 12 22:03:00 2020 +0200 @@ -24,7 +24,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --%> -<%@page contentType="text/html" pageEncoding="UTF-8" trimDirectiveWhitespaces="true" session="true" %> +<%@page contentType="text/html" pageEncoding="UTF-8" trimDirectiveWhitespaces="true" %> <%@page import="de.uapcore.lightpit.Constants" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> diff -r cf85ef18f231 -r e722861558bb src/main/webapp/lightpit.css --- a/src/main/webapp/lightpit.css Mon May 11 19:09:06 2020 +0200 +++ b/src/main/webapp/lightpit.css Tue May 12 22:03:00 2020 +0200 @@ -60,8 +60,7 @@ #subMenu { background: #f7f7ff; - - border-image: linear-gradient(to right, #606060, rgba(60,60,60,.25)); + border-image-source: linear-gradient(to right, #606060, rgba(60, 60, 60, .25)); border-image-slice: 1; border-top-style: solid; border-top-width: 1pt;
:: ${errorCode}