--- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Sat Oct 31 10:54:20 2020 +0100 +++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Thu Nov 05 13:37:48 2020 +0100 @@ -108,7 +108,7 @@ throw new UnsupportedOperationException("Non-exhaustive if-else - this is a bug."); } - private ResponseType invokeMapping(Map.Entry<PathPattern, Method> mapping, HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { + private void invokeMapping(Map.Entry<PathPattern, Method> mapping, HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { final var pathPattern = mapping.getKey(); final var method = mapping.getValue(); try { @@ -128,19 +128,17 @@ paramValues[i] = pathPattern.obtainPathParameters(sanitizeRequestPath(req)); } } - return (ResponseType) method.invoke(this, paramValues); + method.invoke(this, paramValues); } catch (InvocationTargetException ex) { LOG.error("invocation of method {}::{} failed: {}", method.getDeclaringClass().getName(), method.getName(), ex.getTargetException().getMessage()); LOG.debug("Details: ", ex.getTargetException()); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getTargetException().getMessage()); - return ResponseType.NONE; } catch (ReflectiveOperationException | ClassCastException ex) { LOG.error("invocation of method {}::{} failed: {}", method.getDeclaringClass().getName(), method.getName(), ex.getMessage()); LOG.debug("Details: ", ex); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage()); - return ResponseType.NONE; } } @@ -176,12 +174,6 @@ ); continue; } - if (!ResponseType.class.isAssignableFrom(method.getReturnType())) { - LOG.warn("{} is annotated with {} but has the wrong return type - 'ResponseType' required", - method.getName(), RequestMapping.class.getSimpleName() - ); - continue; - } boolean paramsInjectible = true; for (var param : method.getParameterTypes()) { @@ -388,18 +380,8 @@ ); } - private void forwardAsSpecified(ResponseType type, HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - switch (type) { - case NONE: - return; - case HTML: - req.getRequestDispatcher(SITE_JSP).forward(req, resp); - return; - // TODO: implement remaining response types - default: - throw new AssertionError("ResponseType switch is not exhaustive - this is a bug!"); - } + protected void renderSite(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + req.getRequestDispatcher(SITE_JSP).forward(req, resp); } private void doProcess(HttpMethod method, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { @@ -428,7 +410,7 @@ if (fullPath.startsWith("/error/")) { final var mapping = findMapping(method, req); if (mapping.isPresent()) { - forwardAsSpecified(invokeMapping(mapping.get(), req, resp, null), req, resp); + invokeMapping(mapping.get(), req, resp, null); } return; } @@ -447,7 +429,7 @@ // 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); + invokeMapping(mapping.get(), req, resp, dao); } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND); }