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
class ResponseMessage extends MessageHeader implements ResponseHeader
TheResponseMessage
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
Fields Modifier and Type Field Description private int
code
This is the status code used to identify the response type.private int
major
This is the major protocol version used for the response.private int
minor
This is the minor protocol version used for the response.private java.lang.String
text
This is the text description used for the response status.
-
Constructor Summary
Constructors Constructor Description ResponseMessage()
Constructor for theResponseMessage
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getCode()
This represents the status code of the HTTP response.long
getContentLength()
This is a convenience method that can be used to determine the length of the message body.ContentType
getContentType()
This is a convenience method that can be used to determine the content type of the message body.java.lang.String
getDescription()
This can be used to retrieve the text of a HTTP status line.java.lang.CharSequence
getHeader()
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.Status
getStatus()
This is used to acquire the status from the response.java.lang.String
getTransferEncoding()
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(java.lang.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
setStatus(Status status)
This is used to set the status code and description for this response.java.lang.String
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 Detail
-
text
private java.lang.String text
This is the text description used for the response status.
-
major
private int major
This is the major protocol version used for the response.
-
minor
private int minor
This is the minor protocol version used for the response.
-
code
private int code
This is the status code used to identify the response type.
-
-
Method Detail
-
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
public java.lang.String 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
public void setDescription(java.lang.String text)
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
public 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
public void setStatus(Status status)
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
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-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
public java.lang.String 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
public java.lang.CharSequence 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
public java.lang.String 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 classjava.lang.Object
- Returns:
- a string representation of the response message
-
-