Class MessageHeader
- java.lang.Object
-
- org.simpleframework.http.message.MessageHeader
-
- All Implemented Interfaces:
Message
public class MessageHeader extends java.lang.Object implements Message
TheMessage
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.- Author:
- Niall Gallagher
-
-
Constructor Summary
Constructors Constructor Description MessageHeader()
Constructor for theMessage
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDate(java.lang.String name, long date)
This is used as a convenience method for adding a header that needs to be parsed into a HTTPdate string.void
addInteger(java.lang.String name, int value)
This can be used to add a HTTP message header to this object.void
addValue(java.lang.String name, java.lang.String value)
This can be used to add a HTTP message header to this object.java.util.List<java.lang.String>
getAll(java.lang.String name)
This is used to acquire all the individual header values from the message.Cookie
getCookie(java.lang.String name)
This returns theCookie
object stored under the specified name.java.util.List<Cookie>
getCookies()
This returns allCookie
objects stored under the specified name.long
getDate(java.lang.String name)
This can be used to get the value of the first message header that has the specified name.int
getInteger(java.lang.String name)
This can be used to get the value of the first message header that has the specified name.long
getLong(java.lang.String name)
This can be used to get the value of the first message header that has the specified name.java.util.List<java.lang.String>
getNames()
This is used to acquire the names of the of the headers that have been set in the response.java.lang.String
getValue(java.lang.String name)
This can be used to get the value of the first message header that has the specified name.java.lang.String
getValue(java.lang.String name, int index)
This can be used to get the value of the first message header that has the specified name.java.util.List<java.lang.String>
getValues(java.lang.String name)
This can be used to get the values of HTTP message headers that have the specified name.java.util.List<java.lang.String>
getValues(java.util.List<java.lang.String> list)
This can be used to get the values of HTTP message headers that have the specified name.Cookie
setCookie(java.lang.String name, java.lang.String value)
ThesetCookie
method is used to set a cookie value with the cookie name.Cookie
setCookie(Cookie cookie)
ThesetCookie
method is used to set a cookie value with the cookie name.void
setDate(java.lang.String name, long date)
This is used as a convenience method for adding a header that needs to be parsed into a HTTP date string.void
setInteger(java.lang.String name, int value)
This can be used to set a HTTP message header to this object.void
setLong(java.lang.String name, long value)
This can be used to set a HTTP message header to this object.void
setValue(java.lang.String name, java.lang.String value)
This can be used to set a HTTP message header to this object.
-
-
-
Method Detail
-
getNames
public java.util.List<java.lang.String> 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
public void setValue(java.lang.String name, java.lang.String value)
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
public void setInteger(java.lang.String name, int value)
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
public void setLong(java.lang.String name, long value)
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
public void setDate(java.lang.String name, long date)
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
public void addValue(java.lang.String name, java.lang.String value)
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
public void addInteger(java.lang.String name, int value)
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
public void addDate(java.lang.String name, long date)
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
public java.lang.String getValue(java.lang.String name)
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
public java.lang.String getValue(java.lang.String name, int index)
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
public int getInteger(java.lang.String name)
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
public long getLong(java.lang.String name)
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
public long getDate(java.lang.String name)
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
public Cookie getCookie(java.lang.String name)
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
public java.util.List<Cookie> 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
public Cookie setCookie(java.lang.String name, java.lang.String value)
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
public Cookie setCookie(Cookie cookie)
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
public java.util.List<java.lang.String> getValues(java.lang.String name)
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
public java.util.List<java.lang.String> getValues(java.util.List<java.lang.String> list)
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
public java.util.List<java.lang.String> getAll(java.lang.String name)
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.
-
-