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 class
private static class
private 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 boolean
private Map
private final InputStream
private static final byte[]
private static final byte[]
private final OutputStream
private RequestData
private final XmlRpcStreamServer
private static final byte[]
private boolean
private final Socket
private static final String
private final WebServer
private 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 TypeMethodDescriptionvoid
close()
Closes the connection, and frees resources.private RequestData
Returns 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 String
readLine()
void
run()
Performs the task.void
setResponseHeader
(String pHeader, String pValue) Sets a response header value.void
shutdown()
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 void
writeContentLengthHeader
(int pContentLength) 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.
-
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; theConnection
is 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.Task
Performs the task.- Specified by:
run
in interfaceThreadPool.Task
-
readLine
- Throws:
IOException
-
writeResponse
Writes the response header and the response to the output stream.- Parameters:
pData
- The request data.pBuffer
- TheByteArrayOutputStream
holding 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
- TheByteArrayOutputStream
with 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:ServerStreamConnection
Returns the connections output stream.- Specified by:
newOutputStream
in interfaceServerStreamConnection
- Throws:
IOException
-
newInputStream
Description copied from interface:ServerStreamConnection
Returns the connections input stream.- Specified by:
newInputStream
in interfaceServerStreamConnection
- Throws:
IOException
-
close
Description copied from interface:ServerStreamConnection
Closes the connection, and frees resources.- Specified by:
close
in interfaceServerStreamConnection
- Throws:
IOException
-
shutdown
Description copied from interface:ThreadPool.InterruptableTask
Interrupts the task.- Specified by:
shutdown
in interfaceThreadPool.InterruptableTask
- Throws:
Throwable
- Shutting down the task failed.
-