Package org.simpleframework.http.core
Class ResponseMessage
java.lang.Object
org.simpleframework.http.message.MessageHeader
org.simpleframework.http.core.ResponseMessage
- All Implemented Interfaces:
Message
,ResponseHeader
,StatusLine
- Direct Known Subclasses:
ResponseEntity
The
ResponseMessage
object represents the header used
for a response. This is used to get and set the headers in a case
insensitive manner. It is also used to manage the cookies that are
send and received. Also, the status code and description can also
be set through this object as well as the protocol version.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
This is the status code used to identify the response type.private int
This is the major protocol version used for the response.private int
This is the minor protocol version used for the response.private String
This is the text description used for the response status. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
getCode()
This represents the status code of the HTTP response.long
This is a convenience method that can be used to determine the length of the message body.This is a convenience method that can be used to determine the content type of the message body.This can be used to retrieve the text of a HTTP status line.This is used to compose the HTTP response header.int
getMajor()
This can be used to get the major number from a HTTP version.int
getMinor()
This can be used to get the minor number from a HTTP version.This is used to acquire the status from the response.This is a convenience method that can be used to determine the content type of the message body.void
setCode
(int code) This method allows the status for the response to be changed.void
setDescription
(String text) This is used to set the text of the HTTP status line.void
setMajor
(int major) This can be used to set the major number from a HTTP version.void
setMinor
(int minor) This can be used to get the minor number from a HTTP version.void
This is used to set the status code and description for this response.toString()
This is used to compose the HTTP response header.Methods inherited from class org.simpleframework.http.message.MessageHeader
addDate, addInteger, addValue, getAll, getCookie, getCookies, getDate, getInteger, getLong, getNames, getValue, getValue, getValues, getValues, setCookie, setCookie, setDate, setInteger, setLong, setValue
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.simpleframework.http.ResponseHeader
addDate, addInteger, addValue, getCookie, getCookies, getDate, getInteger, getNames, getValue, getValue, getValues, setCookie, setCookie, setDate, setInteger, setLong, setValue
-
Field Details
-
text
This is the text description used for the response status. -
major
private int majorThis is the major protocol version used for the response. -
minor
private int minorThis is the minor protocol version used for the response. -
code
private int codeThis is the status code used to identify the response type.
-
-
Constructor Details
-
ResponseMessage
public ResponseMessage()Constructor for theResponseMessage
object. This is used to create a response message with a default status code of 200 and a a protocol version of HTTP/1.1. If the response is a different status code or version these can be modified.
-
-
Method Details
-
getCode
public int getCode()This represents the status code of the HTTP response. The response code represents the type of message that is being sent to the client. For a description of the codes see RFC 2616 section 10, Status Code Definitions.- Specified by:
getCode
in interfaceStatusLine
- Returns:
- the status code that this HTTP response has
-
setCode
public void setCode(int code) This method allows the status for the response to be changed. This MUST be reflected the the response content given to the client. For a description of the codes see RFC 2616 section 10, Status Code Definitions.- Specified by:
setCode
in interfaceStatusLine
- Parameters:
code
- the new status code for the HTTP response
-
getDescription
This can be used to retrieve the text of a HTTP status line. This is the text description for the status code. This should match the status code specified by the RFC.- Specified by:
getDescription
in interfaceStatusLine
- Returns:
- the message description of the response
-
setDescription
This is used to set the text of the HTTP status line. This should match the status code specified by the RFC.- Specified by:
setDescription
in interfaceStatusLine
- Parameters:
text
- the descriptive text message of the status
-
getStatus
This is used to acquire the status from the response. TheStatus
object returns represents the code that has been set on the response, it does not necessarily represent the description in the response.- Specified by:
getStatus
in interfaceStatusLine
- Returns:
- this is the response for this status line
-
setStatus
This is used to set the status code and description for this response. Setting the code and description in this manner provides a much more convenient way to set the response status line details.- Specified by:
setStatus
in interfaceStatusLine
- Parameters:
status
- this is the status to set on the response
-
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:
getMajor
in interfaceStatusLine
- Returns:
- the major version number for the request message
-
setMajor
public void setMajor(int major) This can be used to set 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:
setMajor
in interfaceStatusLine
- Parameters:
major
- the major version number for the request message
-
getMinor
public int getMinor()This can be used to get the minor number from a HTTP version. The minor 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:
getMinor
in interfaceStatusLine
- Returns:
- the minor version number for the request message
-
setMinor
public void setMinor(int minor) This can be used to get the minor number from a HTTP version. The minor 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:
setMinor
in interfaceStatusLine
- Parameters:
minor
- the minor version number for the request message
-
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-Type
header, 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:
getContentType
in interfaceResponseHeader
- 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-Length
header, if it does then the length can be determined, if not then this returns -1.- Specified by:
getContentLength
in interfaceResponseHeader
- Returns:
- content length, or -1 if it cannot be determined
-
getTransferEncoding
This is a convenience method that can be used to determine the content type of the message body. This will determine whether there is aTransfer-Encoding
header, if there is then this will parse that header and return the first token in the comma separated list of values, which is the primary value.- Specified by:
getTransferEncoding
in interfaceResponseHeader
- Returns:
- this returns the transfer encoding value if it exists
-
getHeader
This is used to compose the HTTP response header. All of the headers added to the response are added, as well as the cookies to form the response message header. To ensure that the text produces is as required the header names are in the same case as they were added to the response message.- Specified by:
getHeader
in interfaceResponseHeader
- Returns:
- a string representation of the response message
-
toString
This is used to compose the HTTP response header. All of the headers added to the response are added, as well as the cookies to form the response message header. To ensure that the text produces is as required the header names are in the same case as they were added to the response message.- Specified by:
toString
in interfaceResponseHeader
- Overrides:
toString
in classObject
- Returns:
- a string representation of the response message
-