public class RequestProcessor extends Thread
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
private static Map<String,Class<? extends RequestHandler>> |
handlers
Collection of request handlers.
|
static String |
PROTOCOLVERSION
RemoteControl protocol version.
|
private Socket |
request
The socket this processor listens on
|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
RequestProcessor(Socket request)
Constructor
|
Modifier and Type | Method and Description |
---|---|
(package private) static void |
addRequestHandlerClass(String command,
Class<? extends RequestHandler> handler)
Add external request handler.
|
private static void |
addRequestHandlerClass(String command,
Class<? extends RequestHandler> handler,
boolean silent)
Add external request handler.
|
static String |
getHandlerInfoAsJSON(String cmd) |
static String |
getHandlersInfoAsJSON() |
static String |
getUsageAsHtml()
Reports HTML message with the description of all available commands
|
private static void |
printJsonInfo(String cmd,
PrintWriter r,
RequestHandler handler) |
static void |
processRequest(Socket request)
Spawns a new thread for the request
|
void |
run()
The work is done here.
|
private void |
sendBadRequest(Writer out,
String help)
Sends a 403 error: forbidden
|
private void |
sendError(Writer out)
Sends a 500 error: server error
|
private void |
sendForbidden(Writer out,
String help)
Sends a 403 error: forbidden
|
private void |
sendHeader(Writer out,
String status,
String contentType,
boolean endHeaders)
Send common HTTP headers to the client.
|
private void |
sendNotImplemented(Writer out)
Sends a 501 error: not implemented
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public static final String PROTOCOLVERSION
private static Map<String,Class<? extends RequestHandler>> handlers
public RequestProcessor(Socket request)
request
- A socket to read the request.public static void processRequest(Socket request)
request
- The request to processstatic void addRequestHandlerClass(String command, Class<? extends RequestHandler> handler)
command
- The command to handle.handler
- The additional request handler.private static void addRequestHandlerClass(String command, Class<? extends RequestHandler> handler, boolean silent)
command
- The command to handle.handler
- The additional request handler.silent
- Don't show message if true.public void run()
private void sendError(Writer out) throws IOException
out
- The writer where the error is writtenIOException
- If the error can not be writtenprivate void sendNotImplemented(Writer out) throws IOException
out
- The writer where the error is writtenIOException
- If the error can not be writtenprivate void sendForbidden(Writer out, String help) throws IOException
out
- The writer where the error is writtenIOException
- If the error can not be writtenprivate void sendBadRequest(Writer out, String help) throws IOException
out
- The writer where the error is writtenIOException
- If the error can not be writtenprivate void sendHeader(Writer out, String status, String contentType, boolean endHeaders) throws IOException
out
- The Writerstatus
- The status string ("200 OK", "500", etc)contentType
- The content type of the data sentendHeaders
- If true, adds a new line, ending the headers.IOException
- When errorpublic static String getHandlersInfoAsJSON()
public static String getHandlerInfoAsJSON(String cmd)
private static void printJsonInfo(String cmd, PrintWriter r, RequestHandler handler)
public static String getUsageAsHtml() throws IllegalAccessException, InstantiationException
IllegalAccessException
InstantiationException