Class LocalHttpHandler

java.lang.Object
com.amalgamasimulation.studies.headlessapp.http.LocalHttpHandler
All Implemented Interfaces:
HttpHandler

public abstract class LocalHttpHandler extends Object implements HttpHandler
  • Field Details

  • Constructor Details

  • Method Details

    • expectedMethod

      protected abstract HttpMethod expectedMethod()
      Returns the HTTP method that must be used in requests processed by this HTTP handler.
    • prepareResponse

      protected abstract HttpResponse prepareResponse(HttpExchange exchange)
      This method should process the request and then prepare and return (but not send!) the response.
    • handle

      public final void handle(HttpExchange exchange) throws IOException
      Specified by:
      handle in interface HttpHandler
      Throws:
      IOException
    • getCorrIDLogMessagePrefix

      protected static String getCorrIDLogMessagePrefix(HttpExchange exchange)
    • logRequest

      protected void logRequest(HttpExchange t)
    • beforeHandle

      protected boolean beforeHandle(HttpExchange t) throws IOException
      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