public class Connection extends java.lang.Object implements ThreadPool.InterruptableTask, ServerStreamConnection
| Modifier and Type | Class and Description |
|---|---|
private static class |
Connection.BadEncodingException |
private static class |
Connection.BadRequestException |
private static class |
Connection.RequestException |
| Modifier and Type | Field and Description |
|---|---|
private byte[] |
buffer |
private static byte[] |
clength |
private static byte[] |
conclose |
private static byte[] |
conkeep |
private static byte[] |
ctype |
private static byte[] |
doubleNewline |
private boolean |
firstByte |
private java.util.Map |
headers |
private java.io.InputStream |
input |
private static byte[] |
newline |
private static byte[] |
ok |
private java.io.OutputStream |
output |
private RequestData |
requestData |
private XmlRpcStreamServer |
server |
private static byte[] |
serverName |
private boolean |
shuttingDown |
private java.net.Socket |
socket |
private static java.lang.String |
US_ASCII |
private WebServer |
webServer |
private static byte[] |
wwwAuthenticate |
| Constructor and Description |
|---|
Connection(WebServer pWebServer,
XmlRpcStreamServer pServer,
java.net.Socket pSocket)
Creates a new webserver connection on the given socket.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the connection, and frees resources.
|
private RequestData |
getRequestConfig()
Returns the connections request configuration by
merging the HTTP request headers and the servers configuration.
|
java.io.InputStream |
newInputStream()
Returns the connections input stream.
|
java.io.OutputStream |
newOutputStream()
Returns the connections output stream.
|
private java.lang.String |
readLine() |
void |
run()
Performs the task.
|
void |
setResponseHeader(java.lang.String pHeader,
java.lang.String pValue)
Sets a response header value.
|
void |
shutdown()
Interrupts the task.
|
private static byte[] |
toHTTPBytes(java.lang.String text)
Returns the US-ASCII encoded byte representation of text for
HTTP use (as per section 2.2 of RFC 2068).
|
private void |
writeContentLengthHeader(int pContentLength) |
void |
writeError(RequestData pData,
java.lang.Throwable pError,
java.io.ByteArrayOutputStream pStream)
Writes an error response to the output stream.
|
void |
writeErrorHeader(RequestData pData,
java.lang.Throwable pError,
int pContentLength)
Writes an error responses headers to the output stream.
|
void |
writeResponse(RequestData pData,
java.io.OutputStream pBuffer)
Writes the response header and the response to the
output stream.
|
void |
writeResponseHeader(RequestData pData,
int pContentLength)
Writes the response header to the output stream.
|
private static final java.lang.String US_ASCII
private static final byte[] ctype
private static final byte[] clength
private static final byte[] newline
private static final byte[] doubleNewline
private static final byte[] conkeep
private static final byte[] conclose
private static final byte[] ok
private static final byte[] serverName
private static final byte[] wwwAuthenticate
private final WebServer webServer
private final java.net.Socket socket
private final java.io.InputStream input
private final java.io.OutputStream output
private final XmlRpcStreamServer server
private byte[] buffer
private java.util.Map headers
private RequestData requestData
private boolean shuttingDown
private boolean firstByte
public Connection(WebServer pWebServer, XmlRpcStreamServer pServer, java.net.Socket pSocket) throws java.io.IOException
pWebServer - The webserver maintaining this connection.pServer - The server being used to execute requests.pSocket - The server socket to handle; the Connection
is responsible for closing this socket.java.io.IOExceptionprivate static final byte[] toHTTPBytes(java.lang.String text)
private RequestData getRequestConfig() throws java.io.IOException
java.io.IOException - Reading the request headers failed.public void run()
ThreadPool.Taskrun in interface ThreadPool.Taskprivate java.lang.String readLine()
throws java.io.IOException
java.io.IOExceptionpublic void writeResponse(RequestData pData, java.io.OutputStream pBuffer) throws java.io.IOException
pData - The request data.pBuffer - The ByteArrayOutputStream holding the response.java.io.IOException - Writing the response failed.public void writeResponseHeader(RequestData pData, int pContentLength) throws java.io.IOException
pData - The request datapContentLength - The content length, if known, or -1.java.io.IOException - Writing the response failed.public void writeError(RequestData pData, java.lang.Throwable pError, java.io.ByteArrayOutputStream pStream) throws java.io.IOException
pData - The request data.pError - The error being reported.pStream - The ByteArrayOutputStream with the error response.java.io.IOException - Writing the response failed.public void writeErrorHeader(RequestData pData, java.lang.Throwable pError, int pContentLength) throws java.io.IOException
pData - The request data.pError - The error being reported.pContentLength - The response length, if known, or -1.java.io.IOException - Writing the response failed.private void writeContentLengthHeader(int pContentLength)
throws java.io.IOException
java.io.IOExceptionpublic void setResponseHeader(java.lang.String pHeader,
java.lang.String pValue)
public java.io.OutputStream newOutputStream()
throws java.io.IOException
ServerStreamConnectionnewOutputStream in interface ServerStreamConnectionjava.io.IOExceptionpublic java.io.InputStream newInputStream()
throws java.io.IOException
ServerStreamConnectionnewInputStream in interface ServerStreamConnectionjava.io.IOExceptionpublic void close()
throws java.io.IOException
ServerStreamConnectionclose in interface ServerStreamConnectionjava.io.IOExceptionpublic void shutdown()
throws java.lang.Throwable
ThreadPool.InterruptableTaskshutdown in interface ThreadPool.InterruptableTaskjava.lang.Throwable - Shutting down the task failed.