HTTP Message base.
This class forms the basis of HTTP requests and replies. It provides
header fields, content and optional trailer fields, while managing the
state of the message.
__HTTP_0_9
public static final String __HTTP_0_9
__HTTP_1_0
public static final String __HTTP_1_0
__HTTP_1_1
public static final String __HTTP_1_1
__HTTP_1_X
public static final String __HTTP_1_X
__MSG_BAD
public static final int __MSG_BAD
Message States.
__MSG_EDITABLE
public static final int __MSG_EDITABLE
Message States.
__MSG_RECEIVED
public static final int __MSG_RECEIVED
Message States.
__MSG_SENDING
public static final int __MSG_SENDING
Message States.
__MSG_SENT
public static final int __MSG_SENT
Message States.
__SCHEME
public static final String __SCHEME
__SSL_SCHEME
public static final String __SSL_SCHEME
__state
public static final String[] __state
_attributes
protected Map _attributes
_characterEncoding
protected String _characterEncoding
_dotVersion
protected int _dotVersion
_mimeType
protected String _mimeType
_state
protected int _state
_version
protected String _version
_wrapper
protected Object _wrapper
addDateField
public void addDateField(String name,
Date date)
Adds the value of a date field.
Header or Trailer fields are set depending on message state.
name
- the field namedate
- the field date value
addDateField
public void addDateField(String name,
long date)
Add the value of a date field.
Header or Trailer fields are set depending on message state.
name
- the field namedate
- the field date value
addField
public void addField(String name,
String value)
throws IllegalStateException
Add to a multi-value field value.
If the message is editable, then a header field is set. Otherwise
if the meesage is sending and a HTTP/1.1 version, then a trailer
field is set.
name
- Name of fieldvalue
- New value to add to the field
addIntField
public void addIntField(String name,
int value)
Adds the value of an integer field.
Header or Trailer fields are set depending on message state.
name
- the field namevalue
- the field integer value
containsField
public boolean containsField(String name)
Does the header or trailer contain a field?
- True if contained in header or trailer.
destroy
public void destroy()
Destroy the message.
Help the garbage collector by nulling everything that we can.
getAttribute
public Object getAttribute(String name)
Get a request attribute.
getAttributeNames
public Enumeration getAttributeNames()
Get Attribute names.
getCharacterEncoding
public String getCharacterEncoding()
Character Encoding.
The character encoding is extracted from the ContentType field
when set.
- Character Encoding or null
getContentLength
public int getContentLength()
getContentType
public String getContentType()
getDateField
public long getDateField(String name)
Get a header as a date value.
Look in header and trailer fields.
Returns the value of a date field, or -1 if not found.
The case of the field name is ignored.
name
- the case-insensitive field name
getDotVersion
public int getDotVersion()
Get the protocol version.
- return the version dot (0.9=-1 1.0=0 1.1=1)
getField
public String getField(String name)
Get a message field.
Get a field from a message header. If no header field is found,
trailer fields are searched.
getFieldNames
public Enumeration getFieldNames()
Get field names.
- Enumeration of Field Names
getFieldValues
public Enumeration getFieldValues(String name)
Get a multi valued message field.
Get a field from a message header.
- Enumeration of field values or null
getFieldValues
public Enumeration getFieldValues(String name,
String separators)
Get a multi valued message field.
Get a field from a message header.
name
- The field nameseparators
- String of separators.
- Enumeration of field values or null
getHeader
public HttpFields getHeader()
Get the HTTP header fields.
getInputStream
public InputStream getInputStream()
getIntField
public int getIntField(String name)
Get a field as an integer value.
Look in header and trailer fields.
Returns the value of an integer field, or -1 if not found.
The case of the field name is ignored.
name
- the case-insensitive field name
getMimeType
public String getMimeType()
Mime Type.
The mime type is extracted from the contenttype field when set.
- Content type without parameters
getOutputStream
public OutputStream getOutputStream()
getState
public int getState()
Get the message state.
__MSG_EDITABLE = 0 - Created locally, all set methods enabled
__MSG_BAD = 1 - Bad message or send failure.
__MSG_RECEIVED = 2 - Received from connection.
__MSG_SENDING = 3 - Headers sent.
__MSG_SENT = 4 - Entity and trailers sent.
getVersion
public String getVersion()
Get the protocol version.
getWrapper
public Object getWrapper()
Get an associated wrapper object.
isCommitted
public boolean isCommitted()
isDirty
public boolean isDirty()
- true if the message has been modified.
removeAttribute
public void removeAttribute(String name)
Remove a request attribute.
removeField
public String removeField(String name)
throws IllegalStateException
Remove a field.
If the message is editable, then a header field is removed. Otherwise
if the message is sending and a HTTP/1.1 version, then a trailer
field is removed.
reset
protected void reset()
setAttribute
public Object setAttribute(String name,
Object attribute)
Set a request attribute.
name
- Attribute nameattribute
- Attribute value
setCharacterEncoding
public void setCharacterEncoding(String encoding,
boolean setField)
Set Character Encoding.
encoding
- An encoding that can override the encoding set
from the ContentType field.
setContentLength
public void setContentLength(int len)
setContentType
public void setContentType(String contentType)
setDateField
public void setDateField(String name,
Date date)
Sets the value of a date field.
Header or Trailer fields are set depending on message state.
name
- the field namedate
- the field date value
setDateField
public void setDateField(String name,
long date)
Sets the value of a date field.
Header or Trailer fields are set depending on message state.
name
- the field namedate
- the field date value
setField
public void setField(String name,
List value)
Set a multi-value field value.
If the message is editable, then a header field is set. Otherwise
if the meesage is sending and a HTTP/1.1 version, then a trailer
field is set.
name
- Name of fieldvalue
- New values of field
setField
public String setField(String name,
String value)
Set a field value.
If the message is editable, then a header field is set. Otherwise
if the message is sending and a HTTP/1.1 version, then a trailer
field is set.
name
- Name of fieldvalue
- New value of field
setIntField
public void setIntField(String name,
int value)
Sets the value of an integer field.
Header or Trailer fields are set depending on message state.
name
- the field namevalue
- the field integer value
setState
public int setState(int state)
Set the message state.
This method should be used by experts only as it can prevent
normal handling of a request/response.
setVersion
public void setVersion(String version)
Set the request version
version
- the HTTP version string (eg HTTP/1.1)
setWrapper
public void setWrapper(Object wrapper)
Set a wrapper object.
A wrapper object is an object associated with this message and
presents it with an different interface. The
primary example of a HttpRequest facade is ServletHttpRequest.
A single facade object may be associated with the message with
this call and retrieved with the getFacade method.
toString
public String toString()
Convert to String.
The message header is converted to a String.
updateMimeType
public void updateMimeType()