Interface Message<M extends Message<M>>
- Type Parameters:
M
- The sub-type of this message.
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Implementing Classes:
MessageImpl
,Request
,Response
A message is a resource container, and thus needs to be closed in order to free-up acquired resources.
Please carefully note the following regarding closing a message:
the asynchronous nature of both Handler
and Filter
that produce
promises of Response
make it impossible to know,
for the producer of the message, when it can be closed. Thus, the responsibility of closing the message
is on the final consumer: the point after which the message is no longer used.
Example of such situations:
- In a
Filter
: Production and forwarding of a newResponse
instance in one of the callbacks (Function
/AsyncFunction
) attached to a promise, instead of the givenresponse
parameter. - When consuming/extracting something out of a
response
because a different type (notResponse
) has to be returned.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddHeaders
(Header... headers) Add one or more headers to the message.void
close()
Closes all resources associated with the entity.Returns the entity.Returns the headers.Returns the protocol version.modifyHeaders
(Consumer<Headers> headersConsumer) Interact with theHeaders
object from thegetHeaders()
in a fluent way.putHeaders
(Header... headers) Put one or more headers to the message.Sets the content of the entity to the provided value.setVersion
(String version) Sets the protocol version.
-
Method Details
-
getEntity
Entity getEntity()Returns the entity.- Returns:
- The entity.
-
getHeaders
Headers getHeaders()Returns the headers.- Returns:
- The headers.
-
modifyHeaders
Interact with theHeaders
object from thegetHeaders()
in a fluent way.- Parameters:
headersConsumer
- A consumer function.- Returns:
- This message.
-
addHeaders
Add one or more headers to the message.- Parameters:
headers
- The headers.- Returns:
- This message.
-
putHeaders
Put one or more headers to the message. This will overwrite any existing header values for the names of the headers provided.- Parameters:
headers
- The headers.- Returns:
- This message.
-
getVersion
String getVersion()Returns the protocol version. Default:HTTP/1.1
.- Returns:
- The protocol version.
-
setEntity
Sets the content of the entity to the provided value. Calling this method will close any existing streams associated with the entity. May also set theContent-Length
header, overwriting any existing header.This method is intended mostly as a convenience method within scripts. The parameter will be handled depending on its type as follows:
BranchingInputStream
- equivalent to callingEntity.setRawContentInputStream(org.forgerock.http.io.BranchingInputStream)
byte[]
- equivalent to callingEntity.setBytes(byte[])
String
- equivalent to callingEntity.setString(java.lang.String)
Object
- equivalent to callingEntity.setJson(java.lang.Object)
.
Note: This method does not attempt to encode the entity based-on any codings specified in the
Content-Encoding
header.- Parameters:
o
- The object whose value should be stored in the entity.- Returns:
- This message.
-
setVersion
Sets the protocol version. Default:HTTP/1.1
.- Parameters:
version
- The protocol version.- Returns:
- This message.
-
close
void close()Closes all resources associated with the entity. Any open streams will be closed, and the underlying content reset back to a zero length.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- See Also:
-