Thu, 05 Nov 2020 13:37:48 +0100
removes ResponseType enum
1.1 --- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Sat Oct 31 10:54:20 2020 +0100 1.2 +++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java Thu Nov 05 13:37:48 2020 +0100 1.3 @@ -108,7 +108,7 @@ 1.4 throw new UnsupportedOperationException("Non-exhaustive if-else - this is a bug."); 1.5 } 1.6 1.7 - private ResponseType invokeMapping(Map.Entry<PathPattern, Method> mapping, HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { 1.8 + private void invokeMapping(Map.Entry<PathPattern, Method> mapping, HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { 1.9 final var pathPattern = mapping.getKey(); 1.10 final var method = mapping.getValue(); 1.11 try { 1.12 @@ -128,19 +128,17 @@ 1.13 paramValues[i] = pathPattern.obtainPathParameters(sanitizeRequestPath(req)); 1.14 } 1.15 } 1.16 - return (ResponseType) method.invoke(this, paramValues); 1.17 + method.invoke(this, paramValues); 1.18 } catch (InvocationTargetException ex) { 1.19 LOG.error("invocation of method {}::{} failed: {}", 1.20 method.getDeclaringClass().getName(), method.getName(), ex.getTargetException().getMessage()); 1.21 LOG.debug("Details: ", ex.getTargetException()); 1.22 resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getTargetException().getMessage()); 1.23 - return ResponseType.NONE; 1.24 } catch (ReflectiveOperationException | ClassCastException ex) { 1.25 LOG.error("invocation of method {}::{} failed: {}", 1.26 method.getDeclaringClass().getName(), method.getName(), ex.getMessage()); 1.27 LOG.debug("Details: ", ex); 1.28 resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage()); 1.29 - return ResponseType.NONE; 1.30 } 1.31 } 1.32 1.33 @@ -176,12 +174,6 @@ 1.34 ); 1.35 continue; 1.36 } 1.37 - if (!ResponseType.class.isAssignableFrom(method.getReturnType())) { 1.38 - LOG.warn("{} is annotated with {} but has the wrong return type - 'ResponseType' required", 1.39 - method.getName(), RequestMapping.class.getSimpleName() 1.40 - ); 1.41 - continue; 1.42 - } 1.43 1.44 boolean paramsInjectible = true; 1.45 for (var param : method.getParameterTypes()) { 1.46 @@ -388,18 +380,8 @@ 1.47 ); 1.48 } 1.49 1.50 - private void forwardAsSpecified(ResponseType type, HttpServletRequest req, HttpServletResponse resp) 1.51 - throws ServletException, IOException { 1.52 - switch (type) { 1.53 - case NONE: 1.54 - return; 1.55 - case HTML: 1.56 - req.getRequestDispatcher(SITE_JSP).forward(req, resp); 1.57 - return; 1.58 - // TODO: implement remaining response types 1.59 - default: 1.60 - throw new AssertionError("ResponseType switch is not exhaustive - this is a bug!"); 1.61 - } 1.62 + protected void renderSite(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 1.63 + req.getRequestDispatcher(SITE_JSP).forward(req, resp); 1.64 } 1.65 1.66 private void doProcess(HttpMethod method, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 1.67 @@ -428,7 +410,7 @@ 1.68 if (fullPath.startsWith("/error/")) { 1.69 final var mapping = findMapping(method, req); 1.70 if (mapping.isPresent()) { 1.71 - forwardAsSpecified(invokeMapping(mapping.get(), req, resp, null), req, resp); 1.72 + invokeMapping(mapping.get(), req, resp, null); 1.73 } 1.74 return; 1.75 } 1.76 @@ -447,7 +429,7 @@ 1.77 // call the handler, if available, or send an HTTP 404 error 1.78 final var mapping = findMapping(method, req); 1.79 if (mapping.isPresent()) { 1.80 - forwardAsSpecified(invokeMapping(mapping.get(), req, resp, dao), req, resp); 1.81 + invokeMapping(mapping.get(), req, resp, dao); 1.82 } else { 1.83 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 1.84 }
2.1 --- a/src/main/java/de/uapcore/lightpit/ResponseType.java Sat Oct 31 10:54:20 2020 +0100 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,56 +0,0 @@ 2.4 -/* 2.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 2.6 - * 2.7 - * Copyright 2018 Mike Becker. All rights reserved. 2.8 - * 2.9 - * Redistribution and use in source and binary forms, with or without 2.10 - * modification, are permitted provided that the following conditions are met: 2.11 - * 2.12 - * 1. Redistributions of source code must retain the above copyright 2.13 - * notice, this list of conditions and the following disclaimer. 2.14 - * 2.15 - * 2. Redistributions in binary form must reproduce the above copyright 2.16 - * notice, this list of conditions and the following disclaimer in the 2.17 - * documentation and/or other materials provided with the distribution. 2.18 - * 2.19 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2.20 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2.21 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2.22 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 2.23 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2.24 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2.25 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2.26 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2.27 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2.28 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2.29 - * POSSIBILITY OF SUCH DAMAGE. 2.30 - * 2.31 - */ 2.32 -package de.uapcore.lightpit; 2.33 - 2.34 - 2.35 -public enum ResponseType { 2.36 - /** 2.37 - * Renders a full HTML view including the header. 2.38 - */ 2.39 - HTML, 2.40 - /** 2.41 - * Renders a HTML fragment only. 2.42 - * May be used for AJAX responses. 2.43 - */ 2.44 - HTML_FRAGMENT, 2.45 - /** 2.46 - * Returns a fragment with content type 'text/plain'. 2.47 - */ 2.48 - PLAIN, 2.49 - /** 2.50 - * Returns an object in JSON format and with content type 2.51 - * 'application/json'. 2.52 - */ 2.53 - JSON, 2.54 - /** 2.55 - * The handler already sent the output, nothing should be done 2.56 - * additionally by the Servlet. 2.57 - */ 2.58 - NONE 2.59 -}
3.1 --- a/src/main/java/de/uapcore/lightpit/modules/ErrorModule.java Sat Oct 31 10:54:20 2020 +0100 3.2 +++ b/src/main/java/de/uapcore/lightpit/modules/ErrorModule.java Thu Nov 05 13:37:48 2020 +0100 3.3 @@ -31,11 +31,12 @@ 3.4 import de.uapcore.lightpit.AbstractLightPITServlet; 3.5 import de.uapcore.lightpit.HttpMethod; 3.6 import de.uapcore.lightpit.RequestMapping; 3.7 -import de.uapcore.lightpit.ResponseType; 3.8 3.9 +import javax.servlet.ServletException; 3.10 import javax.servlet.annotation.WebServlet; 3.11 import javax.servlet.http.HttpServletRequest; 3.12 import javax.servlet.http.HttpServletResponse; 3.13 +import java.io.IOException; 3.14 import java.util.Optional; 3.15 3.16 @WebServlet( 3.17 @@ -52,7 +53,7 @@ 3.18 } 3.19 3.20 @RequestMapping(requestPath = "generic", method = HttpMethod.GET) 3.21 - public ResponseType onError(HttpServletRequest req, HttpServletResponse resp) { 3.22 + public void onError(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 3.23 Optional.ofNullable(req.getHeader("Referer")).ifPresent( 3.24 referer -> req.setAttribute(REQ_ATTR_RETURN_LINK, referer) 3.25 ); 3.26 @@ -60,6 +61,6 @@ 3.27 setStylesheet(req, "error"); 3.28 setContentPage(req, "error"); 3.29 3.30 - return ResponseType.HTML; 3.31 + renderSite(req, resp); 3.32 } 3.33 }
4.1 --- a/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java Sat Oct 31 10:54:20 2020 +0100 4.2 +++ b/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java Thu Nov 05 13:37:48 2020 +0100 4.3 @@ -37,6 +37,7 @@ 4.4 import javax.servlet.annotation.WebServlet; 4.5 import javax.servlet.http.HttpServletRequest; 4.6 import javax.servlet.http.HttpServletResponse; 4.7 +import java.io.IOException; 4.8 import java.util.*; 4.9 4.10 @WebServlet( 4.11 @@ -85,7 +86,7 @@ 4.12 } 4.13 4.14 @RequestMapping(method = HttpMethod.GET) 4.15 - public ResponseType handle(HttpServletRequest req) { 4.16 + public void handle(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 4.17 4.18 final var viewModel = new LanguageView(); 4.19 viewModel.setLanguages(languages); 4.20 @@ -95,11 +96,12 @@ 4.21 setViewModel(req, viewModel); 4.22 setStylesheet(req, "language"); 4.23 setContentPage(req, "language"); 4.24 - return ResponseType.HTML; 4.25 + 4.26 + renderSite(req, resp); 4.27 } 4.28 4.29 @RequestMapping(method = HttpMethod.POST) 4.30 - public ResponseType switchLanguage(HttpServletRequest req, HttpServletResponse resp) { 4.31 + public void switchLanguage(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 4.32 4.33 Optional<Locale> chosenLanguage = Optional.ofNullable(req.getParameter("language")) 4.34 .map(Locale::forLanguageTag) 4.35 @@ -108,6 +110,6 @@ 4.36 chosenLanguage.ifPresent((l) -> req.getSession().setAttribute(Constants.SESSION_ATTR_LANGUAGE, l)); 4.37 chosenLanguage.ifPresent(resp::setLocale); 4.38 4.39 - return handle(req); 4.40 + handle(req, resp); 4.41 } 4.42 }
5.1 --- a/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java Sat Oct 31 10:54:20 2020 +0100 5.2 +++ b/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java Thu Nov 05 13:37:48 2020 +0100 5.3 @@ -38,6 +38,7 @@ 5.4 import org.slf4j.Logger; 5.5 import org.slf4j.LoggerFactory; 5.6 5.7 +import javax.servlet.ServletException; 5.8 import javax.servlet.annotation.WebServlet; 5.9 import javax.servlet.http.HttpServletRequest; 5.10 import javax.servlet.http.HttpServletResponse; 5.11 @@ -115,16 +116,16 @@ 5.12 } 5.13 } 5.14 5.15 - private ResponseType forwardView(HttpServletRequest req, ProjectView viewModel, String name) { 5.16 + private void forwardView(HttpServletRequest req, HttpServletResponse resp, ProjectView viewModel, String name) throws ServletException, IOException { 5.17 setViewModel(req, viewModel); 5.18 setContentPage(req, name); 5.19 setStylesheet(req, "projects"); 5.20 setNavigationMenu(req, "project-navmenu"); 5.21 - return ResponseType.HTML; 5.22 + renderSite(req, resp); 5.23 } 5.24 5.25 @RequestMapping(method = HttpMethod.GET) 5.26 - public ResponseType index(HttpServletRequest req, DataAccessObjects dao) throws SQLException { 5.27 + public void index(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, ServletException, IOException { 5.28 final var viewModel = new ProjectView(); 5.29 populate(viewModel, null, dao); 5.30 5.31 @@ -136,7 +137,7 @@ 5.32 info.setIssueSummary(projectDao.getIssueSummary(info.getProject())); 5.33 } 5.34 5.35 - return forwardView(req, viewModel, "projects"); 5.36 + forwardView(req, resp, viewModel, "projects"); 5.37 } 5.38 5.39 private void configureProjectEditor(ProjectEditView viewModel, Project project, DataAccessObjects dao) throws SQLException { 5.40 @@ -145,29 +146,29 @@ 5.41 } 5.42 5.43 @RequestMapping(requestPath = "$project/edit", method = HttpMethod.GET) 5.44 - public ResponseType edit(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParams, DataAccessObjects dao) throws IOException, SQLException { 5.45 + public void edit(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParams, DataAccessObjects dao) throws IOException, SQLException, ServletException { 5.46 final var viewModel = new ProjectEditView(); 5.47 populate(viewModel, pathParams, dao); 5.48 5.49 if (!viewModel.isProjectInfoPresent()) { 5.50 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.51 - return ResponseType.NONE; 5.52 + return; 5.53 } 5.54 5.55 configureProjectEditor(viewModel, viewModel.getProjectInfo().getProject(), dao); 5.56 - return forwardView(req, viewModel, "project-form"); 5.57 + forwardView(req, resp, viewModel, "project-form"); 5.58 } 5.59 5.60 @RequestMapping(requestPath = "create", method = HttpMethod.GET) 5.61 - public ResponseType create(HttpServletRequest req, DataAccessObjects dao) throws SQLException { 5.62 + public void create(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, ServletException, IOException { 5.63 final var viewModel = new ProjectEditView(); 5.64 populate(viewModel, null, dao); 5.65 configureProjectEditor(viewModel, new Project(-1), dao); 5.66 - return forwardView(req, viewModel, "project-form"); 5.67 + forwardView(req, resp, viewModel, "project-form"); 5.68 } 5.69 5.70 @RequestMapping(requestPath = "commit", method = HttpMethod.POST) 5.71 - public ResponseType commit(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { 5.72 + public void commit(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, ServletException { 5.73 5.74 try { 5.75 final var project = new Project(getParameter(req, Integer.class, "pid").orElseThrow()); 5.76 @@ -188,22 +189,21 @@ 5.77 setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); 5.78 LOG.debug("Successfully updated project {}", project.getName()); 5.79 5.80 - return ResponseType.HTML; 5.81 + renderSite(req, resp); 5.82 } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { 5.83 resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); 5.84 // TODO: implement - fix issue #21 5.85 - return ResponseType.NONE; 5.86 } 5.87 } 5.88 5.89 @RequestMapping(requestPath = "$project/$component/$version/issues/", method = HttpMethod.GET) 5.90 - public ResponseType issues(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParams, DataAccessObjects dao) throws SQLException, IOException { 5.91 + public void issues(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParams, DataAccessObjects dao) throws SQLException, IOException, ServletException { 5.92 final var viewModel = new ProjectDetailsView(); 5.93 populate(viewModel, pathParams, dao); 5.94 5.95 if (!viewModel.isEveryFilterValid()) { 5.96 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.97 - return ResponseType.NONE; 5.98 + return; 5.99 } 5.100 5.101 final var project = viewModel.getProjectInfo().getProject(); 5.102 @@ -251,18 +251,18 @@ 5.103 if (version.getId() > 0) 5.104 viewModel.getProjectDetails().updateVersionInfo(version); 5.105 5.106 - return forwardView(req, viewModel, "project-details"); 5.107 + forwardView(req, resp, viewModel, "project-details"); 5.108 } 5.109 5.110 @RequestMapping(requestPath = "$project/versions/", method = HttpMethod.GET) 5.111 - public ResponseType versions(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { 5.112 + public void versions(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { 5.113 final var viewModel = new VersionsView(); 5.114 populate(viewModel, pathParameters, dao); 5.115 5.116 final var projectInfo = viewModel.getProjectInfo(); 5.117 if (projectInfo == null) { 5.118 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.119 - return ResponseType.NONE; 5.120 + return; 5.121 } 5.122 5.123 final var issueDao = dao.getIssueDao(); 5.124 @@ -270,48 +270,48 @@ 5.125 for (var issue : issues) issueDao.joinVersionInformation(issue); 5.126 viewModel.update(projectInfo.getVersions(), issues); 5.127 5.128 - return forwardView(req, viewModel, "versions"); 5.129 + forwardView(req, resp, viewModel, "versions"); 5.130 } 5.131 5.132 @RequestMapping(requestPath = "$project/versions/$version/edit", method = HttpMethod.GET) 5.133 - public ResponseType editVersion(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { 5.134 + public void editVersion(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { 5.135 final var viewModel = new VersionEditView(); 5.136 populate(viewModel, pathParameters, dao); 5.137 5.138 if (viewModel.getProjectInfo() == null || viewModel.getVersionFilter() == null) { 5.139 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.140 - return ResponseType.NONE; 5.141 + return; 5.142 } 5.143 5.144 viewModel.setVersion(viewModel.getVersionFilter()); 5.145 5.146 - return forwardView(req, viewModel, "version-form"); 5.147 + forwardView(req, resp, viewModel, "version-form"); 5.148 } 5.149 5.150 @RequestMapping(requestPath = "$project/create-version", method = HttpMethod.GET) 5.151 - public ResponseType createVersion(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { 5.152 + public void createVersion(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { 5.153 final var viewModel = new VersionEditView(); 5.154 populate(viewModel, pathParameters, dao); 5.155 5.156 if (viewModel.getProjectInfo() == null) { 5.157 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.158 - return ResponseType.NONE; 5.159 + return; 5.160 } 5.161 5.162 viewModel.setVersion(new Version(-1)); 5.163 5.164 - return forwardView(req, viewModel, "version-form"); 5.165 + forwardView(req, resp, viewModel, "version-form"); 5.166 } 5.167 5.168 @RequestMapping(requestPath = "commit-version", method = HttpMethod.POST) 5.169 - public ResponseType commitVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { 5.170 + public void commitVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, ServletException { 5.171 5.172 try { 5.173 final var project = dao.getProjectDao().find(getParameter(req, Integer.class, "pid").orElseThrow()); 5.174 if (project == null) { 5.175 // TODO: improve error handling, because not found is not correct for this POST request 5.176 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.177 - return ResponseType.NONE; 5.178 + return; 5.179 } 5.180 final var version = new Version(getParameter(req, Integer.class, "id").orElseThrow()); 5.181 version.setName(getParameter(req, String.class, "name").orElseThrow()); 5.182 @@ -325,74 +325,73 @@ 5.183 5.184 setRedirectLocation(req, "./projects/" + project.getNode() + "/versions/"); 5.185 setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); 5.186 + 5.187 + renderSite(req, resp); 5.188 } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { 5.189 resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); 5.190 // TODO: implement - fix issue #21 5.191 - return ResponseType.NONE; 5.192 } 5.193 - 5.194 - return ResponseType.HTML; 5.195 } 5.196 5.197 @RequestMapping(requestPath = "$project/components/", method = HttpMethod.GET) 5.198 - public ResponseType components(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { 5.199 + public void components(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { 5.200 final var viewModel = new ComponentsView(); 5.201 populate(viewModel, pathParameters, dao); 5.202 5.203 final var projectInfo = viewModel.getProjectInfo(); 5.204 if (projectInfo == null) { 5.205 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.206 - return ResponseType.NONE; 5.207 + return; 5.208 } 5.209 5.210 final var issueDao = dao.getIssueDao(); 5.211 final var issues = issueDao.list(projectInfo.getProject()); 5.212 viewModel.update(projectInfo.getComponents(), issues); 5.213 5.214 - return forwardView(req, viewModel, "components"); 5.215 + forwardView(req, resp, viewModel, "components"); 5.216 } 5.217 5.218 @RequestMapping(requestPath = "$project/components/$component/edit", method = HttpMethod.GET) 5.219 - public ResponseType editComponent(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { 5.220 + public void editComponent(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { 5.221 final var viewModel = new ComponentEditView(); 5.222 populate(viewModel, pathParameters, dao); 5.223 5.224 if (viewModel.getProjectInfo() == null || viewModel.getComponentFilter() == null) { 5.225 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.226 - return ResponseType.NONE; 5.227 + return; 5.228 } 5.229 5.230 viewModel.setComponent(viewModel.getComponentFilter()); 5.231 viewModel.setUsers(dao.getUserDao().list()); 5.232 5.233 - return forwardView(req, viewModel, "component-form"); 5.234 + forwardView(req, resp, viewModel, "component-form"); 5.235 } 5.236 5.237 @RequestMapping(requestPath = "$project/create-component", method = HttpMethod.GET) 5.238 - public ResponseType createComponent(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { 5.239 + public void createComponent(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { 5.240 final var viewModel = new ComponentEditView(); 5.241 populate(viewModel, pathParameters, dao); 5.242 5.243 if (viewModel.getProjectInfo() == null) { 5.244 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.245 - return ResponseType.NONE; 5.246 + return; 5.247 } 5.248 5.249 viewModel.setComponent(new Component(-1)); 5.250 viewModel.setUsers(dao.getUserDao().list()); 5.251 5.252 - return forwardView(req, viewModel, "component-form"); 5.253 + forwardView(req, resp, viewModel, "component-form"); 5.254 } 5.255 5.256 @RequestMapping(requestPath = "commit-component", method = HttpMethod.POST) 5.257 - public ResponseType commitComponent(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { 5.258 + public void commitComponent(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, ServletException { 5.259 5.260 try { 5.261 final var project = dao.getProjectDao().find(getParameter(req, Integer.class, "pid").orElseThrow()); 5.262 if (project == null) { 5.263 // TODO: improve error handling, because not found is not correct for this POST request 5.264 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.265 - return ResponseType.NONE; 5.266 + return; 5.267 } 5.268 final var component = new Component(getParameter(req, Integer.class, "id").orElseThrow()); 5.269 component.setName(getParameter(req, String.class, "name").orElseThrow()); 5.270 @@ -411,13 +410,12 @@ 5.271 5.272 setRedirectLocation(req, "./projects/" + project.getNode() + "/components/"); 5.273 setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); 5.274 + 5.275 + renderSite(req, resp); 5.276 } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { 5.277 resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); 5.278 // TODO: implement - fix issue #21 5.279 - return ResponseType.NONE; 5.280 } 5.281 - 5.282 - return ResponseType.HTML; 5.283 } 5.284 5.285 private void configureIssueEditor(IssueEditView viewModel, Issue issue, DataAccessObjects dao) throws SQLException { 5.286 @@ -430,75 +428,75 @@ 5.287 } 5.288 5.289 @RequestMapping(requestPath = "$project/issues/$issue/view", method = HttpMethod.GET) 5.290 - public ResponseType viewIssue(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { 5.291 + public void viewIssue(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { 5.292 final var viewModel = new IssueDetailView(); 5.293 populate(viewModel, pathParameters, dao); 5.294 5.295 final var projectInfo = viewModel.getProjectInfo(); 5.296 if (projectInfo == null) { 5.297 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.298 - return ResponseType.NONE; 5.299 + return; 5.300 } 5.301 5.302 final var issueDao = dao.getIssueDao(); 5.303 final var issue = issueDao.find(Functions.parseIntOrZero(pathParameters.get("issue"))); 5.304 if (issue == null) { 5.305 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.306 - return ResponseType.NONE; 5.307 + return; 5.308 } 5.309 5.310 issueDao.joinVersionInformation(issue); 5.311 viewModel.setIssue(issue); 5.312 viewModel.setComments(issueDao.listComments(issue)); 5.313 5.314 - return forwardView(req, viewModel, "issue-view"); 5.315 + forwardView(req, resp, viewModel, "issue-view"); 5.316 } 5.317 5.318 // TODO: why should the issue editor be child of $project? 5.319 @RequestMapping(requestPath = "$project/issues/$issue/edit", method = HttpMethod.GET) 5.320 - public ResponseType editIssue(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { 5.321 + public void editIssue(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { 5.322 final var viewModel = new IssueEditView(); 5.323 populate(viewModel, pathParameters, dao); 5.324 5.325 final var projectInfo = viewModel.getProjectInfo(); 5.326 if (projectInfo == null) { 5.327 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.328 - return ResponseType.NONE; 5.329 + return; 5.330 } 5.331 5.332 final var issueDao = dao.getIssueDao(); 5.333 final var issue = issueDao.find(Functions.parseIntOrZero(pathParameters.get("issue"))); 5.334 if (issue == null) { 5.335 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.336 - return ResponseType.NONE; 5.337 + return; 5.338 } 5.339 5.340 issueDao.joinVersionInformation(issue); 5.341 configureIssueEditor(viewModel, issue, dao); 5.342 5.343 - return forwardView(req, viewModel, "issue-form"); 5.344 + forwardView(req, resp, viewModel, "issue-form"); 5.345 } 5.346 5.347 @RequestMapping(requestPath = "$project/create-issue", method = HttpMethod.GET) 5.348 - public ResponseType createIssue(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { 5.349 + public void createIssue(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { 5.350 final var viewModel = new IssueEditView(); 5.351 populate(viewModel, pathParameters, dao); 5.352 5.353 final var projectInfo = viewModel.getProjectInfo(); 5.354 if (projectInfo == null) { 5.355 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.356 - return ResponseType.NONE; 5.357 + return; 5.358 } 5.359 5.360 final var issue = new Issue(-1); 5.361 issue.setProject(projectInfo.getProject()); 5.362 configureIssueEditor(viewModel, issue, dao); 5.363 5.364 - return forwardView(req, viewModel, "issue-form"); 5.365 + forwardView(req, resp, viewModel, "issue-form"); 5.366 } 5.367 5.368 @RequestMapping(requestPath = "commit-issue", method = HttpMethod.POST) 5.369 - public ResponseType commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { 5.370 + public void commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, ServletException { 5.371 try { 5.372 final var issue = new Issue(getParameter(req, Integer.class, "id").orElseThrow()); 5.373 final var componentId = getParameter(req, Integer.class, "component"); 5.374 @@ -512,7 +510,7 @@ 5.375 if (project == null) { 5.376 // TODO: improve error handling, because not found is not correct for this POST request 5.377 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.378 - return ResponseType.NONE; 5.379 + return; 5.380 } 5.381 issue.setProject(project); 5.382 getParameter(req, String.class, "category").map(IssueCategory::valueOf).ifPresent(issue::setCategory); 5.383 @@ -549,25 +547,24 @@ 5.384 setRedirectLocation(req, "./projects/" + issue.getProject().getNode()+"/issues/"+issue.getId()+"/view"); 5.385 setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); 5.386 5.387 - return ResponseType.HTML; 5.388 + renderSite(req, resp); 5.389 } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { 5.390 resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); 5.391 // TODO: implement - fix issue #21 5.392 - return ResponseType.NONE; 5.393 } 5.394 } 5.395 5.396 @RequestMapping(requestPath = "commit-issue-comment", method = HttpMethod.POST) 5.397 - public ResponseType commentIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, IOException { 5.398 + public void commentIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, IOException, ServletException { 5.399 final var issueIdParam = getParameter(req, Integer.class, "issueid"); 5.400 if (issueIdParam.isEmpty()) { 5.401 resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Detected manipulated form."); 5.402 - return ResponseType.NONE; 5.403 + return; 5.404 } 5.405 final var issue = dao.getIssueDao().find(issueIdParam.get()); 5.406 if (issue == null) { 5.407 resp.sendError(HttpServletResponse.SC_NOT_FOUND); 5.408 - return ResponseType.NONE; 5.409 + return; 5.410 } 5.411 try { 5.412 final var issueComment = new IssueComment(getParameter(req, Integer.class, "commentid").orElse(-1)); 5.413 @@ -588,11 +585,10 @@ 5.414 setRedirectLocation(req, "./projects/" + issue.getProject().getNode()+"/issues/"+issue.getId()+"/view"); 5.415 setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); 5.416 5.417 - return ResponseType.HTML; 5.418 + renderSite(req, resp); 5.419 } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { 5.420 resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); 5.421 // TODO: implement - fix issue #21 5.422 - return ResponseType.NONE; 5.423 } 5.424 } 5.425 }
6.1 --- a/src/main/java/de/uapcore/lightpit/modules/UsersModule.java Sat Oct 31 10:54:20 2020 +0100 6.2 +++ b/src/main/java/de/uapcore/lightpit/modules/UsersModule.java Thu Nov 05 13:37:48 2020 +0100 6.3 @@ -28,8 +28,10 @@ 6.4 */ 6.5 package de.uapcore.lightpit.modules; 6.6 6.7 - 6.8 -import de.uapcore.lightpit.*; 6.9 +import de.uapcore.lightpit.AbstractLightPITServlet; 6.10 +import de.uapcore.lightpit.Constants; 6.11 +import de.uapcore.lightpit.HttpMethod; 6.12 +import de.uapcore.lightpit.RequestMapping; 6.13 import de.uapcore.lightpit.dao.DataAccessObjects; 6.14 import de.uapcore.lightpit.entities.User; 6.15 import de.uapcore.lightpit.viewmodel.UsersEditView; 6.16 @@ -37,8 +39,11 @@ 6.17 import org.slf4j.Logger; 6.18 import org.slf4j.LoggerFactory; 6.19 6.20 +import javax.servlet.ServletException; 6.21 import javax.servlet.annotation.WebServlet; 6.22 import javax.servlet.http.HttpServletRequest; 6.23 +import javax.servlet.http.HttpServletResponse; 6.24 +import java.io.IOException; 6.25 import java.sql.SQLException; 6.26 import java.util.NoSuchElementException; 6.27 6.28 @@ -56,7 +61,7 @@ 6.29 } 6.30 6.31 @RequestMapping(method = HttpMethod.GET) 6.32 - public ResponseType index(HttpServletRequest req, DataAccessObjects dao) throws SQLException { 6.33 + public void index(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, ServletException, IOException { 6.34 final var userDao = dao.getUserDao(); 6.35 6.36 final var viewModel = new UsersView(); 6.37 @@ -64,11 +69,11 @@ 6.38 setViewModel(req, viewModel); 6.39 setContentPage(req, "users"); 6.40 6.41 - return ResponseType.HTML; 6.42 + renderSite(req, resp); 6.43 } 6.44 6.45 @RequestMapping(requestPath = "edit", method = HttpMethod.GET) 6.46 - public ResponseType edit(HttpServletRequest req, DataAccessObjects dao) throws SQLException { 6.47 + public void edit(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, ServletException, IOException { 6.48 6.49 final var viewModel = new UsersEditView(); 6.50 viewModel.setUser(findByParameter(req, Integer.class, "id", 6.51 @@ -77,11 +82,11 @@ 6.52 setViewModel(req, viewModel); 6.53 setContentPage(req, "user-form"); 6.54 6.55 - return ResponseType.HTML; 6.56 + renderSite(req, resp); 6.57 } 6.58 6.59 @RequestMapping(requestPath = "commit", method = HttpMethod.POST) 6.60 - public ResponseType commit(HttpServletRequest req, DataAccessObjects dao) { 6.61 + public void commit(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws ServletException, IOException { 6.62 6.63 User user = new User(-1); 6.64 try { 6.65 @@ -107,6 +112,6 @@ 6.66 LOG.debug("Details:", ex); 6.67 } 6.68 6.69 - return ResponseType.HTML; 6.70 + renderSite(req, resp); 6.71 } 6.72 }