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 booleanWhether the data for thisHTTPMessageis transferred in chunks instead of a blob with a predetermined size.protected final longprotected StringThe HTTP version string.protected booleanSeeisLocked().protected HTTPMessageSeegetOther().Fields inherited from class org.omegazero.http.common.HTTPHeaderContainer
headerFieldsFields inherited from class org.omegazero.common.util.SimpleAttachmentContainer
attachments -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedHTTPMessage(String httpVersion, HTTPHeaderContainer headers) Creates a newHTTPMessagewith the given headers.HTTPMessage(HTTPMessage msg) Copies the givenHTTPMessage. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidMay be implemented by subclasses to prevent changing header data in certain situations.longReturns the time thisHTTPMessageobject was created, as returned bySystem.currentTimeMillis().Returns the HTTP version declared in thisHTTPMessage.getOther()Returns the otherHTTPMessageof the HTTP message exchange thisHTTPMessageis part of.booleanReturns whether the message body is chunked, as set bysetChunkedTransfer(boolean)or by the application that created thisHTTPMessageobject.booleanisLocked()voidlock()Locks thisHTTPMessage, which will cause any method that changes the state of this object (for example, setters) to throw anIllegalStateException.voidsetChunkedTransfer(boolean chunkedTransfer) Sets whether the body of this message should be chunked.voidsetHttpVersion(String httpVersion) Sets the HTTP version string of thisHTTPMessage.voidsetOther(HTTPMessage other) Sets theHTTPMessagereturned 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, toStringMethods inherited from class org.omegazero.common.util.SimpleAttachmentContainer
getAttachment, hasAttachment, removeAttachment, setAttachmentMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 thisHTTPMessageis transferred in chunks instead of a blob with a predetermined size. SeeisChunkedTransfer(). -
other
SeegetOther(). -
locked
protected transient boolean lockedSeeisLocked().
-
-
Constructor Details
-
HTTPMessage
Creates a newHTTPMessagewith the given headers.Note that no deep copy of the headers will be created, meaning changes made to the given
HTTPHeaderContainerwill reflect on thisHTTPMessage.- Parameters:
httpVersion- The HTTP version string sent in this messageheaders- The HTTP headers, ornullto create an empty set of headers
-
HTTPMessage
Copies the givenHTTPMessage.The following properties are not copied:
- The creation time
- The
HTTPMessagereturned bygetOther() - The locked state
- Parameters:
msg- TheHTTPMessageto copy from- See Also:
-
-
Method Details
-
getCreatedTime
public long getCreatedTime()Returns the time thisHTTPMessageobject 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 thisHTTPMessageis locked- See Also:
-
isChunkedTransfer
public boolean isChunkedTransfer()Returns whether the message body is chunked, as set bysetChunkedTransfer(boolean)or by the application that created thisHTTPMessageobject.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:
trueif 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 otherHTTPMessageof the HTTP message exchange thisHTTPMessageis part of. This may benull.For example, for
HTTPRequests, this would be the response of the request, and vice versa.- Returns:
- The other
HTTPMessageinvolved in the HTTP message exchange
-
setOther
Sets theHTTPMessagereturned bygetOther().- Parameters:
other- The otherHTTPMessage
-
isLocked
public boolean isLocked()- Returns:
trueif thisHTTPMessageis 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:HTTPHeaderContainerMay 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:
checkLockedin classHTTPHeaderContainer
-