Interface ResponseHandler

All Known Implementing Classes:
DefaultResponseHandler

public interface ResponseHandler
Contract for writing an HTTP response.

Implementors should use handleResponse(HttpServletRequest, HttpServletResponse, Optional, Optional, Optional) to write an appropriate HTTP response body, content type, and any relevant headers.

Since:
1.0.0
Author:
Mark Allen
  • Method Details

    • handleResponse

      void handleResponse(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Optional<Route> route, Optional<Object> response, Optional<Exception> exception) throws IOException
      Determines and writes an appropriate response for the client based on RequestHandler output.

      Optionals are as follows:

      • route: The route matching the request. Empty if no matching method was found for the request URL (normally you'll want to return a 404 in this case)
      • response: The return value of the method invoked to handle this request. Empty if the method is declared as void or returned null
      • exception: The exception that occurred during request processing. Empty if no exception occurred
      Parameters:
      httpServletRequest - Servlet request
      httpServletResponse - Servlet response
      route - The route that matched this request (if any)
      response - The result of the resourceMethod invocation (if any)
      exception - The exception that occurred when attempting to handle the request (if any)
      Throws:
      IOException - If an error occurs while writing the response