Class BaseHandler

Direct Known Subclasses:
TestHandler

public abstract class BaseHandler extends RequestHandler
A base handler class that eliminates the need for boilerplate constructors. Developers can simply extend this class without having to create a constructor that passes request and response objects to the parent class.
  • Constructor Details

    • BaseHandler

      public BaseHandler()
      Default constructor that passes null request and response objects. These will be set later by the HandlerPool when the handler is acquired.
    • BaseHandler

      public BaseHandler(Request req, Response res)
      Constructor with request and response objects. This is used internally by the framework.
  • Method Details

    • initialize

      protected void initialize()
      Initialize method that's called after request and response are set. Override this method instead of creating a constructor.
    • setRequestResponse

      public void setRequestResponse(Request req, Response res)
      Description copied from class: RequestHandler
      Set the request and response objects
      Overrides:
      setRequestResponse in class RequestHandler
      Parameters:
      req - The request object
      res - The response object
    • handle

      public final Object handle()
      The main handle method that processes the request. This implementation calls the process method and then either returns the result or calls the resolve method.
      Specified by:
      handle in class RequestHandler
      Returns:
      The response object
    • process

      protected void process()
      Process method that should be implemented by handler classes. This is where validation and middleware-like logic should be placed. By default, it just continues to the next step.
    • resolve

      protected Object resolve()
      Handle implementation method that should be implemented by concrete handlers. This is where the final handler logic should be placed.
    • next

      protected final void next()
      Continues processing to the next step. This should be called when the current processing is successful.
    • fail

      protected final void fail(String message, int status)
      Fails the request with a custom message and status code. This should be called when an error condition is detected.
      Parameters:
      message - The error message
      status - The HTTP status code
    • fail

      protected final void fail(String message)
      Fails the request with a custom message and default 400 status code.
      Parameters:
      message - The error message
    • complete

      protected final void complete(Object customResult)
      Completes the request with a custom result. This should be called when you want to return a result without continuing to the next step.
      Parameters:
      customResult - The result to return