Class DefaultRouteProviderContextHandler

java.lang.Object
com.kingsrook.qqq.middleware.javalin.routeproviders.contexthandlers.DefaultRouteProviderContextHandler
All Implemented Interfaces:
RouteProviderContextHandlerInterface

public class DefaultRouteProviderContextHandler extends Object implements RouteProviderContextHandlerInterface
Default implementation of RouteProviderContextHandlerInterface. Handles the bidirectional mapping between Javalin HTTP context and QQQ process input/output for ProcessBasedRouter routes. Request Handling: - Extracts path, method, path params, query params, cookies, and headers - Reads request body as string or form parameters - Populates RunProcessInput with these values Response Handling: - Sets HTTP status code and response headers - Handles redirects via redirectURL - Sends response body as string, bytes, or stream (via StorageInput) This implementation reads the entire request body as a string, which works for most use cases but may not be suitable for large file uploads. For those cases, extend this class and override handleRequestBody().
  • Constructor Details

    • DefaultRouteProviderContextHandler

      public DefaultRouteProviderContextHandler()
  • Method Details

    • handleRequest

      public void handleRequest(io.javalin.http.Context context, RunProcessInput input)
      Extract request data from Javalin context and populate process input. Populates the RunProcessInput with path, method, params, cookies, headers, and body content that the process can access.
      Specified by:
      handleRequest in interface RouteProviderContextHandlerInterface
      Parameters:
      context - the Javalin HTTP context
      input - the process input to populate
    • handleRequestBody

      protected void handleRequestBody(io.javalin.http.Context context, RunProcessInput input)
      Extract request body content and add to process input. Default implementation reads form parameters and body as a string. Override this method for custom body handling (e.g., multipart file uploads).
      Parameters:
      context - the Javalin HTTP context
      input - the process input to populate
    • handleResponse

      public boolean handleResponse(io.javalin.http.Context context, RunProcessOutput runProcessOutput) throws QException
      Build HTTP response from process output. Handles status codes, redirects, headers, and response body from the process output. Supports string responses, byte array responses, and streaming responses via StorageInput.
      Specified by:
      handleResponse in interface RouteProviderContextHandlerInterface
      Parameters:
      context - the Javalin HTTP context
      runProcessOutput - the process output containing response data
      Returns:
      true if response was handled; false otherwise
      Throws:
      QException - if response processing fails
    • handleResponseHeaders

      protected void handleResponseHeaders(io.javalin.http.Context context, RunProcessOutput runProcessOutput)
      Extract response headers from process output and set on HTTP response.
      Parameters:
      context - the Javalin HTTP context
      runProcessOutput - the process output containing response headers
    • handleResponseBody

      protected boolean handleResponseBody(io.javalin.http.Context context, RunProcessOutput runProcessOutput) throws QException
      Extract response body from process output and write to HTTP response. Checks for responseString, responseBytes, or responseStorageInput in the process output and sends the appropriate content type. Returns true if a response body was found and sent.
      Parameters:
      context - the Javalin HTTP context
      runProcessOutput - the process output containing response body
      Returns:
      true if response body was sent; false if no body content found
      Throws:
      QException - if response body processing fails