org.apache.xmlrpc.webserver

Class Connection

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

Connection(WebServer pWebServer, XmlRpcStreamServer pServer, Socket pSocket)
Creates a new webserver connection on the given socket.

Method Summary

void
close()
Closes the connection, and frees resources.
InputStream
newInputStream()
Returns the connections input stream.
OutputStream
newOutputStream()
Returns the connections output stream.
void
run()
Performs the task.
void
setResponseHeader(String pHeader, String pValue)
Sets a response header value.
void
shutdown()
Interrupts the task.
void
writeError(RequestData pData, Throwable pError, ByteArrayOutputStream pStream)
Writes an error response to the output stream.
void
writeErrorHeader(RequestData pData, Throwable pError, int pContentLength)
Writes an error responses headers to the output stream.
void
writeResponse(RequestData pData, 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.

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; the Connection is responsible for closing this socket.

Method Details

close

public void close()
            throws IOException
Closes the connection, and frees resources.
Specified by:
close in interface ServerStreamConnection

newInputStream

public InputStream newInputStream()
            throws IOException
Returns the connections input stream.
Specified by:
newInputStream in interface ServerStreamConnection

newOutputStream

public OutputStream newOutputStream()
            throws IOException
Returns the connections output stream.
Specified by:
newOutputStream in interface ServerStreamConnection

run

public void run()
Performs the task.
Specified by:
run in interface ThreadPool.Task

setResponseHeader

public void setResponseHeader(String pHeader,
                              String pValue)
Sets a response header value.

shutdown

public void shutdown()
            throws Throwable
Interrupts the task.
Specified by:
shutdown in interface ThreadPool.InterruptableTask

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 - The ByteArrayOutputStream with the error response.

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.

writeResponse

public void writeResponse(RequestData pData,
                          OutputStream pBuffer)
            throws IOException
Writes the response header and the response to the output stream.
Parameters:
pData - The request data.
pBuffer - The ByteArrayOutputStream holding the response.

writeResponseHeader

public void writeResponseHeader(RequestData pData,
                                int pContentLength)
            throws IOException
Writes the response header to the output stream. *
Parameters:
pData - The request data
pContentLength - The content length, if known, or -1.

Copyright © 2001-2007 Apache Software Foundation. All Rights Reserved.