M
- The sub-type of this message.public interface Message<M extends Message<M>> extends Closeable
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:
Filter
: Production and forwarding of a new Response
instance
in one of the callbacks (Function
/ AsyncFunction
)
attached to a promise, instead of the given response
parameter.response
because a different type
(not Response
) has to be returned.Closeables.closeSilently(Closeable...)
Modifier and Type | Method and Description |
---|---|
M |
addHeaders(Header... headers)
Add one or more headers to the request.
|
void |
close()
Closes all resources associated with the entity.
|
Entity |
getEntity()
Returns the entity.
|
Headers |
getHeaders()
Returns the headers.
|
String |
getVersion()
Returns the protocol version.
|
M |
modifyHeaders(Consumer<Headers> headersConsumer)
Interact with the
Headers object from the Message.getHeaders() in a fluent way. |
M |
putHeaders(Header... headers)
Put one or more headers to the request.
|
M |
setEntity(Object o)
Sets the content of the entity to the provided value.
|
M |
setVersion(String version)
Sets the protocol version.
|
Entity getEntity()
Headers getHeaders()
M modifyHeaders(Consumer<Headers> headersConsumer)
Headers
object from the Message.getHeaders()
in a fluent way.headersConsumer
- A consumer function.M addHeaders(Header... headers)
headers
- The headers.M putHeaders(Header... headers)
headers
- The headers.String getVersion()
HTTP/1.1
.M setEntity(Object o)
Content-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 calling
Entity.setRawContentInputStream(org.forgerock.http.io.BranchingInputStream)
byte[]
- equivalent to calling Entity.setBytes(byte[])
String
- equivalent to calling Entity.setString(java.lang.String)
Object
- equivalent to calling Entity.setJson(java.lang.Object)
.
Note: This method does not attempt to encode the entity based-on any
codings specified in the Content-Encoding
header.
o
- The object whose value should be stored in the entity.M setVersion(String version)
HTTP/1.1
.version
- The protocol version.void close()
close
in interface AutoCloseable
close
in interface Closeable
Entity.close()
Copyright © 2010-2018, ForgeRock All Rights Reserved.