org.openstreetmap.josm.io.remotecontrol
Class RequestProcessor

java.lang.Object
  extended by java.lang.Thread
      extended by org.openstreetmap.josm.io.remotecontrol.RequestProcessor
All Implemented Interfaces:
java.lang.Runnable

public class RequestProcessor
extends java.lang.Thread

Processes HTTP "remote control" requests.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
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
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
RequestProcessor(java.net.Socket request)
          Constructor
 
Method Summary
(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 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
 
Methods inherited from class java.lang.Thread
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
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROTOCOLVERSION

public static final java.lang.String PROTOCOLVERSION
RemoteControl protocol version. Change minor number for compatible interface extensions. Change major number in case of incompatible changes.

See Also:
Constant Field Values

request

private java.net.Socket request
The socket this processor listens on


handlers

private static java.util.Map<java.lang.String,java.lang.Class<? extends RequestHandler>> handlers
Collection of request handlers. Will be initialized with default handlers here. Other plug-ins can extend this list by using @see addRequestHandler

Constructor Detail

RequestProcessor

public RequestProcessor(java.net.Socket request)
Constructor

Parameters:
request - A socket to read the request.
Method Detail

processRequest

public static void processRequest(java.net.Socket request)
Spawns a new thread for the request


addRequestHandlerClass

static void addRequestHandlerClass(java.lang.String command,
                                   java.lang.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(java.lang.String command,
                                           java.lang.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.

run

public void run()
The work is done here.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

sendError

private void sendError(java.io.Writer out)
                throws java.io.IOException
Sends a 500 error: server error

Parameters:
out - The writer where the error is written
Throws:
java.io.IOException - If the error can not be written

sendNotImplemented

private void sendNotImplemented(java.io.Writer out)
                         throws java.io.IOException
Sends a 501 error: not implemented

Parameters:
out - The writer where the error is written
Throws:
java.io.IOException - If the error can not be written

sendForbidden

private void sendForbidden(java.io.Writer out,
                           java.lang.String help)
                    throws java.io.IOException
Sends a 403 error: forbidden

Parameters:
out - The writer where the error is written
Throws:
java.io.IOException - If the error can not be written

sendBadRequest

private void sendBadRequest(java.io.Writer out,
                            java.lang.String help)
                     throws java.io.IOException
Sends a 403 error: forbidden

Parameters:
out - The writer where the error is written
Throws:
java.io.IOException - If the error can not be written

sendHeader

private void sendHeader(java.io.Writer out,
                        java.lang.String status,
                        java.lang.String contentType,
                        boolean endHeaders)
                 throws java.io.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:
java.io.IOException - When error


JOSM