public class Response extends Object
This class represents the single response (which may have any content model that a RequestHandler
chooses
to implement) of some single request. Contrary to the Request
class, this has no active reference to the
parent Container
(this is tracked internally by counting the number of requests vs the number of responses
seen). The ResponseHandler
of a Response is implicit in the invocation of RequestHandler.handleRequest(Request, ResponseHandler)
.
The usage pattern of the Response is similar to that of the Request in that the ResponseHandler
returns a
ContentChannel
into which to write the Response content.
Request
,
ResponseHandler
Modifier and Type | Class and Description |
---|---|
static interface |
Response.Status
This interface acts as a namespace for the built-in status codes of the jDISC core.
|
Modifier and Type | Field and Description |
---|---|
private Map<String,Object> |
context |
private Throwable |
error |
private HeaderFields |
headers |
private int |
status |
Constructor and Description |
---|
Response(int status)
Creates a new instance of this class.
|
Response(int status,
Throwable error)
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
Map<String,Object> |
context()
Returns the named application context objects.
|
static void |
dispatchTimeout(ResponseHandler handler)
This is a convenience method for creating a Response with status
Response.Status.GATEWAY_TIMEOUT and passing
that to the given ResponseHandler.handleResponse(Response) . |
Throwable |
getError()
Returns the error of this response, or null if none has been set.
|
int |
getStatus()
Returns the status code of this response.
|
HeaderFields |
headers()
Returns the set of header fields of this Request.
|
Response |
setError(Throwable error)
Sets the error of this response.
|
Response |
setStatus(int status)
Sets the status code of this response.
|
private final HeaderFields headers
private Throwable error
private int status
public Response(int status)
Creates a new instance of this class.
status
- The status code to assign to this.public Response(int status, Throwable error)
Creates a new instance of this class.
status
- The status code to assign to this.error
- The error to assign to this.public Map<String,Object> context()
Returns the named application context objects. This data is not intended for network transport, rather they are intended for passing shared data between components of an Application.
Modifying the context map is a thread-unsafe operation -- any changes made after calling ResponseHandler.handleResponse(Response)
might never become visible to other threads, and might throw
ConcurrentModificationExceptions in other threads.
public HeaderFields headers()
Returns the set of header fields of this Request. These are the meta-data of the Request, and are not applied
to any internal Container
logic. Modifying headers is a thread-unsafe operation -- any changes made after
calling ResponseHandler.handleResponse(Response)
might never become visible to other threads, and might
throw ConcurrentModificationExceptions in other threads.
public int getStatus()
Returns the status code of this response. This is an integer result code of the attempt to understand and
satisfy the corresponding Request
. It is encouraged, although not enforced, to use the built-in Response.Status
codes whenever possible.
setStatus(int)
public Response setStatus(int status)
Sets the status code of this response. This is an integer result code of the attempt to understand and
satisfy the corresponding Request
. It is encouraged, although not enforced, to use the built-in Response.Status
codes whenever possible.
Because access to this field is not guarded by any lock, any changes made after calling ResponseHandler.handleResponse(Response)
might never become visible to other threads.
status
- The status code to set.getStatus()
public Throwable getError()
Returns the error of this response, or null if none has been set. This is typically non-null if the status indicates an unsuccessful response.
getError()
public Response setError(Throwable error)
Sets the error of this response. It is encouraged, although not enforced, to use this field to attach additional information to an unsuccessful response.
Because access to this field is not guarded by any lock, any changes made after calling ResponseHandler.handleResponse(Response)
might never become visible to other threads.
error
- The error to set.getError()
public static void dispatchTimeout(ResponseHandler handler)
Response.Status.GATEWAY_TIMEOUT
and passing
that to the given ResponseHandler.handleResponse(Response)
. For trivial implementations of RequestHandler.handleTimeout(Request, ResponseHandler)
, simply call this method.handler
- The handler to pass the timeout Response
to.Copyright © 2018. All rights reserved.