Class MethodeBasedHandler
java.lang.Object
com.ns.tcpframework.reqeustHandlers.RequestHandler
com.ns.tcpframework.reqeustHandlers.MethodeBasedHandler
- Direct Known Subclasses:
HelloWorldHandler, StaticFileHandler
Abstract base class for handling HTTP requests.
This class uses the Template Method design pattern to define the structure of request handling.
Subclasses can override specific HTTP method handlers (GET, POST, PUT, DELETE) as needed.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionhandle(HTTPRequest request) Handles an HTTP request by routing it to the appropriate method based on the HTTP method.protected HTTPResponsehandleDeleteRequest(HTTPRequest request) Handles HTTP DELETE requests.protected HTTPResponsehandleGetRequest(HTTPRequest request) Handles HTTP GET requests.protected HTTPResponsehandleHeadRequest(HTTPRequest request) Handles HTTP HEAD requests.protected HTTPResponsehandlePostRequest(HTTPRequest request) Handles HTTP POST requests.protected HTTPResponsehandlePutRequest(HTTPRequest request) Handles HTTP PUT requests.Methods inherited from class RequestHandler
handle
-
Constructor Details
-
MethodeBasedHandler
public MethodeBasedHandler()
-
-
Method Details
-
handle
Handles an HTTP request by routing it to the appropriate method based on the HTTP method.- Specified by:
handlein classRequestHandler- Parameters:
request- The HTTP request to handle.- Returns:
- An HTTPResponse object containing the response to be sent to the client.
- Throws:
Exception- If an error occurs during request handling.
-
handleGetRequest
Handles HTTP GET requests. Subclasses should override this method to provide specific GET request handling logic.- Parameters:
request- The HTTP request to handle.- Returns:
- An HTTPResponse object containing the status code, headers, and body to send to the client.
- Throws:
Exception- If the method is not implemented or an error occurs.
-
handlePostRequest
Handles HTTP POST requests. Subclasses should override this method to provide specific POST request handling logic.- Parameters:
request- The HTTP request to handle.- Returns:
- An HTTPResponse object containing the status code, headers, and body to send to the client.
- Throws:
Exception- If the method is not implemented or an error occurs.
-
handlePutRequest
Handles HTTP PUT requests. Subclasses should override this method to provide specific PUT request handling logic.- Parameters:
request- The HTTP request to handle.- Returns:
- An HTTPResponse object containing the status code, headers, and body to send to the client.
- Throws:
Exception- If the method is not implemented or an error occurs.
-
handleDeleteRequest
Handles HTTP DELETE requests. Subclasses should override this method to provide specific DELETE request handling logic.- Parameters:
request- The HTTP request to handle.- Returns:
- An HTTPResponse object containing the status code, headers, and body to send to the client.
- Throws:
Exception- If the method is not implemented or an error occurs.
-
handleHeadRequest
Handles HTTP HEAD requests. Subclasses should override this method to provide specific HEAD request handling logic.- Parameters:
request- The HTTP request to handle.- Returns:
- An HTTPResponse object containing the status code and headers to send to the client (no body).
- Throws:
Exception- If the method is not implemented or an error occurs.
-