Package org.forgerock.http.protocol
Class Response
- java.lang.Object
-
- org.forgerock.http.protocol.MessageImpl<Response>
-
- org.forgerock.http.protocol.Response
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Message<Response>
public final class Response extends MessageImpl<Response>
A response message.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Response
addTrailers(Header... trailers)
Add one or more trailers, aka trailing headers, to the response.Exception
getCause()
Returns the (possiblynull
) cause of this error message (assuming it is a 4xx or a 5xx).Status
getStatus()
Returns the response status.Headers
getTrailers()
Returns the trailers, aka trailing headers.boolean
hasStreamingContent()
Indicates that the response's content has to be considered as a streaming and thus some special treatments may apply on it.static Promise<Response,NeverThrowsException>
newResponsePromise(Response response)
Returns aPromise
representing theResponse
for an asynchronousRequest
which has already completed.static PromiseImpl<Response,NeverThrowsException>
newResponsePromiseImpl()
Response
putTrailers(Header... trailers)
Put one or more trailers, aka trailing headers, to the response.Response
setCause(Exception cause)
Link a 'caused by' exception to this response.Response
setEntity(Object o)
Sets the content of the entity to the provided value.Response
setStatus(Status status)
Sets the response status code.Response
setStreamingContent(boolean streamingContent)
Set that the response's content has to be considered as a streaming and thus some special treatments may apply on it.Response
setVersion(String version)
Sets the protocol version.-
Methods inherited from class org.forgerock.http.protocol.MessageImpl
addHeaders, close, getEntity, getHeaders, getVersion, modifyHeaders, putHeaders
-
-
-
-
Constructor Detail
-
Response
public Response(Response response) throws IOException
Creates a defensive copy of the givenresponse
message.- Parameters:
response
- response to be copied- Throws:
IOException
- when entity cannot be cloned
-
Response
public Response(Status status)
Creates a new response with a default status.- Parameters:
status
- The status to use for the Reponse.
-
-
Method Detail
-
newResponsePromise
public static Promise<Response,NeverThrowsException> newResponsePromise(Response response)
Returns aPromise
representing theResponse
for an asynchronousRequest
which has already completed. Attempts to get theResponse
will immediately return without blocking, and any listeners registered against the returned promise will be immediately invoked in the same thread as the caller.- Parameters:
response
- TheResponse
.- Returns:
- A
Promise
representing theResponse
for an asynchronousRequest
which has already completed.
-
newResponsePromiseImpl
public static PromiseImpl<Response,NeverThrowsException> newResponsePromiseImpl()
Creates a new pendingPromise
implementation representing theResponse
for an asynchronousRequest
. The returnedPromiseImpl
must be completed once theResponse
is received by invoking thehandleResult
method.- Returns:
- A new pending
Promise
implementation representing theResponse
for an asynchronousRequest
.
-
getStatus
public Status getStatus()
Returns the response status.- Returns:
- The response status.
-
getCause
public Exception getCause()
Returns the (possiblynull
) cause of this error message (assuming it is a 4xx or a 5xx).- Returns:
- the (possibly
null
) cause of this error message (assuming it is a 4xx or a 5xx).
-
setCause
public Response setCause(Exception cause)
Link a 'caused by' exception to this response. That can be used to determine if this error response was triggered by an exception (as opposed to obtained from a remote server). Note: this method does not change thestatus
of this message, neither touch its content. It's up to the caller to ensure consistency (if required in the execution context).- Parameters:
cause
- Cause of this error response- Returns:
- This response.
-
setEntity
public Response setEntity(Object o)
Description copied from interface:Message
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.
-
setStatus
public Response setStatus(Status status)
Sets the response status code.- Parameters:
status
- The response status code.- Returns:
- This response.
-
setVersion
public Response setVersion(String version)
Description copied from interface:Message
Sets the protocol version. Default:HTTP/1.1
.- Parameters:
version
- The protocol version.- Returns:
- This message.
-
hasStreamingContent
public boolean hasStreamingContent()
Indicates that the response's content has to be considered as a streaming and thus some special treatments may apply on it.- Returns:
- true if the response's content has to be considered as a streaming content.
-
setStreamingContent
public Response setStreamingContent(boolean streamingContent)
Set that the response's content has to be considered as a streaming and thus some special treatments may apply on it.- Parameters:
streamingContent
- Is it a streamed content or not ?- Returns:
- This response.
-
getTrailers
public Headers getTrailers()
Returns the trailers, aka trailing headers.- Returns:
- The trailers.
-
addTrailers
public Response addTrailers(Header... trailers)
Add one or more trailers, aka trailing headers, to the response.- Parameters:
trailers
- The trailers to add (not null).- Returns:
- This response.
-
-