Package org.simpleframework.http.core
Class RequestMessage
- java.lang.Object
-
- org.simpleframework.http.core.RequestMessage
-
- All Implemented Interfaces:
RequestHeader,RequestLine
- Direct Known Subclasses:
RequestEntity
class RequestMessage extends java.lang.Object implements RequestHeader
TheRequestMessageobject is used to create a HTTP request header representation. All requests for details within a request message delegates to an underlying header, which contains all of the header names and values sent by the client. The header names are case insensitively mapped as required by RFC 2616.
-
-
Constructor Summary
Constructors Constructor Description RequestMessage()Constructor for theRequestMessageobject.RequestMessage(Header header)Constructor for theRequestMessageobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AddressgetAddress()This is used to acquire the address from the request line.longgetContentLength()This is a convenience method that can be used to determine the length of the message body.ContentTypegetContentType()This is a convenience method that can be used to determine the content type of the message body.CookiegetCookie(java.lang.String name)This is used to acquire a cookie usiing the name of that cookie.java.util.List<Cookie>getCookies()This is used to acquire all cookies that were sent in the header.longgetDate(java.lang.String name)This can be used to get the date of the first message header that has the specified name.java.lang.CharSequencegetHeader()This method returns aCharSequenceholding the header consumed for the request.intgetInteger(java.lang.String name)This can be used to get the integer of the first message header that has the specified name.java.util.List<java.util.Locale>getLocales()This is used to acquire the locales from the request header.intgetMajor()This can be used to get the major number from a HTTP version.java.lang.StringgetMethod()This can be used to get the HTTP method for this request.intgetMinor()This can be used to get the major number from a HTTP version.java.util.List<java.lang.String>getNames()This method is used to get aListof the names for the headers.PathgetPath()This is used to acquire the path as extracted from the HTTP request URI.QuerygetQuery()This method is used to acquire the query part from the HTTP request URI target.java.lang.StringgetTarget()This can be used to get the URI specified for this HTTP request.java.lang.StringgetValue(java.lang.String name)This can be used to get the value of the first message header that has the specified name.java.lang.StringgetValue(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.lang.StringtoString()This is used to provide a string representation of the header read.
-
-
-
Field Detail
-
header
protected Header header
This is the underlying header used to house the headers.
-
-
Constructor Detail
-
RequestMessage
public RequestMessage()
Constructor for theRequestMessageobject. This is used to create a request message without an underlying header. In such an event it is up to the subclass to provide the instance, this is useful for testing the request.
-
RequestMessage
public RequestMessage(Header header)
Constructor for theRequestMessageobject. This is used to create a request with a header instance. In such a case the header provided will be queried for headers and is used to store headers added to this message instance.- Parameters:
header- this is the backing header for the message
-
-
Method Detail
-
getTarget
public java.lang.String getTarget()
This can be used to get the URI specified for this HTTP request. This corresponds to the /index part of a http://www.domain.com/index URL but may contain the full URL. This is a read only value for the request.- Specified by:
getTargetin interfaceRequestLine- Returns:
- the URI that this HTTP request is targeting
-
getAddress
public Address getAddress()
This is used to acquire the address from the request line. An address is the full URI including the scheme, domain, port and the query parts. This allows various parameters to be acquired without having to parse the raw request target URI.- Specified by:
getAddressin interfaceRequestLine- Returns:
- this returns the address of the request line
-
getPath
public Path getPath()
This is used to acquire the path as extracted from the HTTP request URI. ThePathobject that is provided by this method is immutable, it represents the normalized path only part from the request uniform resource identifier.- Specified by:
getPathin interfaceRequestLine- Returns:
- this returns the normalized path for the request
-
getQuery
public Query getQuery()
This method is used to acquire the query part from the HTTP request URI target. This will return only the values that have been extracted from the request URI target.- Specified by:
getQueryin interfaceRequestLine- Returns:
- the query associated with the HTTP target URI
-
getMethod
public java.lang.String getMethod()
This can be used to get the HTTP method for this request. The HTTP specification RFC 2616 specifies the HTTP request methods in section 9, Method Definitions. Typically this will be a GET, POST or a HEAD method, although any string is possible.- Specified by:
getMethodin interfaceRequestLine- Returns:
- the request method for this request message
-
getMajor
public int getMajor()
This can be used to get the major number from a HTTP version. The major version corresponds to the major type that is the 1 of a HTTP/1.0 version string.- Specified by:
getMajorin interfaceRequestLine- Returns:
- the major version number for the request message
-
getMinor
public int getMinor()
This can be used to get the major number from a HTTP version. The major version corresponds to the major type that is the 0 of a HTTP/1.0 version string. This is used to determine if the request message has keep alive semantics.- Specified by:
getMinorin interfaceRequestLine- Returns:
- the major version number for the request message
-
getNames
public java.util.List<java.lang.String> getNames()
This method is used to get aListof the names for the headers. This will provide the original names for the HTTP headers for the message. Modifications to the provided list will not affect the header, the list is a simple copy.- Specified by:
getNamesin interfaceRequestHeader- Returns:
- this returns a list of the names within the header
-
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. The value provided from this will be trimmed so there is no need to modify the value, also if the header name specified refers to a comma seperated list of values the value returned is the first value in that list. This returns null if theres no HTTP message header.- Specified by:
getValuein interfaceRequestHeader- Parameters:
name- the HTTP message header to get the value from- Returns:
- this returns the value that the HTTP message header
-
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. The value provided from this will be trimmed so there is no need to modify the value, also if the header name specified refers to a comma separated list of values the value returned is the first value in that list. This returns null if theres no HTTP message header.- Specified by:
getValuein interfaceRequestHeader- Parameters:
name- the HTTP message header to get the value fromindex- if there are multiple values this selects one- Returns:
- this returns the value that the HTTP message header
-
getInteger
public int getInteger(java.lang.String name)
This can be used to get the integer of the first message header that has the specified name. This is a convenience method that avoids having to deal with parsing the value of the requested HTTP message header. This returns -1 if theres no HTTP header value for the specified name.- Specified by:
getIntegerin interfaceRequestHeader- Parameters:
name- the HTTP message header to get the value from- Returns:
- this returns the date as a long from the header value
-
getDate
public long getDate(java.lang.String name)
This can be used to get the date of the first message header that has the specified name. This is a convenience method that avoids having to deal with parsing the value of the requested HTTP message header. This returns -1 if theres no HTTP header value for the specified name.- Specified by:
getDatein interfaceRequestHeader- Parameters:
name- the HTTP message header to get the value from- Returns:
- this returns the date as a long from the header value
-
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 benifits as it avoids having to deal withsubstringandtrimcalls.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 appearence.
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 higest preference.
- Specified by:
getValuesin interfaceRequestHeader- Parameters:
name- the name of the headers that are to be retrieved- Returns:
- ordered array of tokens extracted from the header(s)
-
getLocales
public java.util.List<java.util.Locale> getLocales()
This is used to acquire the locales from the request header. The locales are provided in theAccept-Languageheader. This provides an indication as to the languages that the client accepts. It provides the locales in preference order.- Specified by:
getLocalesin interfaceRequestHeader- Returns:
- this returns the locales preferred by the client
-
getCookie
public Cookie getCookie(java.lang.String name)
This is used to acquire a cookie usiing the name of that cookie. If the cookie exists within the HTTP header then it is returned as aCookieobject. Otherwise this method will return null. Each cookie object will contain the name, value and path of the cookie as well as the optional domain part.- Specified by:
getCookiein interfaceRequestHeader- Parameters:
name- this is the name of the cookie object to acquire- Returns:
- this returns a cookie object from the header or null
-
getCookies
public java.util.List<Cookie> getCookies()
This is used to acquire all cookies that were sent in the header. If any cookies exists within the HTTP header they are returned asCookieobjects. Otherwise this method will an empty list. Each cookie object will contain the name, value and path of the cookie as well as the optional domain part.- Specified by:
getCookiesin interfaceRequestHeader- Returns:
- this returns all cookie objects from the HTTP header
-
getContentType
public ContentType getContentType()
This is a convenience method that can be used to determine the content type of the message body. This will determine whether there is aContent-Typeheader, if there is then this will parse that header and represent it as a typed object which will expose the various parts of the HTTP header.- Specified by:
getContentTypein interfaceRequestHeader- Returns:
- this returns the content type value if it exists
-
getContentLength
public long getContentLength()
This is a convenience method that can be used to determine the length of the message body. This will determine if there is aContent-Lengthheader, if it does then the length can be determined, if not then this returns -1.- Specified by:
getContentLengthin interfaceRequestHeader- Returns:
- the content length, or -1 if it cannot be determined
-
getHeader
public java.lang.CharSequence getHeader()
This method returns aCharSequenceholding the header consumed for the request. A character sequence is returned as it can provide a much more efficient means of representing the header data by just wrapping the consumed byte array.- Specified by:
getHeaderin interfaceRequestHeader- Returns:
- this returns the characters consumed for the header
-
toString
public java.lang.String toString()
This is used to provide a string representation of the header read. Providing a string representation of the header is used so that on debugging the contents of the delivered header can be inspected in order to determine a cause of error.- Specified by:
toStringin interfaceRequestHeader- Overrides:
toStringin classjava.lang.Object- Returns:
- this returns a string representation of the header
-
-