Package com.pixelservices.flash.models
Class BaseHandler
java.lang.Object
com.pixelservices.flash.components.http.RequestHandler
com.pixelservices.flash.models.BaseHandler
- Direct Known Subclasses:
TestHandler
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.
-
Field Summary
Fields inherited from class com.pixelservices.flash.components.http.RequestHandler
expectedBodyFields, expectedBodyFiles, expectedRequestParameters, req, res
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor that passes null request and response objects.BaseHandler
(Request req, Response res) Constructor with request and response objects. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
Completes the request with a custom result.protected final void
Fails the request with a custom message and default 400 status code.protected final void
Fails the request with a custom message and status code.final Object
handle()
The main handle method that processes the request.protected void
Initialize method that's called after request and response are set.protected final void
next()
Continues processing to the next step.protected void
process()
Process method that should be implemented by handler classes.protected Object
resolve()
Handle implementation method that should be implemented by concrete handlers.void
setRequestResponse
(Request req, Response res) Set the request and response objectsMethods inherited from class com.pixelservices.flash.components.http.RequestHandler
expectedBodyField, expectedBodyField, expectedBodyFile, expectedBodyFile, expectedRequestParameter, expectedRequestParameter, getExpectedBodyFields, getExpectedBodyFiles, getExpectedRequestParameters, getHandlerName, getHandlerType, getRequest, getRequestBody, getRequestBody, getResponse, getRouteParameters, getSpecification, isEnforcedNonNullBody, setHandlerType, setSpecification
-
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
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
Description copied from class:RequestHandler
Set the request and response objects- Overrides:
setRequestResponse
in classRequestHandler
- Parameters:
req
- The request objectres
- The response 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 classRequestHandler
- 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
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
Fails the request with a custom message and status code. This should be called when an error condition is detected.- Parameters:
message
- The error messagestatus
- The HTTP status code
-
fail
Fails the request with a custom message and default 400 status code.- Parameters:
message
- The error message
-
complete
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
-