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 java.lang.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.
-
-
Constructor Summary
Constructors Constructor Description Connection(WebServer pWebServer, XmlRpcStreamServer pServer, java.net.Socket pSocket)Creates a new webserver connection on the given socket.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the connection, and frees resources.java.io.InputStreamnewInputStream()Returns the connections input stream.java.io.OutputStreamnewOutputStream()Returns the connections output stream.voidrun()Performs the task.voidsetResponseHeader(java.lang.String pHeader, java.lang.String pValue)Sets a response header value.voidshutdown()Interrupts the task.voidwriteError(RequestData pData, java.lang.Throwable pError, java.io.ByteArrayOutputStream pStream)Writes an error response to the output stream.voidwriteErrorHeader(RequestData pData, java.lang.Throwable pError, int pContentLength)Writes an error responses headers to the output stream.voidwriteResponse(RequestData pData, java.io.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.
-
-
-
Constructor Detail
-
Connection
public Connection(WebServer pWebServer, XmlRpcStreamServer pServer, java.net.Socket pSocket) throws java.io.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:
java.io.IOException
-
-
Method Detail
-
run
public void run()
Description copied from interface:ThreadPool.TaskPerforms the task.- Specified by:
runin interfaceThreadPool.Task
-
writeResponse
public void writeResponse(RequestData pData, java.io.OutputStream pBuffer) throws java.io.IOException
Writes the response header and the response to the output stream.- Parameters:
pData- The request data.pBuffer- TheByteArrayOutputStreamholding the response.- Throws:
java.io.IOException- Writing the response failed.
-
writeResponseHeader
public void writeResponseHeader(RequestData pData, int pContentLength) throws java.io.IOException
Writes the response header to the output stream. *- Parameters:
pData- The request datapContentLength- The content length, if known, or -1.- Throws:
java.io.IOException- Writing the response failed.
-
writeError
public void writeError(RequestData pData, java.lang.Throwable pError, java.io.ByteArrayOutputStream pStream) throws java.io.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:
java.io.IOException- Writing the response failed.
-
writeErrorHeader
public void writeErrorHeader(RequestData pData, java.lang.Throwable pError, int pContentLength) throws java.io.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:
java.io.IOException- Writing the response failed.
-
setResponseHeader
public void setResponseHeader(java.lang.String pHeader, java.lang.String pValue)Sets a response header value.
-
newOutputStream
public java.io.OutputStream newOutputStream() throws java.io.IOExceptionDescription copied from interface:ServerStreamConnectionReturns the connections output stream.- Specified by:
newOutputStreamin interfaceServerStreamConnection- Throws:
java.io.IOException
-
newInputStream
public java.io.InputStream newInputStream() throws java.io.IOExceptionDescription copied from interface:ServerStreamConnectionReturns the connections input stream.- Specified by:
newInputStreamin interfaceServerStreamConnection- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionDescription copied from interface:ServerStreamConnectionCloses the connection, and frees resources.- Specified by:
closein interfaceServerStreamConnection- Throws:
java.io.IOException
-
shutdown
public void shutdown() throws java.lang.ThrowableDescription copied from interface:ThreadPool.InterruptableTaskInterrupts the task.- Specified by:
shutdownin interfaceThreadPool.InterruptableTask- Throws:
java.lang.Throwable- Shutting down the task failed.
-
-