|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread com.bbn.openmap.util.http.HttpConnection
public class HttpConnection
HttpConnection handles the communication with an HTTP client in its
own thread. An instance of this class is created by the
HttpServer
each time a connection is made. The
instance exists only long enough to fulfill the request, then dies.
HttpServer
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
protected java.net.Socket |
client
|
static java.lang.String |
CONTENT_GEOTIFF
|
static java.lang.String |
CONTENT_GIF
|
static java.lang.String |
CONTENT_HTML
|
static java.lang.String |
CONTENT_JPEG
|
static java.lang.String |
CONTENT_JSON
|
static java.lang.String |
CONTENT_MOV
|
static java.lang.String |
CONTENT_PLAIN
|
static java.lang.String |
CONTENT_PNG
|
static java.lang.String |
CONTENT_PPM
|
static java.lang.String |
CONTENT_SVG
|
static java.lang.String |
CONTENT_TIFF
|
static java.lang.String |
CONTENT_WBMP
|
static java.lang.String |
CONTENT_XML
|
protected java.io.BufferedReader |
in
|
protected boolean |
isConnectionOpen
|
protected java.io.OutputStream |
out
|
protected HttpServer |
server
|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
HttpConnection(java.net.Socket client_socket,
HttpServer server)
Initialize the input Reader and output
Writer and start the connection thread. |
Method Summary | |
---|---|
void |
close()
Close the socket connection that we have opened |
static java.lang.String[] |
getAllContentTypes()
|
protected void |
handlePost()
|
protected boolean |
isEnvarLine(java.lang.String line)
|
protected void |
processGetCommand(java.lang.String cmd)
Process a "GET" HTTP command. |
protected void |
processLine(java.lang.String line)
Processes a line of an HTTP request. |
protected void |
readContent(int length)
|
protected int |
readContentLength(java.lang.String line)
|
void |
run()
The running thread simply reads all the lines of input and hands each line off to be parsed. |
static void |
writeHttpResponse(java.io.OutputStream out,
java.lang.String contentType,
byte[] response)
Write a byte[] response to the OutputStream. |
static void |
writeHttpResponse(java.io.OutputStream out,
java.lang.String contentType,
java.lang.String response)
Write a String response to the OutputStream. |
static void |
writeHttpResponseHeader(java.io.Writer out,
java.lang.String contentType,
int contentLength)
Can be used to write the header to an HttpResponse. |
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 |
---|
protected HttpServer server
protected java.net.Socket client
protected java.io.BufferedReader in
protected java.io.OutputStream out
protected boolean isConnectionOpen
public static final java.lang.String CONTENT_JPEG
public static final java.lang.String CONTENT_GIF
public static final java.lang.String CONTENT_PPM
public static final java.lang.String CONTENT_PNG
public static final java.lang.String CONTENT_TIFF
public static final java.lang.String CONTENT_GEOTIFF
public static final java.lang.String CONTENT_WBMP
public static final java.lang.String CONTENT_SVG
public static final java.lang.String CONTENT_HTML
public static final java.lang.String CONTENT_MOV
public static final java.lang.String CONTENT_PLAIN
public static final java.lang.String CONTENT_XML
public static final java.lang.String CONTENT_JSON
Constructor Detail |
---|
public HttpConnection(java.net.Socket client_socket, HttpServer server)
Reader
and output
Writer
and start the connection thread.
client_socket
- the client's socketserver
- the server objectMethod Detail |
---|
public static java.lang.String[] getAllContentTypes()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
protected void processLine(java.lang.String line) throws java.io.IOException
line
- one line of an HTTP request
java.io.IOException
protected void handlePost() throws java.io.IOException
java.io.IOException
protected int readContentLength(java.lang.String line)
protected boolean isEnvarLine(java.lang.String line)
protected void readContent(int length) throws java.io.IOException
java.io.IOException
protected void processGetCommand(java.lang.String cmd) throws java.io.IOException
cmd
- a "GET" HTTP command
java.io.IOException
public static void writeHttpResponseHeader(java.io.Writer out, java.lang.String contentType, int contentLength) throws java.io.IOException
out
- Writer to place text on the OutputStream.contentType
- the mime type for your response.contentLength
- the byte length of your response.
java.io.IOException
public static void writeHttpResponse(java.io.OutputStream out, java.lang.String contentType, java.lang.String response) throws java.io.IOException
out
- the OutputStream of the response.contentType
- the content type of the response.response
- the string containing the response.
java.io.IOException
public static void writeHttpResponse(java.io.OutputStream out, java.lang.String contentType, byte[] response) throws java.io.IOException
out
- the OutputStream of the response.contentType
- the content type of the response.response
- the byte array containing the response.
java.io.IOException
public void close() throws java.io.IOException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |