package com.perforce.workspace.tjuricek.p4oauth.controllers; import com.perforce.workspace.tjuricek.p4oauth.util.HttpServletRequestHelper; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Optional; /** * Controllers in this application are basic functional objects with the * following interface that basically have a simple lifetime. * <p> * In general, check out one of the handlers. The logic to use a controller * is fairly simple: * <p> * if (controller.matches(request)) { * controller.handle(request, response); * } */ public interface ControllerMethod { /** * If this returns true, assume that this method should probably be called * back. * * @param request The HttpServletRequest to check */ boolean matches(HttpServletRequest request); /** * Executes the controller call, writing out (and closing) the response. * * @param request The HttpServletRequest that should indicate most of our input data * @param response The response object to write out to */ void handle(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException; default String getOrSendError(HttpServletRequestHelper request, String key, HttpServletResponse response) throws IOException { Optional<String> valOpt = request.getParam(key); if (!valOpt.isPresent()) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing required parameter " + key); } return valOpt.orElse(null); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 9095 | tjuricek | Added some basic test data and renamed "workspace" to "workshop" in package name | ||
#1 | 9089 | tjuricek |
Moving some code that worked via some manual validation to the workshop. This just implements a basic code authorization grant scheme. Automated tests are forthcoming, awating some gradle plugin work that should sit outside of this project. |