public class HttpServer
extends java.lang.Thread
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PORT
The default port.
|
protected java.net.ServerSocket |
listen_socket |
protected java.util.Vector |
listeners |
protected int |
port |
Constructor and Description |
---|
HttpServer()
Creates an Http Server on any free port, and then starts a
thread that listens to that port.
|
HttpServer(int port)
Creates an Http Server on the indicated port, and then starts a
thread that listens to that port.
|
HttpServer(int port,
boolean asDaemon)
Creates an Http Server on the indicated port, and then starts a
thread that listens to that port.
|
Modifier and Type | Method and Description |
---|---|
void |
addHttpRequestListener(HttpRequestListener l)
Adds a new http request listener.
|
HttpRequestEvent |
fireHttpRequestEvent(java.lang.String request,
java.io.OutputStream output)
Creates a HttpRequestEvent and sends it to all registered
listeners.
|
int |
getPort()
Gets the port associate with this server.
|
static void |
main(java.lang.String[] args)
A main routine for unit testing.
|
void |
removeHttpRequestListener(HttpRequestListener l)
Removes an http request listener.
|
void |
run()
The body of the server 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
public static final int DEFAULT_PORT
protected int port
protected java.net.ServerSocket listen_socket
protected java.util.Vector listeners
public HttpServer(int port) throws java.io.IOException
port
- the port to openjava.io.IOException
ServerSocket
public HttpServer(int port, boolean asDaemon) throws java.io.IOException
port
- the port to openasDaemon
- whether to make thread a daemonjava.io.IOException
ServerSocket
public HttpServer() throws java.io.IOException
java.io.IOException
ServerSocket
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
HttpConnection
,
Socket
public int getPort()
public HttpRequestEvent fireHttpRequestEvent(java.lang.String request, java.io.OutputStream output) throws java.io.IOException
request
- the parsed http requestoutput
- OutputStream associated with the request's client
connection.java.io.IOException
DataOutputStream
,
HttpRequestListener
,
HttpRequestEvent
public void addHttpRequestListener(HttpRequestListener l)
l
- the listenerHttpRequestListener
public void removeHttpRequestListener(HttpRequestListener l)
l
- a listenerHttpRequestListener
public static void main(java.lang.String[] args)
Usage: java com.bbn.openmap.layer.util.http.HttpServer [port]
If no port is specified, the default port is used.
If port zero is specified, the system chooses the port.
If a port other than zero is specified, the http server will attempt to open that port, or fail if it is in use.
Examples:
java com.bbn.openmap.layer.util.http.HttpServer
java com.bbn.openmap.layer.util.http.HttpServer 8000
java com.bbn.openmap.layer.util.http.HttpServer 0
args
- command line argsCopyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details