Tue, 12 May 2020 22:03:00 +0200
fixes minor issues that were reported by default inspection
1.1 --- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Mon May 11 19:09:06 2020 +0200 1.2 +++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Tue May 12 22:03:00 2020 +0200 1.3 @@ -60,12 +60,6 @@ 1.4 */ 1.5 private LightPITModule.ELProxy moduleInfo = null; 1.6 1.7 - 1.8 - @FunctionalInterface 1.9 - private interface HandlerMethod { 1.10 - ResponseType apply(HttpServletRequest request, HttpServletResponse response, DataAccessObjects dao) throws IOException, SQLException; 1.11 - } 1.12 - 1.13 /** 1.14 * Invocation mapping gathered from the {@link RequestMapping} annotations. 1.15 * <p> 1.16 @@ -75,7 +69,7 @@ 1.17 * The reason for this is the different handling of empty paths in 1.18 * {@link HttpServletRequest#getPathInfo()}. 1.19 */ 1.20 - private final Map<HttpMethod, Map<String, HandlerMethod>> mappings = new HashMap<>(); 1.21 + private final Map<HttpMethod, Map<String, Method>> mappings = new HashMap<>(); 1.22 1.23 /** 1.24 * Gives implementing modules access to the {@link ModuleManager}. 1.25 @@ -95,12 +89,10 @@ 1.26 */ 1.27 private DataAccessObjects createDataAccessObjects(Connection connection) throws SQLException { 1.28 final var df = (DatabaseFacade) getServletContext().getAttribute(DatabaseFacade.SC_ATTR_NAME); 1.29 - switch (df.getSQLDialect()) { 1.30 - case Postgres: 1.31 - return new PGDataAccessObjects(connection); 1.32 - default: 1.33 - throw new AssertionError("Non-exhaustive switch - this is a bug."); 1.34 + if (df.getSQLDialect() == DatabaseFacade.Dialect.Postgres) { 1.35 + return new PGDataAccessObjects(connection); 1.36 } 1.37 + throw new AssertionError("Non-exhaustive if-else - this is a bug."); 1.38 } 1.39 1.40 private ResponseType invokeMapping(Method method, HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { 1.41 @@ -160,9 +152,9 @@ 1.42 1.43 final String requestPath = "/" + mapping.get().requestPath(); 1.44 1.45 - if (mappings.computeIfAbsent(mapping.get().method(), k -> new HashMap<>()). 1.46 - putIfAbsent(requestPath, 1.47 - (req, resp, dao) -> invokeMapping(method, req, resp, dao)) != null) { 1.48 + if (mappings 1.49 + .computeIfAbsent(mapping.get().method(), k -> new HashMap<>()) 1.50 + .putIfAbsent(requestPath, method) != null) { 1.51 LOG.warn("{} {} has multiple mappings", 1.52 mapping.get().method(), 1.53 mapping.get().requestPath() 1.54 @@ -232,10 +224,10 @@ 1.55 req.getRequestDispatcher(HTML_FULL_DISPATCHER).forward(req, resp); 1.56 } 1.57 1.58 - private Optional<HandlerMethod> findMapping(HttpMethod method, HttpServletRequest req) { 1.59 - return Optional.ofNullable(mappings.get(method)).map( 1.60 - (rm) -> rm.get(Optional.ofNullable(req.getPathInfo()).orElse("/")) 1.61 - ); 1.62 + private Optional<Method> findMapping(HttpMethod method, HttpServletRequest req) { 1.63 + return Optional.ofNullable(mappings.get(method)) 1.64 + .map(rm -> rm.get(Optional.ofNullable(req.getPathInfo()).orElse("/")) 1.65 + ); 1.66 } 1.67 1.68 private void forwardAsSpecified(ResponseType type, HttpServletRequest req, HttpServletResponse resp) 1.69 @@ -277,15 +269,24 @@ 1.70 final var db = (DatabaseFacade) req.getServletContext().getAttribute(DatabaseFacade.SC_ATTR_NAME); 1.71 try (final var connection = db.getDataSource().getConnection()) { 1.72 final var dao = createDataAccessObjects(connection); 1.73 - // call the handler, if available, or send an HTTP 404 error 1.74 - final var mapping = findMapping(method, req); 1.75 - if (mapping.isPresent()) { 1.76 - forwardAsSpecified(mapping.get().apply(req, resp, dao), req, resp); 1.77 - } else { 1.78 - resp.sendError(HttpServletResponse.SC_NOT_FOUND); 1.79 + try { 1.80 + connection.setAutoCommit(false); 1.81 + // call the handler, if available, or send an HTTP 404 error 1.82 + final var mapping = findMapping(method, req); 1.83 + if (mapping.isPresent()) { 1.84 + forwardAsSpecified(invokeMapping(mapping.get(), req, resp, dao), req, resp); 1.85 + } else { 1.86 + resp.sendError(HttpServletResponse.SC_NOT_FOUND); 1.87 + } 1.88 + connection.commit(); 1.89 + } catch (SQLException ex) { 1.90 + LOG.warn("Database transaction failed (Code {}): {}", ex.getErrorCode(), ex.getMessage()); 1.91 + LOG.debug("Details: ", ex); 1.92 + resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unhandled Transaction Error - Code:" + ex.getErrorCode()); 1.93 + connection.rollback(); 1.94 } 1.95 } catch (SQLException ex) { 1.96 - LOG.error("Database exception (Code {}): {}", ex.getErrorCode(), ex.getMessage()); 1.97 + LOG.error("Severe Database Exception (Code {}): {}", ex.getErrorCode(), ex.getMessage()); 1.98 LOG.debug("Details: ", ex); 1.99 resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Database Error - Code:" + ex.getErrorCode()); 1.100 }
2.1 --- a/src/main/java/de/uapcore/lightpit/dao/AbstractDao.java Mon May 11 19:09:06 2020 +0200 2.2 +++ b/src/main/java/de/uapcore/lightpit/dao/AbstractDao.java Tue May 12 22:03:00 2020 +0200 2.3 @@ -74,7 +74,7 @@ 2.4 } 2.5 } 2.6 2.7 - protected final <T> void setForeignKeyOrNull(PreparedStatement stmt, int index, T instance, Function<T, Integer> keyGetter) throws SQLException { 2.8 + protected final void setForeignKeyOrNull(PreparedStatement stmt, int index, Object instance, Function<Object, Integer> keyGetter) throws SQLException { 2.9 Integer key = Optional.ofNullable(instance).map(keyGetter).orElse(null); 2.10 if (key == null) { 2.11 stmt.setNull(index, Types.INTEGER);
3.1 --- a/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java Mon May 11 19:09:06 2020 +0200 3.2 +++ b/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java Tue May 12 22:03:00 2020 +0200 3.3 @@ -68,13 +68,13 @@ 3.4 } 3.5 languages.add(locale); 3.6 } catch (IllformedLocaleException ex) { 3.7 - LOG.warn("Specified lanaguge {} in context parameter cannot be mapped to an existing locale - skipping.", lang); 3.8 + LOG.warn("Specified language {} in context parameter cannot be mapped to an existing locale - skipping.", lang); 3.9 } 3.10 } 3.11 3.12 } else { 3.13 languages.add(Locale.ENGLISH); 3.14 - LOG.warn("Context parameter 'available-languges' not found. Only english will be available."); 3.15 + LOG.warn("Context parameter 'available-languages' not found. Only english will be available."); 3.16 } 3.17 } 3.18
4.1 --- a/src/main/webapp/WEB-INF/dynamic_fragments/error.jsp Mon May 11 19:09:06 2020 +0200 4.2 +++ b/src/main/webapp/WEB-INF/dynamic_fragments/error.jsp Tue May 12 22:03:00 2020 +0200 4.3 @@ -24,18 +24,20 @@ 4.4 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 4.5 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4.6 --%> 4.7 -<%@page pageEncoding="UTF-8" session="true" %> 4.8 +<%@page pageEncoding="UTF-8" %> 4.9 <%@page import="de.uapcore.lightpit.modules.ErrorModule" %> 4.10 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4.11 <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 4.12 4.13 +<jsp:useBean id="exception" scope="request" type="java.lang.Throwable"/> 4.14 + 4.15 <c:set scope="page" var="errorCode" value="${requestScope[ErrorModule.REQ_ATTR_ERROR_CODE]}"/> 4.16 4.17 <div id="error-page"> 4.18 <h1><fmt:message key="h1"/></h1> 4.19 <table> 4.20 <tr> 4.21 - <th><fmt:message key="errorCode" />:</th> 4.22 + <th><fmt:message key="errorCode"/>:</th> 4.23 <td>${errorCode}</td> 4.24 </tr> 4.25 <tr>
5.1 --- a/src/main/webapp/WEB-INF/dynamic_fragments/language.jsp Mon May 11 19:09:06 2020 +0200 5.2 +++ b/src/main/webapp/WEB-INF/dynamic_fragments/language.jsp Tue May 12 22:03:00 2020 +0200 5.3 @@ -24,20 +24,25 @@ 5.4 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 5.5 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5.6 --%> 5.7 -<%@page pageEncoding="UTF-8" session="true" %> 5.8 +<%@page pageEncoding="UTF-8" %> 5.9 <%@page import="de.uapcore.lightpit.Constants" %> 5.10 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 5.11 <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 5.12 5.13 -<c:set scope="page" var="currentLanguage" value="${sessionScope[Constants.SESSION_ATTR_LANGUAGE]}" /> 5.14 +<jsp:useBean id="languages" type="java.util.List<java.util.Locale>" scope="request"/> 5.15 +<jsp:useBean id="browserLanguage" type="java.util.Locale" scope="request"/> 5.16 5.17 -<form method="POST"id="lang-selector"> 5.18 +<c:set scope="page" var="currentLanguage" value="${sessionScope[Constants.SESSION_ATTR_LANGUAGE]}"/> 5.19 + 5.20 +<form method="POST" id="lang-selector"> 5.21 <c:forEach items="${languages}" var="l"> 5.22 <label> 5.23 <input type="radio" name="language" value="${l.language}" 5.24 <c:if test="${l.language eq currentLanguage.language}">checked</c:if>/> 5.25 - ${l.displayLanguage} 5.26 - (${l.getDisplayLanguage(currentLanguage)}<c:if test="${not empty browserLanguage and l.language eq browserLanguage.language}"><c:set var="browserLanguagePresent" value="true"/> - <fmt:message key="browserLanguage"/></c:if>) 5.27 + ${l.displayLanguage} 5.28 + (${l.getDisplayLanguage(currentLanguage)} 5.29 + <c:if test="${not empty browserLanguage and l.language eq browserLanguage.language}"><c:set 5.30 + var="browserLanguagePresent" value="true"/> - <fmt:message key="browserLanguage"/></c:if>) 5.31 </label> 5.32 </c:forEach> 5.33 <c:if test="${not browserLanguagePresent}">
6.1 --- a/src/main/webapp/WEB-INF/jsp/html_full.jsp Mon May 11 19:09:06 2020 +0200 6.2 +++ b/src/main/webapp/WEB-INF/jsp/html_full.jsp Tue May 12 22:03:00 2020 +0200 6.3 @@ -24,7 +24,7 @@ 6.4 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 6.5 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 6.6 --%> 6.7 -<%@page contentType="text/html" pageEncoding="UTF-8" trimDirectiveWhitespaces="true" session="true" %> 6.8 +<%@page contentType="text/html" pageEncoding="UTF-8" trimDirectiveWhitespaces="true" %> 6.9 <%@page import="de.uapcore.lightpit.Constants" %> 6.10 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 6.11 <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
7.1 --- a/src/main/webapp/lightpit.css Mon May 11 19:09:06 2020 +0200 7.2 +++ b/src/main/webapp/lightpit.css Tue May 12 22:03:00 2020 +0200 7.3 @@ -60,8 +60,7 @@ 7.4 7.5 #subMenu { 7.6 background: #f7f7ff; 7.7 - 7.8 - border-image: linear-gradient(to right, #606060, rgba(60,60,60,.25)); 7.9 + border-image-source: linear-gradient(to right, #606060, rgba(60, 60, 60, .25)); 7.10 border-image-slice: 1; 7.11 border-top-style: solid; 7.12 border-top-width: 1pt;