Thu, 05 Nov 2020 13:37:48 +0100
removes ResponseType enum
--- 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); }
--- a/src/main/java/de/uapcore/lightpit/ResponseType.java Sat Oct 31 10:54:20 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2018 Mike Becker. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, 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. - * - */ -package de.uapcore.lightpit; - - -public enum ResponseType { - /** - * Renders a full HTML view including the header. - */ - HTML, - /** - * Renders a HTML fragment only. - * May be used for AJAX responses. - */ - HTML_FRAGMENT, - /** - * Returns a fragment with content type 'text/plain'. - */ - PLAIN, - /** - * Returns an object in JSON format and with content type - * 'application/json'. - */ - JSON, - /** - * The handler already sent the output, nothing should be done - * additionally by the Servlet. - */ - NONE -}
--- a/src/main/java/de/uapcore/lightpit/modules/ErrorModule.java Sat Oct 31 10:54:20 2020 +0100 +++ b/src/main/java/de/uapcore/lightpit/modules/ErrorModule.java Thu Nov 05 13:37:48 2020 +0100 @@ -31,11 +31,12 @@ import de.uapcore.lightpit.AbstractLightPITServlet; import de.uapcore.lightpit.HttpMethod; import de.uapcore.lightpit.RequestMapping; -import de.uapcore.lightpit.ResponseType; +import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.Optional; @WebServlet( @@ -52,7 +53,7 @@ } @RequestMapping(requestPath = "generic", method = HttpMethod.GET) - public ResponseType onError(HttpServletRequest req, HttpServletResponse resp) { + public void onError(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Optional.ofNullable(req.getHeader("Referer")).ifPresent( referer -> req.setAttribute(REQ_ATTR_RETURN_LINK, referer) ); @@ -60,6 +61,6 @@ setStylesheet(req, "error"); setContentPage(req, "error"); - return ResponseType.HTML; + renderSite(req, resp); } }
--- a/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java Sat Oct 31 10:54:20 2020 +0100 +++ b/src/main/java/de/uapcore/lightpit/modules/LanguageModule.java Thu Nov 05 13:37:48 2020 +0100 @@ -37,6 +37,7 @@ import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.*; @WebServlet( @@ -85,7 +86,7 @@ } @RequestMapping(method = HttpMethod.GET) - public ResponseType handle(HttpServletRequest req) { + public void handle(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final var viewModel = new LanguageView(); viewModel.setLanguages(languages); @@ -95,11 +96,12 @@ setViewModel(req, viewModel); setStylesheet(req, "language"); setContentPage(req, "language"); - return ResponseType.HTML; + + renderSite(req, resp); } @RequestMapping(method = HttpMethod.POST) - public ResponseType switchLanguage(HttpServletRequest req, HttpServletResponse resp) { + public void switchLanguage(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Optional<Locale> chosenLanguage = Optional.ofNullable(req.getParameter("language")) .map(Locale::forLanguageTag) @@ -108,6 +110,6 @@ chosenLanguage.ifPresent((l) -> req.getSession().setAttribute(Constants.SESSION_ATTR_LANGUAGE, l)); chosenLanguage.ifPresent(resp::setLocale); - return handle(req); + handle(req, resp); } }
--- a/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java Sat Oct 31 10:54:20 2020 +0100 +++ b/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java Thu Nov 05 13:37:48 2020 +0100 @@ -38,6 +38,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -115,16 +116,16 @@ } } - private ResponseType forwardView(HttpServletRequest req, ProjectView viewModel, String name) { + private void forwardView(HttpServletRequest req, HttpServletResponse resp, ProjectView viewModel, String name) throws ServletException, IOException { setViewModel(req, viewModel); setContentPage(req, name); setStylesheet(req, "projects"); setNavigationMenu(req, "project-navmenu"); - return ResponseType.HTML; + renderSite(req, resp); } @RequestMapping(method = HttpMethod.GET) - public ResponseType index(HttpServletRequest req, DataAccessObjects dao) throws SQLException { + public void index(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, ServletException, IOException { final var viewModel = new ProjectView(); populate(viewModel, null, dao); @@ -136,7 +137,7 @@ info.setIssueSummary(projectDao.getIssueSummary(info.getProject())); } - return forwardView(req, viewModel, "projects"); + forwardView(req, resp, viewModel, "projects"); } private void configureProjectEditor(ProjectEditView viewModel, Project project, DataAccessObjects dao) throws SQLException { @@ -145,29 +146,29 @@ } @RequestMapping(requestPath = "$project/edit", method = HttpMethod.GET) - public ResponseType edit(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParams, DataAccessObjects dao) throws IOException, SQLException { + public void edit(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParams, DataAccessObjects dao) throws IOException, SQLException, ServletException { final var viewModel = new ProjectEditView(); populate(viewModel, pathParams, dao); if (!viewModel.isProjectInfoPresent()) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } configureProjectEditor(viewModel, viewModel.getProjectInfo().getProject(), dao); - return forwardView(req, viewModel, "project-form"); + forwardView(req, resp, viewModel, "project-form"); } @RequestMapping(requestPath = "create", method = HttpMethod.GET) - public ResponseType create(HttpServletRequest req, DataAccessObjects dao) throws SQLException { + public void create(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, ServletException, IOException { final var viewModel = new ProjectEditView(); populate(viewModel, null, dao); configureProjectEditor(viewModel, new Project(-1), dao); - return forwardView(req, viewModel, "project-form"); + forwardView(req, resp, viewModel, "project-form"); } @RequestMapping(requestPath = "commit", method = HttpMethod.POST) - public ResponseType commit(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { + public void commit(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, ServletException { try { final var project = new Project(getParameter(req, Integer.class, "pid").orElseThrow()); @@ -188,22 +189,21 @@ setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); LOG.debug("Successfully updated project {}", project.getName()); - return ResponseType.HTML; + renderSite(req, resp); } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); // TODO: implement - fix issue #21 - return ResponseType.NONE; } } @RequestMapping(requestPath = "$project/$component/$version/issues/", method = HttpMethod.GET) - public ResponseType issues(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParams, DataAccessObjects dao) throws SQLException, IOException { + public void issues(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParams, DataAccessObjects dao) throws SQLException, IOException, ServletException { final var viewModel = new ProjectDetailsView(); populate(viewModel, pathParams, dao); if (!viewModel.isEveryFilterValid()) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } final var project = viewModel.getProjectInfo().getProject(); @@ -251,18 +251,18 @@ if (version.getId() > 0) viewModel.getProjectDetails().updateVersionInfo(version); - return forwardView(req, viewModel, "project-details"); + forwardView(req, resp, viewModel, "project-details"); } @RequestMapping(requestPath = "$project/versions/", method = HttpMethod.GET) - public ResponseType versions(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { + public void versions(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { final var viewModel = new VersionsView(); populate(viewModel, pathParameters, dao); final var projectInfo = viewModel.getProjectInfo(); if (projectInfo == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } final var issueDao = dao.getIssueDao(); @@ -270,48 +270,48 @@ for (var issue : issues) issueDao.joinVersionInformation(issue); viewModel.update(projectInfo.getVersions(), issues); - return forwardView(req, viewModel, "versions"); + forwardView(req, resp, viewModel, "versions"); } @RequestMapping(requestPath = "$project/versions/$version/edit", method = HttpMethod.GET) - public ResponseType editVersion(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { + public void editVersion(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { final var viewModel = new VersionEditView(); populate(viewModel, pathParameters, dao); if (viewModel.getProjectInfo() == null || viewModel.getVersionFilter() == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } viewModel.setVersion(viewModel.getVersionFilter()); - return forwardView(req, viewModel, "version-form"); + forwardView(req, resp, viewModel, "version-form"); } @RequestMapping(requestPath = "$project/create-version", method = HttpMethod.GET) - public ResponseType createVersion(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { + public void createVersion(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { final var viewModel = new VersionEditView(); populate(viewModel, pathParameters, dao); if (viewModel.getProjectInfo() == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } viewModel.setVersion(new Version(-1)); - return forwardView(req, viewModel, "version-form"); + forwardView(req, resp, viewModel, "version-form"); } @RequestMapping(requestPath = "commit-version", method = HttpMethod.POST) - public ResponseType commitVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { + public void commitVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, ServletException { try { final var project = dao.getProjectDao().find(getParameter(req, Integer.class, "pid").orElseThrow()); if (project == null) { // TODO: improve error handling, because not found is not correct for this POST request resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } final var version = new Version(getParameter(req, Integer.class, "id").orElseThrow()); version.setName(getParameter(req, String.class, "name").orElseThrow()); @@ -325,74 +325,73 @@ setRedirectLocation(req, "./projects/" + project.getNode() + "/versions/"); setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); + + renderSite(req, resp); } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); // TODO: implement - fix issue #21 - return ResponseType.NONE; } - - return ResponseType.HTML; } @RequestMapping(requestPath = "$project/components/", method = HttpMethod.GET) - public ResponseType components(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { + public void components(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { final var viewModel = new ComponentsView(); populate(viewModel, pathParameters, dao); final var projectInfo = viewModel.getProjectInfo(); if (projectInfo == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } final var issueDao = dao.getIssueDao(); final var issues = issueDao.list(projectInfo.getProject()); viewModel.update(projectInfo.getComponents(), issues); - return forwardView(req, viewModel, "components"); + forwardView(req, resp, viewModel, "components"); } @RequestMapping(requestPath = "$project/components/$component/edit", method = HttpMethod.GET) - public ResponseType editComponent(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { + public void editComponent(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { final var viewModel = new ComponentEditView(); populate(viewModel, pathParameters, dao); if (viewModel.getProjectInfo() == null || viewModel.getComponentFilter() == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } viewModel.setComponent(viewModel.getComponentFilter()); viewModel.setUsers(dao.getUserDao().list()); - return forwardView(req, viewModel, "component-form"); + forwardView(req, resp, viewModel, "component-form"); } @RequestMapping(requestPath = "$project/create-component", method = HttpMethod.GET) - public ResponseType createComponent(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { + public void createComponent(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { final var viewModel = new ComponentEditView(); populate(viewModel, pathParameters, dao); if (viewModel.getProjectInfo() == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } viewModel.setComponent(new Component(-1)); viewModel.setUsers(dao.getUserDao().list()); - return forwardView(req, viewModel, "component-form"); + forwardView(req, resp, viewModel, "component-form"); } @RequestMapping(requestPath = "commit-component", method = HttpMethod.POST) - public ResponseType commitComponent(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { + public void commitComponent(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, ServletException { try { final var project = dao.getProjectDao().find(getParameter(req, Integer.class, "pid").orElseThrow()); if (project == null) { // TODO: improve error handling, because not found is not correct for this POST request resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } final var component = new Component(getParameter(req, Integer.class, "id").orElseThrow()); component.setName(getParameter(req, String.class, "name").orElseThrow()); @@ -411,13 +410,12 @@ setRedirectLocation(req, "./projects/" + project.getNode() + "/components/"); setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); + + renderSite(req, resp); } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); // TODO: implement - fix issue #21 - return ResponseType.NONE; } - - return ResponseType.HTML; } private void configureIssueEditor(IssueEditView viewModel, Issue issue, DataAccessObjects dao) throws SQLException { @@ -430,75 +428,75 @@ } @RequestMapping(requestPath = "$project/issues/$issue/view", method = HttpMethod.GET) - public ResponseType viewIssue(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { + public void viewIssue(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { final var viewModel = new IssueDetailView(); populate(viewModel, pathParameters, dao); final var projectInfo = viewModel.getProjectInfo(); if (projectInfo == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } final var issueDao = dao.getIssueDao(); final var issue = issueDao.find(Functions.parseIntOrZero(pathParameters.get("issue"))); if (issue == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } issueDao.joinVersionInformation(issue); viewModel.setIssue(issue); viewModel.setComments(issueDao.listComments(issue)); - return forwardView(req, viewModel, "issue-view"); + forwardView(req, resp, viewModel, "issue-view"); } // TODO: why should the issue editor be child of $project? @RequestMapping(requestPath = "$project/issues/$issue/edit", method = HttpMethod.GET) - public ResponseType editIssue(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { + public void editIssue(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { final var viewModel = new IssueEditView(); populate(viewModel, pathParameters, dao); final var projectInfo = viewModel.getProjectInfo(); if (projectInfo == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } final var issueDao = dao.getIssueDao(); final var issue = issueDao.find(Functions.parseIntOrZero(pathParameters.get("issue"))); if (issue == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } issueDao.joinVersionInformation(issue); configureIssueEditor(viewModel, issue, dao); - return forwardView(req, viewModel, "issue-form"); + forwardView(req, resp, viewModel, "issue-form"); } @RequestMapping(requestPath = "$project/create-issue", method = HttpMethod.GET) - public ResponseType createIssue(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException { + public void createIssue(HttpServletRequest req, HttpServletResponse resp, PathParameters pathParameters, DataAccessObjects dao) throws IOException, SQLException, ServletException { final var viewModel = new IssueEditView(); populate(viewModel, pathParameters, dao); final var projectInfo = viewModel.getProjectInfo(); if (projectInfo == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } final var issue = new Issue(-1); issue.setProject(projectInfo.getProject()); configureIssueEditor(viewModel, issue, dao); - return forwardView(req, viewModel, "issue-form"); + forwardView(req, resp, viewModel, "issue-form"); } @RequestMapping(requestPath = "commit-issue", method = HttpMethod.POST) - public ResponseType commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException { + public void commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, ServletException { try { final var issue = new Issue(getParameter(req, Integer.class, "id").orElseThrow()); final var componentId = getParameter(req, Integer.class, "component"); @@ -512,7 +510,7 @@ if (project == null) { // TODO: improve error handling, because not found is not correct for this POST request resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } issue.setProject(project); getParameter(req, String.class, "category").map(IssueCategory::valueOf).ifPresent(issue::setCategory); @@ -549,25 +547,24 @@ setRedirectLocation(req, "./projects/" + issue.getProject().getNode()+"/issues/"+issue.getId()+"/view"); setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); - return ResponseType.HTML; + renderSite(req, resp); } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); // TODO: implement - fix issue #21 - return ResponseType.NONE; } } @RequestMapping(requestPath = "commit-issue-comment", method = HttpMethod.POST) - public ResponseType commentIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, IOException { + public void commentIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, IOException, ServletException { final var issueIdParam = getParameter(req, Integer.class, "issueid"); if (issueIdParam.isEmpty()) { resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Detected manipulated form."); - return ResponseType.NONE; + return; } final var issue = dao.getIssueDao().find(issueIdParam.get()); if (issue == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return ResponseType.NONE; + return; } try { final var issueComment = new IssueComment(getParameter(req, Integer.class, "commentid").orElse(-1)); @@ -588,11 +585,10 @@ setRedirectLocation(req, "./projects/" + issue.getProject().getNode()+"/issues/"+issue.getId()+"/view"); setContentPage(req, Constants.JSP_COMMIT_SUCCESSFUL); - return ResponseType.HTML; + renderSite(req, resp); } catch (NoSuchElementException | IllegalArgumentException | SQLException ex) { resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); // TODO: implement - fix issue #21 - return ResponseType.NONE; } } }
--- a/src/main/java/de/uapcore/lightpit/modules/UsersModule.java Sat Oct 31 10:54:20 2020 +0100 +++ b/src/main/java/de/uapcore/lightpit/modules/UsersModule.java Thu Nov 05 13:37:48 2020 +0100 @@ -28,8 +28,10 @@ */ package de.uapcore.lightpit.modules; - -import de.uapcore.lightpit.*; +import de.uapcore.lightpit.AbstractLightPITServlet; +import de.uapcore.lightpit.Constants; +import de.uapcore.lightpit.HttpMethod; +import de.uapcore.lightpit.RequestMapping; import de.uapcore.lightpit.dao.DataAccessObjects; import de.uapcore.lightpit.entities.User; import de.uapcore.lightpit.viewmodel.UsersEditView; @@ -37,8 +39,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.sql.SQLException; import java.util.NoSuchElementException; @@ -56,7 +61,7 @@ } @RequestMapping(method = HttpMethod.GET) - public ResponseType index(HttpServletRequest req, DataAccessObjects dao) throws SQLException { + public void index(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, ServletException, IOException { final var userDao = dao.getUserDao(); final var viewModel = new UsersView(); @@ -64,11 +69,11 @@ setViewModel(req, viewModel); setContentPage(req, "users"); - return ResponseType.HTML; + renderSite(req, resp); } @RequestMapping(requestPath = "edit", method = HttpMethod.GET) - public ResponseType edit(HttpServletRequest req, DataAccessObjects dao) throws SQLException { + public void edit(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws SQLException, ServletException, IOException { final var viewModel = new UsersEditView(); viewModel.setUser(findByParameter(req, Integer.class, "id", @@ -77,11 +82,11 @@ setViewModel(req, viewModel); setContentPage(req, "user-form"); - return ResponseType.HTML; + renderSite(req, resp); } @RequestMapping(requestPath = "commit", method = HttpMethod.POST) - public ResponseType commit(HttpServletRequest req, DataAccessObjects dao) { + public void commit(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws ServletException, IOException { User user = new User(-1); try { @@ -107,6 +112,6 @@ LOG.debug("Details:", ex); } - return ResponseType.HTML; + renderSite(req, resp); } }