|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.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 sizepublic 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 sizeMethod Detail |
---|
public void reset()
reset
in interface HTTPConnection
IOException
public boolean isSuppressOutput()
public void setSuppressOutput(boolean suppressOutput)
suppressOutput
- should the output be suppressed or not.public int getBufferSize()
getBufferSize
in interface HTTPConnection
public void setBufferSize(int size)
setBufferSize
in interface HTTPConnection
size
- buffer sizepublic void processRequest() throws IOException
IOException
protected void parseHttpRequestLine() throws IOException
IOException
protected void parseGetParameters()
IOException
protected 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 valuepublic String readLine() throws IOException
null
if EOF
is reached
IOException
public MultiStringMap getRequestHeaders()
getRequestHeaders
in interface HTTPConnection
protected void createRequestHeaders()
public MultiStringMap getRequestParameters()
List
returned with all parameter
values in it.
getRequestParameters
in interface HTTPConnection
public String getRequestMethod()
getRequestMethod
in interface HTTPConnection
public String getRequestProtocol()
getRequestProtocol
in interface HTTPConnection
public String getContextPath()
getContextPath
in interface HTTPConnection
public void addComponentPathToContextPath()
addComponentPathToContextPath
in interface HTTPConnection
public String getComponentPath()
getComponentPath
in interface HTTPConnection
public void setComponentPath(String requestURI)
setComponentPath
in interface HTTPConnection
requestURI
- public String getComponentResourcePath()
getComponentResourcePath
in interface HTTPConnection
public void setComponentResourcePath(String resourcePath)
setComponentResourcePath
in interface HTTPConnection
resourcePath
- component resource pathpublic String getRequestPath()
getRequestURI()
but without parameters part
getRequestPath
in interface HTTPConnection
public String getRequestURI()
getRequestURI
in interface HTTPConnection
public MultiStringMap getResponseHeaders()
getResponseHeaders
in interface HTTPConnection
protected void createResponseHeaders()
public Status getResponseStatus()
getResponseStatus
in interface HTTPConnection
public void setResponseStatus(Status status)
setResponseStatus
in interface HTTPConnection
status
- response statuspublic String getResponseProtocol()
getResponseProtocol
in interface HTTPConnection
public void setResponseProtocol(String protocol)
setResponseProtocol
in interface HTTPConnection
protocol
- response protocolpublic boolean isCommited()
true
if headers are already send back to the client
isCommited
in interface HTTPConnection
true
if headers are already send back to the clientpublic void commitHeaders()
IOException
public HTTPBufferedOutputStream getContentOutputStream()
Connection#getOutputStream
public HTTPBufferedInputStream getContentInputStream()
protected void handleExpectationHeader()
protected void updateInputStreamLen()
public PrintWriter getContentWriter() throws RuntimeIOException
RuntimeIOException
protected String getOutputEncoding()
public BufferedReader getContentReader()
protected String getInputEncoding()
public Map<String,Object> getAttributes()
getAttributes
in interface HTTPConnection
public void forward(String uri)
forward
in interface HTTPConnection
uri
- uri to be redirected topublic <T> T adapt(Class<T> cls)
HTTPConnection
adapt
in interface Adaptable
adapt
in class ConnectionWrapper
cls
- class
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |