public class RequestProcessor extends java.lang.Thread
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.String,java.lang.Class<? extends RequestHandler>> |
handlers
Collection of request handlers.
|
static java.lang.String |
PROTOCOLVERSION
RemoteControl protocol version.
|
private java.net.Socket |
request
The socket this processor listens on
|
Constructor and Description |
---|
RequestProcessor(java.net.Socket request)
Constructor
|
Modifier and Type | Method and Description |
---|---|
(package private) static void |
addRequestHandlerClass(java.lang.String command,
java.lang.Class<? extends RequestHandler> handler)
Add external request handler.
|
private static void |
addRequestHandlerClass(java.lang.String command,
java.lang.Class<? extends RequestHandler> handler,
boolean silent)
Add external request handler.
|
static java.lang.String |
getHandlerInfoAsJSON(java.lang.String cmd) |
static java.lang.String |
getHandlersInfoAsJSON() |
static java.lang.String |
getUsageAsHtml()
Reports HTML message with the description of all available commands
|
private static void |
printJsonInfo(java.lang.String cmd,
java.io.PrintWriter r,
RequestHandler handler) |
static void |
processRequest(java.net.Socket request)
Spawns a new thread for the request
|
void |
run()
The work is done here.
|
private void |
sendBadRequest(java.io.Writer out,
java.lang.String help)
Sends a 403 error: forbidden
|
private void |
sendError(java.io.Writer out)
Sends a 500 error: server error
|
private void |
sendForbidden(java.io.Writer out,
java.lang.String help)
Sends a 403 error: forbidden
|
private void |
sendHeader(java.io.Writer out,
java.lang.String status,
java.lang.String contentType,
boolean endHeaders)
Send common HTTP headers to the client.
|
private void |
sendNotImplemented(java.io.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 java.lang.String PROTOCOLVERSION
private java.net.Socket request
private static java.util.Map<java.lang.String,java.lang.Class<? extends RequestHandler>> handlers
public RequestProcessor(java.net.Socket request)
request
- A socket to read the request.public static void processRequest(java.net.Socket request)
request
- The request to processstatic void addRequestHandlerClass(java.lang.String command, java.lang.Class<? extends RequestHandler> handler)
command
- The command to handle.handler
- The additional request handler.private static void addRequestHandlerClass(java.lang.String command, java.lang.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()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
private void sendError(java.io.Writer out) throws java.io.IOException
out
- The writer where the error is writtenjava.io.IOException
- If the error can not be writtenprivate void sendNotImplemented(java.io.Writer out) throws java.io.IOException
out
- The writer where the error is writtenjava.io.IOException
- If the error can not be writtenprivate void sendForbidden(java.io.Writer out, java.lang.String help) throws java.io.IOException
out
- The writer where the error is writtenjava.io.IOException
- If the error can not be writtenprivate void sendBadRequest(java.io.Writer out, java.lang.String help) throws java.io.IOException
out
- The writer where the error is writtenjava.io.IOException
- If the error can not be writtenprivate void sendHeader(java.io.Writer out, java.lang.String status, java.lang.String contentType, boolean endHeaders) throws java.io.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.java.io.IOException
- When errorpublic static java.lang.String getHandlersInfoAsJSON()
public static java.lang.String getHandlerInfoAsJSON(java.lang.String cmd)
private static void printJsonInfo(java.lang.String cmd, java.io.PrintWriter r, RequestHandler handler)
public static java.lang.String getUsageAsHtml() throws java.lang.IllegalAccessException, java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.InstantiationException