|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.abstracthorizon.danube.connection.ConnectionWrapper
org.abstracthorizon.danube.http.HTTPConnectionImpl
public class HTTPConnectionImpl
This connection represents one HTTP request and response. It can be reused over the same underlaying connection (multiple requests over the same socket).
This implementation handles HTTP request string, headers and parameters.
| Field Summary | |
|---|---|
protected Map<String,Object> |
attributes
Map of attributes |
protected HTTPBufferedInputStream |
bufferedInput
Buffered input |
protected HTTPBufferedOutputStream |
bufferedOutput
Buffered output |
protected BufferedReader |
cachedBufferedReader
Cached buffered reader |
protected InputStream |
cachedInputStream
Cached underlaying connection's input stream |
protected OutputStream |
cachedOutputStream
Cached underlaying connection's output stream |
protected EncodingPrintWrtier |
cachedPrintWriter
Cached print writer |
protected String |
cachedReadersEncoding
Cached readers encoding |
protected String |
componentPath
Current (processed) requestURI. |
protected int |
componentPointer
Pointer to end of component part of the request path |
protected String |
componentResourcePath
Current (processed) requestURI. |
protected String |
contextPath
Current path up to the current component |
protected int |
contextPointer
Pointer to end of context part of the request path |
protected static String |
CRLF
Helper array of CR and LF characters |
protected int |
defaultBufferSize
Default buffer size |
protected boolean |
expectationIsHandled
Is expectation header handled |
protected boolean |
headersCommitted
Have headers been commited already. |
protected ConnectionHandler |
parent
Reference to creator of this handler so forward can work from that point |
protected MultiStringHashMap |
requestHeaders
Request headers |
protected String |
requestMethod
Request method (GET, POST, etc) |
protected MultiStringHashMap |
requestParameters
Request parameters. |
protected String |
requestPath
Similar as raw URI but without parameters |
protected String |
requestProtocol
Requested protocol (HTTP/1.0, HTTP/1.1 or null) |
protected String |
requestURI
Raw URI request. |
protected MultiStringHashMap |
responseHeaders
Response headers |
protected String |
responseProtocol
Response protocol |
protected Status |
responseStatus
Response status |
protected boolean |
suppressOutput
Shell content output be suppressed or not. |
protected StringPrintWriter |
writer
Writer |
protected boolean |
writerReturned
Has writer been already returned |
| Fields inherited from class org.abstracthorizon.danube.connection.ConnectionWrapper |
|---|
connection, logger |
| Fields inherited from interface org.abstracthorizon.danube.http.HTTPConnection |
|---|
HEADER_DATE_FORMAT |
| Constructor Summary | |
|---|---|
HTTPConnectionImpl(Connection connection,
ConnectionHandler parent,
InputStream inputStream,
OutputStream outputStream,
int defaultBufferSize)
Constructor. |
|
HTTPConnectionImpl(Connection connection,
ConnectionHandler parent,
int defaultBufferSize)
Constructor. |
|
| Method Summary | ||
|---|---|---|
|
adapt(Class<T> cls)
Adapts this class to HTTPConnection |
|
void |
addComponentPathToContextPath()
Updates context path adding new path element to it |
|
static void |
addParam(MultiStringMap params,
String name,
String value)
Adds parameter to the map. |
|
void |
commitHeaders()
This method output response string and headers |
|
protected void |
createRequestHeaders()
|
|
protected void |
createResponseHeaders()
|
|
void |
forward(String uri)
Redirects request |
|
Map<String,Object> |
getAttributes()
Returns map of attributes. |
|
int |
getBufferSize()
Returns buffer size |
|
String |
getComponentPath()
Returns request uri |
|
String |
getComponentResourcePath()
Returns remainder of path after context path and component path is removed |
|
HTTPBufferedInputStream |
getContentInputStream()
Returns content input stream |
|
HTTPBufferedOutputStream |
getContentOutputStream()
Returns output stream but creates and commits headers before. |
|
BufferedReader |
getContentReader()
Returns content reader |
|
PrintWriter |
getContentWriter()
Returns writer. |
|
String |
getContextPath()
Returns portion of request path up to component path |
|
protected String |
getInputEncoding()
Returns request encoding |
|
protected String |
getOutputEncoding()
Retuns response encoding |
|
MultiStringMap |
getRequestHeaders()
Returns request headers map |
|
String |
getRequestMethod()
Returns request method |
|
MultiStringMap |
getRequestParameters()
Returns request parameters map. |
|
String |
getRequestPath()
This is similar to getRequestURI() but without parameters part |
|
String |
getRequestProtocol()
Returns request protocol |
|
String |
getRequestURI()
Returns raw requested uri along with all parameters if supplied (GET method) |
|
MultiStringMap |
getResponseHeaders()
Returns response headers map |
|
String |
getResponseProtocol()
Returns response protocol |
|
Status |
getResponseStatus()
Returns response status |
|
protected void |
handleExpectationHeader()
|
|
boolean |
isCommited()
Returns true if headers are already send back to the client |
|
boolean |
isSuppressOutput()
Should content output be suppressed or not. |
|
protected void |
parseGetParameters()
Retrieves get parameters |
|
protected void |
parseHttpRequestLine()
|
|
protected void |
parsePostParameters()
Retrieves post parameters |
|
void |
processRequest()
This method processes request. |
|
String |
readLine()
Utility method that reads a line from input stream |
|
void |
reset()
This method processes request. |
|
protected void |
retrieveHeaders()
Retrieves headers |
|
protected static void |
retrieveParams(MultiStringMap params,
Reader r,
int len)
This method extracts parameters from givem reader. |
|
void |
setBufferSize(int size)
Sets buffer size |
|
void |
setComponentPath(String requestURI)
Sets request uri. |
|
void |
setComponentResourcePath(String resourcePath)
Sets component resource path |
|
void |
setResponseProtocol(String protocol)
Sets response protocol |
|
void |
setResponseStatus(Status status)
Sets response status |
|
void |
setSuppressOutput(boolean suppressOutput)
Should output be suppressed or not. |
|
protected void |
setupRequestPaths()
Retrieves get parameters |
|
protected void |
updateInputStreamLen()
Updates content input stream's length or chunked encoding |
|
| Methods inherited from class org.abstracthorizon.danube.connection.ConnectionWrapper |
|---|
close, isClosed |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.abstracthorizon.danube.connection.Connection |
|---|
close, isClosed |
| Field Detail |
|---|
protected static final String CRLF
protected InputStream cachedInputStream
protected OutputStream cachedOutputStream
protected MultiStringHashMap requestHeaders
protected MultiStringHashMap requestParameters
String as a type,
a List is going to be used.
protected String requestMethod
protected String requestProtocol
protected String requestURI
protected String requestPath
protected int contextPointer
protected int componentPointer
protected String contextPath
protected String componentPath
protected String componentResourcePath
protected MultiStringHashMap responseHeaders
protected Status responseStatus
protected String responseProtocol
protected boolean headersCommitted
protected StringPrintWriter writer
protected Map<String,Object> attributes
protected ConnectionHandler parent
protected boolean writerReturned
protected boolean suppressOutput
protected HTTPBufferedOutputStream bufferedOutput
protected HTTPBufferedInputStream bufferedInput
protected EncodingPrintWrtier cachedPrintWriter
protected BufferedReader cachedBufferedReader
protected String cachedReadersEncoding
protected int defaultBufferSize
protected boolean expectationIsHandled
| Constructor Detail |
|---|
public HTTPConnectionImpl(Connection connection,
ConnectionHandler parent,
int defaultBufferSize)
connection - original connectionparent - parent connection handler needed for forwardingdefaultBufferSize - default buffer size
public HTTPConnectionImpl(Connection connection,
ConnectionHandler parent,
InputStream inputStream,
OutputStream outputStream,
int defaultBufferSize)
connection - original connectionparent - parent connection handler needed for forwardinginputStream - input stream to be read fromoutputStrema - output stream to be written todefaultBufferSize - default buffer size| Method Detail |
|---|
public void reset()
reset in interface HTTPConnectionIOExceptionpublic boolean isSuppressOutput()
public void setSuppressOutput(boolean suppressOutput)
suppressOutput - should the output be suppressed or not.public int getBufferSize()
getBufferSize in interface HTTPConnectionpublic void setBufferSize(int size)
setBufferSize in interface HTTPConnectionsize - buffer size
public void processRequest()
throws IOException
IOException
protected void parseHttpRequestLine()
throws IOException
IOExceptionprotected void parseGetParameters()
IOExceptionprotected void setupRequestPaths()
IOException
protected void parsePostParameters()
throws IOException
IOException
protected void retrieveHeaders()
throws IOException
IOException
protected static void retrieveParams(MultiStringMap params,
Reader r,
int len)
throws IOException
params - parameters mapr - readerlen - number of chars to be read from reader
IOException
public static void addParam(MultiStringMap params,
String name,
String value)
String type then it is replaced with a List
and then old and new parameter stored under it.
params - parameter mapname - name of parametervalue - parameter's value
public String readLine()
throws IOException
null if EOF is reached
IOExceptionpublic MultiStringMap getRequestHeaders()
getRequestHeaders in interface HTTPConnectionprotected void createRequestHeaders()
public MultiStringMap getRequestParameters()
List returned with all parameter
values in it.
getRequestParameters in interface HTTPConnectionpublic String getRequestMethod()
getRequestMethod in interface HTTPConnectionpublic String getRequestProtocol()
getRequestProtocol in interface HTTPConnectionpublic String getContextPath()
getContextPath in interface HTTPConnectionpublic void addComponentPathToContextPath()
addComponentPathToContextPath in interface HTTPConnectionpublic String getComponentPath()
getComponentPath in interface HTTPConnectionpublic void setComponentPath(String requestURI)
setComponentPath in interface HTTPConnectionrequestURI - public String getComponentResourcePath()
getComponentResourcePath in interface HTTPConnectionpublic void setComponentResourcePath(String resourcePath)
setComponentResourcePath in interface HTTPConnectionresourcePath - component resource pathpublic String getRequestPath()
getRequestURI() but without parameters part
getRequestPath in interface HTTPConnectionpublic String getRequestURI()
getRequestURI in interface HTTPConnectionpublic MultiStringMap getResponseHeaders()
getResponseHeaders in interface HTTPConnectionprotected void createResponseHeaders()
public Status getResponseStatus()
getResponseStatus in interface HTTPConnectionpublic void setResponseStatus(Status status)
setResponseStatus in interface HTTPConnectionstatus - response statuspublic String getResponseProtocol()
getResponseProtocol in interface HTTPConnectionpublic void setResponseProtocol(String protocol)
setResponseProtocol in interface HTTPConnectionprotocol - response protocolpublic boolean isCommited()
true if headers are already send back to the client
isCommited in interface HTTPConnectiontrue if headers are already send back to the clientpublic void commitHeaders()
IOExceptionpublic HTTPBufferedOutputStream getContentOutputStream()
Connection#getOutputStreampublic HTTPBufferedInputStream getContentInputStream()
protected void handleExpectationHeader()
protected void updateInputStreamLen()
public PrintWriter getContentWriter()
throws RuntimeIOException
RuntimeIOExceptionprotected String getOutputEncoding()
public BufferedReader getContentReader()
protected String getInputEncoding()
public Map<String,Object> getAttributes()
getAttributes in interface HTTPConnectionpublic void forward(String uri)
forward in interface HTTPConnectionuri - uri to be redirected topublic <T> T adapt(Class<T> cls)
HTTPConnection
adapt in interface Adaptableadapt in class ConnectionWrappercls - class
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||