Package org.apache.xmlrpc.webserver
Class Connection
java.lang.Object
org.apache.xmlrpc.webserver.Connection
- All Implemented Interfaces:
ServerStreamConnection,ThreadPool.InterruptableTask,ThreadPool.Task
public class Connection
extends Object
implements ThreadPool.InterruptableTask, ServerStreamConnection
Handler for a single clients connection. This implementation
is able to do HTTP keepalive. In other words, it can serve
multiple requests via a single, physical connection.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]private static final byte[]private static final byte[]private static final byte[]private static final byte[]private static final byte[]private booleanprivate Mapprivate final InputStreamprivate static final byte[]private static final byte[]private final OutputStreamprivate RequestDataprivate final XmlRpcStreamServerprivate static final byte[]private booleanprivate final Socketprivate static final Stringprivate final WebServerprivate static final byte[] -
Constructor Summary
ConstructorsConstructorDescriptionConnection(WebServer pWebServer, XmlRpcStreamServer pServer, Socket pSocket) Creates a new webserver connection on the given socket. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the connection, and frees resources.private RequestDataReturns the connections request configuration by merging the HTTP request headers and the servers configuration.Returns the connections input stream.Returns the connections output stream.private StringreadLine()voidrun()Performs the task.voidsetResponseHeader(String pHeader, String pValue) Sets a response header value.voidshutdown()Interrupts the task.private static final byte[]toHTTPBytes(String text) Returns the US-ASCII encoded byte representation of text for HTTP use (as per section 2.2 of RFC 2068).private voidwriteContentLengthHeader(int pContentLength) voidwriteError(RequestData pData, Throwable pError, ByteArrayOutputStream pStream) Writes an error response to the output stream.voidwriteErrorHeader(RequestData pData, Throwable pError, int pContentLength) Writes an error responses headers to the output stream.voidwriteResponse(RequestData pData, OutputStream pBuffer) Writes the response header and the response to the output stream.voidwriteResponseHeader(RequestData pData, int pContentLength) Writes the response header to the output stream.
-
Field Details
-
US_ASCII
- See Also:
-
ctype
private static final byte[] ctype -
clength
private static final byte[] clength -
newline
private static final byte[] newline -
doubleNewline
private static final byte[] doubleNewline -
conkeep
private static final byte[] conkeep -
conclose
private static final byte[] conclose -
ok
private static final byte[] ok -
serverName
private static final byte[] serverName -
wwwAuthenticate
private static final byte[] wwwAuthenticate -
webServer
-
socket
-
input
-
output
-
server
-
buffer
private byte[] buffer -
headers
-
requestData
-
shuttingDown
private boolean shuttingDown -
firstByte
private boolean firstByte
-
-
Constructor Details
-
Connection
public Connection(WebServer pWebServer, XmlRpcStreamServer pServer, Socket pSocket) throws IOException Creates a new webserver connection on the given socket.- Parameters:
pWebServer- The webserver maintaining this connection.pServer- The server being used to execute requests.pSocket- The server socket to handle; theConnectionis responsible for closing this socket.- Throws:
IOException
-
-
Method Details
-
toHTTPBytes
Returns the US-ASCII encoded byte representation of text for HTTP use (as per section 2.2 of RFC 2068). -
getRequestConfig
Returns the connections request configuration by merging the HTTP request headers and the servers configuration.- Returns:
- The connections request configuration.
- Throws:
IOException- Reading the request headers failed.
-
run
public void run()Description copied from interface:ThreadPool.TaskPerforms the task.- Specified by:
runin interfaceThreadPool.Task
-
readLine
- Throws:
IOException
-
writeResponse
Writes the response header and the response to the output stream.- Parameters:
pData- The request data.pBuffer- TheByteArrayOutputStreamholding the response.- Throws:
IOException- Writing the response failed.
-
writeResponseHeader
Writes the response header to the output stream. *- Parameters:
pData- The request datapContentLength- The content length, if known, or -1.- Throws:
IOException- Writing the response failed.
-
writeError
public void writeError(RequestData pData, Throwable pError, ByteArrayOutputStream pStream) throws IOException Writes an error response to the output stream.- Parameters:
pData- The request data.pError- The error being reported.pStream- TheByteArrayOutputStreamwith the error response.- Throws:
IOException- Writing the response failed.
-
writeErrorHeader
public void writeErrorHeader(RequestData pData, Throwable pError, int pContentLength) throws IOException Writes an error responses headers to the output stream.- Parameters:
pData- The request data.pError- The error being reported.pContentLength- The response length, if known, or -1.- Throws:
IOException- Writing the response failed.
-
writeContentLengthHeader
- Throws:
IOException
-
setResponseHeader
Sets a response header value. -
newOutputStream
Description copied from interface:ServerStreamConnectionReturns the connections output stream.- Specified by:
newOutputStreamin interfaceServerStreamConnection- Throws:
IOException
-
newInputStream
Description copied from interface:ServerStreamConnectionReturns the connections input stream.- Specified by:
newInputStreamin interfaceServerStreamConnection- Throws:
IOException
-
close
Description copied from interface:ServerStreamConnectionCloses the connection, and frees resources.- Specified by:
closein interfaceServerStreamConnection- Throws:
IOException
-
shutdown
Description copied from interface:ThreadPool.InterruptableTaskInterrupts the task.- Specified by:
shutdownin interfaceThreadPool.InterruptableTask- Throws:
Throwable- Shutting down the task failed.
-