Class MessageHeader
- All Implemented Interfaces:
Message
- Direct Known Subclasses:
ResponseMessage
Message
object is used to store an retrieve the
headers for both a request and response. Headers are stored and
retrieved in a case insensitive manner according to RFC 2616.
The message also allows multiple header values to be added to a
single header name, headers such as Cookie and Set-Cookie can be
added multiple times with different values.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
TheSeries
object is used to represent a list of HTTP header value for a given name. -
Field Summary
FieldsModifier and TypeFieldDescriptionThis is used to store the cookies added to the HTTP header.This is used to store the individual names for the header.private final DateParser
This is used to parse all date headers added to the message.private final KeyMap
<MessageHeader.Series> This is used to store multiple header values for a name. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
This is used as a convenience method for adding a header that needs to be parsed into a HTTPdate string.void
addInteger
(String name, int value) This can be used to add a HTTP message header to this object.void
This can be used to add a HTTP message header to this object.This is used to acquire all the individual header values from the message.This is used to acquire all the individual header values from the message.This returns theCookie
object stored under the specified name.This returns allCookie
objects stored under the specified name.long
This can be used to get the value of the first message header that has the specified name.int
getInteger
(String name) This can be used to get the value of the first message header that has the specified name.long
This can be used to get the value of the first message header that has the specified name.getNames()
This is used to acquire the names of the of the headers that have been set in the response.This can be used to get the value of the first message header that has the specified name.This can be used to get the value of the first message header that has the specified name.This can be used to get the values of HTTP message headers that have the specified name.This can be used to get the values of HTTP message headers that have the specified name.ThesetCookie
method is used to set a cookie value with the cookie name.ThesetCookie
method is used to set a cookie value with the cookie name.void
This is used as a convenience method for adding a header that needs to be parsed into a HTTP date string.void
setInteger
(String name, int value) This can be used to set a HTTP message header to this object.void
This can be used to set a HTTP message header to this object.void
This can be used to set a HTTP message header to this object.
-
Field Details
-
cookies
This is used to store the cookies added to the HTTP header. -
values
This is used to store multiple header values for a name. -
names
This is used to store the individual names for the header. -
parser
This is used to parse all date headers added to the message.
-
-
Constructor Details
-
MessageHeader
public MessageHeader()Constructor for theMessage
object. This is used to create a case insensitive means for storing HTTP header names and values. Dates can also be added to message as a long value and is converted to RFC 1123 compliant date string.
-
-
Method Details
-
getNames
This is used to acquire the names of the of the headers that have been set in the response. This can be used to acquire all header values by name that have been set within the response. If no headers have been set this will return an empty list. -
setValue
This can be used to set a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using thegetValue
in combination with the get methods. This will perform aremove
using the issued header name before the header value is set. -
setInteger
This can be used to set a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using thegetValue
in combination with the get methods. This will perform aremove
using the issued header name before the header value is set.- Specified by:
setInteger
in interfaceMessage
- Parameters:
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will have
-
setLong
This can be used to set a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using thegetValue
in combination with the get methods. This will perform aremove
using the issued header name before the header value is set.- Parameters:
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will have
-
setDate
This is used as a convenience method for adding a header that needs to be parsed into a HTTP date string. This will convert the date given into a date string defined in RFC 2616 sec 3.3.1. This will perform aremove
using the issued header name before the header value is set. -
addValue
This can be used to add a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using thegetValue
in combination with the get methods. -
addInteger
This can be used to add a HTTP message header to this object. The name and value of the HTTP message header will be used to create a HTTP message header object which can be retrieved using thegetInteger
in combination with the get methods.- Specified by:
addInteger
in interfaceMessage
- Parameters:
name
- the name of the HTTP message header to be addedvalue
- the value the HTTP message header will have
-
addDate
This is used as a convenience method for adding a header that needs to be parsed into a HTTPdate string. This will convert the date given into a date string defined in RFC 2616 sec 3.3.1. -
getValue
This can be used to get the value of the first message header that has the specified name. This will return the full string representing the named header value. If the named header does not exist then this will return a null value. -
getValue
This can be used to get the value of the first message header that has the specified name. This will return the full string representing the named header value. If the named header does not exist then this will return a null value. -
getInteger
This can be used to get the value of the first message header that has the specified name. This will return the integer representing the named header value. If the named header does not exist then this will return a value of minus one, -1.- Specified by:
getInteger
in interfaceMessage
- Parameters:
name
- the HTTP message header to get the value from- Returns:
- this returns the value that the HTTP message header
-
getLong
This can be used to get the value of the first message header that has the specified name. This will return the long representing the named header value. If the named header does not exist then this will return a value of minus one, -1.- Parameters:
name
- the HTTP message header to get the value from- Returns:
- this returns the value that the HTTP message header
-
getDate
This can be used to get the value of the first message header that has the specified name. This will return the long value representing the named header value. If the named header does not exist then this will return a value of minus one, -1. -
getCookie
This returns theCookie
object stored under the specified name. This is used to retrieve cookies that have been set with thesetCookie
methods. If the cookie does not exist under the specified name this will return null. -
getCookies
This returns allCookie
objects stored under the specified name. This is used to retrieve cookies that have been set with thesetCookie
methods. If there are no cookies then this will return an empty list.- Specified by:
getCookies
in interfaceMessage
- Returns:
- returns all the
Cookie
in the response
-
setCookie
ThesetCookie
method is used to set a cookie value with the cookie name. This will add a cookie to the response stored under the name of the cookie, when this is committed it will be added as a Set-Cookie header to the resulting response. This is a convenience method that avoids cookie creation. -
setCookie
ThesetCookie
method is used to set a cookie value with the cookie name. This will add a cookie to the response stored under the name of the cookie, when this is committed it will be added as a Set-Cookie header to the resulting response. -
getValues
This can be used to get the values of HTTP message headers that have the specified name. This is a convenience method that will present that values as tokens extracted from the header. This has obvious performance benefits as it avoids having to deal withsubstring
andtrim
calls.The tokens returned by this method are ordered according to there HTTP quality values, or "q" values, see RFC 2616 section 3.9. This also strips out the quality parameter from tokens returned. So "image/html; q=0.9" results in "image/html". If there are no "q" values present then order is by appearance.
The result from this is either the trimmed header value, that is, the header value with no leading or trailing whitespace or an array of trimmed tokens ordered with the most preferred in the lower indexes, so index 0 is has highest preference.
-
getValues
This can be used to get the values of HTTP message headers that have the specified name. This is a convenience method that will present that values as tokens extracted from the header. This has obvious performance benefits as it avoids having to deal withsubstring
andtrim
calls.The tokens returned by this method are ordered according to there HTTP quality values, or "q" values, see RFC 2616 section 3.9. This also strips out the quality parameter from tokens returned. So "image/html; q=0.9" results in "image/html". If there are no "q" values present then order is by appearance.
The result from this is either the trimmed header value, that is, the header value with no leading or trailing whitespace or an array of trimmed tokens ordered with the most preferred in the lower indexes, so index 0 is has highest preference.
-
getAll
This is used to acquire all the individual header values from the message. The header values provided by this are unparsed and represent the actual string values that have been added to the message keyed by a given header name. -
getAll
This is used to acquire all the individual header values from the message. The header values provided by this are unparsed and represent the actual string values that have been added to the message keyed by a given header name.- Parameters:
name
- the name of the header to get the values fortoken
- this provides a lower case version of the header- Returns:
- this returns a list of the values for the header name
-