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
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 Details

    • text

      private 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.
  • Constructor Details

    • ResponseMessage

      public ResponseMessage()
      Constructor for the ResponseMessage 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 interface StatusLine
      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 interface StatusLine
      Parameters:
      code - the new status code for the HTTP response
    • getDescription

      public 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 interface StatusLine
      Returns:
      the message description of the response
    • setDescription

      public void setDescription(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 interface StatusLine
      Parameters:
      text - the descriptive text message of the status
    • getStatus

      public Status getStatus()
      This is used to acquire the status from the response. The Status 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 interface StatusLine
      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 interface StatusLine
      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 interface StatusLine
      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 interface StatusLine
      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 interface StatusLine
      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 interface StatusLine
      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 a Content-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 interface ResponseHeader
      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 a Content-Length header, if it does then the length can be determined, if not then this returns -1.
      Specified by:
      getContentLength in interface ResponseHeader
      Returns:
      content length, or -1 if it cannot be determined
    • getTransferEncoding

      public 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 a Transfer-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 interface ResponseHeader
      Returns:
      this returns the transfer encoding value if it exists
    • getHeader

      public 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 interface ResponseHeader
      Returns:
      a string representation of the response message
    • toString

      public 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 interface ResponseHeader
      Overrides:
      toString in class Object
      Returns:
      a string representation of the response message