Package org.omegazero.http.common
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
Represents a generic HTTP request or response message, agnostic of the HTTP version used.
- Since:
- 1.2.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Whether the data for thisHTTPMessage
is transferred in chunks instead of a blob with a predetermined size.protected final long
protected String
The HTTP version string.protected boolean
SeeisLocked()
.protected HTTPMessage
SeegetOther()
.Fields inherited from class org.omegazero.http.common.HTTPHeaderContainer
headerFields
Fields inherited from class org.omegazero.common.util.SimpleAttachmentContainer
attachments
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
HTTPMessage
(String httpVersion, HTTPHeaderContainer headers) Creates a newHTTPMessage
with the given headers.HTTPMessage
(HTTPMessage msg) Copies the givenHTTPMessage
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
May be implemented by subclasses to prevent changing header data in certain situations.long
Returns the time thisHTTPMessage
object was created, as returned bySystem.currentTimeMillis()
.Returns the HTTP version declared in thisHTTPMessage
.getOther()
Returns the otherHTTPMessage
of the HTTP message exchange thisHTTPMessage
is part of.boolean
Returns whether the message body is chunked, as set bysetChunkedTransfer(boolean)
or by the application that created thisHTTPMessage
object.boolean
isLocked()
void
lock()
Locks thisHTTPMessage
, which will cause any method that changes the state of this object (for example, setters) to throw anIllegalStateException
.void
setChunkedTransfer
(boolean chunkedTransfer) Sets whether the body of this message should be chunked.void
setHttpVersion
(String httpVersion) Sets the HTTP version string of thisHTTPMessage
.void
setOther
(HTTPMessage other) Sets theHTTPMessage
returned bygetOther()
.Methods inherited from class org.omegazero.http.common.HTTPHeaderContainer
addHeader, addHeader, appendHeader, appendHeader, appendHeader, deleteHeader, deleteHeader, editHeader, extractHeader, extractHeaders, fromLegacy, getHeader, getHeader, getHeader, getHeader, getHeaderCount, headerExists, headerIterator, headerNameCount, headerNameSet, headers, headerSet, setHeader, toString
Methods inherited from class org.omegazero.common.util.SimpleAttachmentContainer
getAttachment, hasAttachment, removeAttachment, setAttachment
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.omegazero.common.util.AttachmentContainer
requireAttachment
-
Field Details
-
createdTime
protected final long createdTime -
httpVersion
The HTTP version string. -
chunkedTransfer
protected boolean chunkedTransferWhether the data for thisHTTPMessage
is transferred in chunks instead of a blob with a predetermined size. SeeisChunkedTransfer()
. -
other
SeegetOther()
. -
locked
protected transient boolean lockedSeeisLocked()
.
-
-
Constructor Details
-
HTTPMessage
Creates a newHTTPMessage
with the given headers.Note that no deep copy of the headers will be created, meaning changes made to the given
HTTPHeaderContainer
will reflect on thisHTTPMessage
.- Parameters:
httpVersion
- The HTTP version string sent in this messageheaders
- The HTTP headers, ornull
to create an empty set of headers
-
HTTPMessage
Copies the givenHTTPMessage
.The following properties are not copied:
- The creation time
- The
HTTPMessage
returned bygetOther()
- The locked state
- Parameters:
msg
- TheHTTPMessage
to copy from- See Also:
-
-
Method Details
-
getCreatedTime
public long getCreatedTime()Returns the time thisHTTPMessage
object was created, as returned bySystem.currentTimeMillis()
.- Returns:
- The creation time of this object in milliseconds
-
getHttpVersion
Returns the HTTP version declared in thisHTTPMessage
.- Returns:
- The HTTP version string
- See Also:
-
setHttpVersion
Sets the HTTP version string of thisHTTPMessage
.- Parameters:
httpVersion
- The new HTTP version string- Throws:
IllegalStateException
- If thisHTTPMessage
is locked- See Also:
-
isChunkedTransfer
public boolean isChunkedTransfer()Returns whether the message body is chunked, as set bysetChunkedTransfer(boolean)
or by the application that created thisHTTPMessage
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 usingHTTPMessageData.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
Returns the otherHTTPMessage
of the HTTP message exchange thisHTTPMessage
is part of. This may benull
.For example, for
HTTPRequest
s, this would be the response of the request, and vice versa.- Returns:
- The other
HTTPMessage
involved in the HTTP message exchange
-
setOther
Sets theHTTPMessage
returned bygetOther()
.- Parameters:
other
- The otherHTTPMessage
-
isLocked
public boolean isLocked()- Returns:
true
if thisHTTPMessage
is locked- See Also:
-
lock
public void lock()Locks thisHTTPMessage
, which will cause any method that changes the state of this object (for example, setters) to throw anIllegalStateException
.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 anIllegalStateException
.- Overrides:
checkLocked
in classHTTPHeaderContainer
-