Class LocalHttpHandler
java.lang.Object
com.amalgamasimulation.studies.headlessapp.http.LocalHttpHandler
- All Implemented Interfaces:
HttpHandler
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanPerforms a set of checks that should be run before handling a HTTP request.protected abstract HttpMethodReturns the HTTP method that must be used in requests processed by this HTTP handler.protected static StringgetCorrIDLogMessagePrefix(HttpExchange exchange) final voidhandle(HttpExchange exchange) protected voidprotected abstract HttpResponseprepareResponse(HttpExchange exchange) This method should process the request and then prepare and return (but not send!) the response.protected static voidwriteResponse(HttpExchange t, int httpResultCode, String response) protected static voidwriteResponseJSON(HttpExchange t, int httpResultCode, String responseJSON) protected static voidwriteResponseJSON(HttpExchange exchange, HttpResponse response) protected static voidwriteResponseMessage(HttpExchange t, int httpResultCode, String response) Writes a HTTP response as a single-field JSON object.
-
Field Details
-
server
-
-
Constructor Details
-
LocalHttpHandler
-
-
Method Details
-
expectedMethod
Returns the HTTP method that must be used in requests processed by this HTTP handler. -
prepareResponse
This method should process the request and then prepare and return (but not send!) the response. -
handle
- Specified by:
handlein interfaceHttpHandler- Throws:
IOException
-
getCorrIDLogMessagePrefix
-
logRequest
-
beforeHandle
Performs a set of checks that should be run before handling a HTTP request. Returns true if checks were successful.This method must be called in the beginning of the 'handle()' method in each subclass. If this method returns false, the rest of the 'handle()' method should not be run.
- Throws:
IOException
-
writeResponseMessage
protected static void writeResponseMessage(HttpExchange t, int httpResultCode, String response) throws IOException Writes a HTTP response as a single-field JSON object. The field's name is "message" and its value is the 'response' method parameter.- Throws:
IOException
-
writeResponseJSON
protected static void writeResponseJSON(HttpExchange t, int httpResultCode, String responseJSON) throws IOException - Throws:
IOException
-
writeResponse
protected static void writeResponse(HttpExchange t, int httpResultCode, String response) throws IOException - Throws:
IOException
-
writeResponseJSON
protected static void writeResponseJSON(HttpExchange exchange, HttpResponse response) throws IOException - Throws:
IOException
-