Class RequestProcessor

    • Constructor Detail

      • RequestProcessor

        public RequestProcessor​(Socket request)
        Constructor
        Parameters:
        request - A socket to read the request.
    • Method Detail

      • processRequest

        public static void processRequest​(Socket request)
        Spawns a new thread for the request
        Parameters:
        request - The request to process
      • addRequestHandlerClass

        public static void addRequestHandlerClass​(String command,
                                                  Class<? extends RequestHandler> handler)
        Add external request handler. Can be used by other plug-ins that want to use remote control.
        Parameters:
        command - The command to handle.
        handler - The additional request handler.
      • addRequestHandlerClass

        private static void addRequestHandlerClass​(String command,
                                                   Class<? extends RequestHandler> handler,
                                                   boolean silent)
        Add external request handler. Message can be suppressed. (for internal use)
        Parameters:
        command - The command to handle.
        handler - The additional request handler.
        silent - Don't show message if true.
      • initialize

        public static void initialize()
        Force the class to initialize and load the handlers
      • run

        public void run()
        The work is done here.
        Specified by:
        run in interface Runnable
        Overrides:
        run in class Thread
      • sendInternalError

        private static void sendInternalError​(Writer out,
                                              String help)
                                       throws IOException
        Sends a 500 error: internal server error
        Parameters:
        out - The writer where the error is written
        help - Optional HTML help content to display, can be null
        Throws:
        IOException - If the error can not be written
      • sendNotImplemented

        private static void sendNotImplemented​(Writer out)
                                        throws IOException
        Sends a 501 error: not implemented
        Parameters:
        out - The writer where the error is written
        Throws:
        IOException - If the error can not be written
      • sendBadGateway

        private static void sendBadGateway​(Writer out,
                                           String help)
                                    throws IOException
        Sends a 502 error: bad gateway
        Parameters:
        out - The writer where the error is written
        help - Optional HTML help content to display, can be null
        Throws:
        IOException - If the error can not be written
      • sendForbidden

        private static void sendForbidden​(Writer out,
                                          String help)
                                   throws IOException
        Sends a 403 error: forbidden
        Parameters:
        out - The writer where the error is written
        help - Optional HTML help content to display, can be null
        Throws:
        IOException - If the error can not be written
      • sendBadRequest

        private static void sendBadRequest​(Writer out,
                                           String help)
                                    throws IOException
        Sends a 400 error: bad request
        Parameters:
        out - The writer where the error is written
        help - Optional help content to display, can be null
        Throws:
        IOException - If the error can not be written
      • sendHeader

        private static void sendHeader​(Writer out,
                                       String status,
                                       String contentType,
                                       boolean endHeaders)
                                throws IOException
        Send common HTTP headers to the client.
        Parameters:
        out - The Writer
        status - The status string ("200 OK", "500", etc)
        contentType - The content type of the data sent
        endHeaders - If true, adds a new line, ending the headers.
        Throws:
        IOException - When error
      • getHandlersInfo

        public static Stream<RequestHandlergetHandlersInfo​(Collection<String> handlers)
        Returns the information for the given (if null: all) handlers.
        Parameters:
        handlers - the handlers
        Returns:
        the information for the given (if null: all) handlers
      • getHandlerInfo

        public static RequestHandler getHandlerInfo​(String cmd)
        Returns the information for a given handler.
        Parameters:
        cmd - handler key
        Returns:
        the information for the given handler