Class HTTPMessage

java.lang.Object
org.omegazero.common.util.SimpleAttachmentContainer
org.omegazero.http.common.HTTPHeaderContainer
org.omegazero.http.common.HTTPMessage
All Implemented Interfaces:
Serializable, org.omegazero.common.util.AttachmentContainer
Direct Known Subclasses:
HTTPRequest, HTTPResponse

public abstract class HTTPMessage extends HTTPHeaderContainer
Represents a generic HTTP request or response message, agnostic of the HTTP version used.
Since:
1.2.1
See Also:
  • Field Details

    • createdTime

      protected final long createdTime
    • httpVersion

      protected String httpVersion
      The HTTP version string.
    • chunkedTransfer

      protected boolean chunkedTransfer
      Whether the data for this HTTPMessage is transferred in chunks instead of a blob with a predetermined size. See isChunkedTransfer().
    • other

      protected transient HTTPMessage other
    • locked

      protected transient boolean locked
  • Constructor Details

  • Method Details

    • getCreatedTime

      public long getCreatedTime()
      Returns the time this HTTPMessage object was created, as returned by System.currentTimeMillis().
      Returns:
      The creation time of this object in milliseconds
    • getHttpVersion

      public String getHttpVersion()
      Returns the HTTP version declared in this HTTPMessage.
      Returns:
      The HTTP version string
      See Also:
    • setHttpVersion

      public void setHttpVersion(String httpVersion)
      Sets the HTTP version string of this HTTPMessage.
      Parameters:
      httpVersion - The new HTTP version string
      Throws:
      IllegalStateException - If this HTTPMessage is locked
      See Also:
    • isChunkedTransfer

      public boolean isChunkedTransfer()
      Returns whether the message body is chunked, as set by setChunkedTransfer(boolean) or by the application that created this HTTPMessage object.

      HTTP requests or responses that contain a body may declare their full body size in the Content-Length HTTP header. If the header exists and is valid, the transfer is considered not chunked, otherwise, body data is transferred in chunks and it may be any size in total.

      If this is false, the length of data set using HTTPMessageData.setData(byte[]) must be the same as the original length.

      Returns:
      true if the message body is chunked
    • setChunkedTransfer

      public void setChunkedTransfer(boolean chunkedTransfer)
      Sets whether the body of this message should be chunked.
      Parameters:
      chunkedTransfer - Whether the message body should be chunked
    • getOther

      public HTTPMessage getOther()
      Returns the other HTTPMessage of the HTTP message exchange this HTTPMessage is part of. This may be null.

      For example, for HTTPRequests, this would be the response of the request, and vice versa.

      Returns:
      The other HTTPMessage involved in the HTTP message exchange
    • setOther

      public void setOther(HTTPMessage other)
      Sets the HTTPMessage returned by getOther().
      Parameters:
      other - The other HTTPMessage
    • isLocked

      public boolean isLocked()
      Returns true if this HTTPMessage is locked.
      Returns:
      true if this HTTPMessage is locked
      See Also:
    • lock

      public void lock()
      Locks this HTTPMessage, which will cause any method that changes the state of this object (for example, setters) to throw an IllegalStateException.

      Multiple calls to this method have no additional effect.

      See Also:
    • checkLocked

      protected void checkLocked()
      Description copied from class: HTTPHeaderContainer
      May be implemented by subclasses to prevent changing header data in certain situations. This method is called each time an action that would change any header data is about to be performed. To deny this action, this method should throw an IllegalStateException.
      Overrides:
      checkLocked in class HTTPHeaderContainer