|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.flat502.rox.http.HttpMessage
public abstract class HttpMessage
This class represents an abstract HTTP message and provides support for various aspects of an HTTP message common to both requests and responses.
This class is not thread-safe.
Constructor Summary | |
---|---|
protected |
HttpMessage(Encoding encoding)
Constructs an instance |
Method Summary | |
---|---|
java.lang.String |
addHeader(java.lang.String name,
java.lang.String value)
Add a header and value to this instance. |
java.lang.String |
formatDate(java.util.Date date)
Formats a Date instance as described in
section
3.1.1 of RFC 2616. |
protected java.lang.String |
getHeaderValue(java.lang.String name)
|
protected java.lang.String |
getStartLine()
Implementation should return the HTTP start line for this message (without a newline marker). |
protected java.lang.String |
getVersionString()
Get the HTTP version string for this instance. |
protected boolean |
isHeaderSet(java.lang.String name)
Check if a header has been set. |
byte[] |
marshal()
A convenience routine that constructs a byte array representing this instance. |
void |
marshal(java.io.OutputStream os)
Writes the HTTP message represented by this instance to a given OutputStream . |
protected void |
marshalContent(java.io.OutputStream contentStream)
Writes this instance's content to the given stream. |
protected void |
marshalHeaders(java.io.OutputStream os)
Writes all defined HTTP headers to the given stream. |
protected abstract void |
marshalStartLine(java.io.OutputStream os)
Writes the HTTP start line for this message. |
protected java.lang.String |
normalizeHeaderName(java.lang.String name)
Normalizes an HTTP header name. |
void |
setContent(byte[] content)
Set the content for this HTTP message. |
java.lang.String |
setHeader(java.lang.String name,
java.lang.String value)
Set a header value, replacing any previously set value. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected HttpMessage(Encoding encoding)
This method sets the Date
header
to the current date.
encoding
- An Encoding
describing the encoding to use when
constructing this message. This also informs the
Content-Encoding
header value. May be
null
.Method Detail |
---|
public java.lang.String formatDate(java.util.Date date)
Date
instance as described in
section
3.1.1 of RFC 2616.
The actual format used is that described in RC 822 and mentioned in section 3.1.1 of RFC 2616 as the preferred format.
date
- The date to format.
public java.lang.String setHeader(java.lang.String name, java.lang.String value)
name
- The header name.value
- The header value.
null
if no value was set.addHeader(String, String)
public java.lang.String addHeader(java.lang.String name, java.lang.String value)
Header order is preserved. Headers are
marshalled
in the
order in which they are added to this instance, with
one exception: duplicate headers.
If this method is called multiple times for the same header values are folded into a single comma-separated value as allowed for by section 4 of RFC 2616.
Header names are normalized
before being stored. As such, case is unimportant.
setHeader(String, String)
allows for the
replacement of headers.
name
- The header name.value
- The header value.
HttpConstants.Headers
,
setHeader(String, String)
,
normalizeHeaderName(String)
protected java.lang.String getHeaderValue(java.lang.String name)
protected java.lang.String normalizeHeaderName(java.lang.String name)
Normalization produces the logical equivalent of the following algorithm.
The name is split into words using the '-' character. Each word is then normalized by converting the first character to uppercase and all remaining characters to lowercase. The resulting words are joined again using the '-' character. The result is returned.
name
- The header name.
public void setContent(byte[] content)
This method sets the Content-Length
header (using setHeader(String, String)
)
to the length of content
.
content
- The content to include in this HTTP message.public void marshal(java.io.OutputStream os) throws java.io.IOException
OutputStream
.
os
- The stream to write to.
java.io.IOException
- If an error occurs writing to the stream or if
any required character set cannot be loaded.protected abstract void marshalStartLine(java.io.OutputStream os) throws java.io.IOException
This implementation writes the string returned
by getStartLine()
followed by a newline
marker.
The "start line" is described in section 4.1 of RFC 2616.
os
- The stream to write the start line to.
java.io.IOException
protected java.lang.String getStartLine()
protected void marshalHeaders(java.io.OutputStream os) throws java.io.IOException
If the Content-Type
header has not yet
been set it is set to 0 (but see setContent(byte[])
as well).
Headers are rendered in the order in which they were
first added (using either addHeader(String, String)
or setHeader(String, String)
). If an existing
header is replaced with a call to setHeader(String, String)
it's rendered order is not affected.
os
- The stream to write the start line to.
java.io.IOException
protected void marshalContent(java.io.OutputStream contentStream) throws java.io.IOException
If setContent(byte[])
has not been invoked
this method returns without doing anything.
contentStream
- The stream to write to.
java.io.IOException
- if an error occurs writing to the stream.public byte[] marshal() throws java.io.IOException
This method is equivalent to invoking
marshal(OutputStream)
to a
ByteArrayOutputStream
instance and
retrieving the byte array.
java.io.IOException
- If an error occurs writing to the stream or if
any required character set cannot be loaded.protected java.lang.String getVersionString()
HTTP/1.1
.protected boolean isHeaderSet(java.lang.String name)
Case is unimportant.
name
- The header name.
true
if the named header has been
set.public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |