Class Response
- java.lang.Object
-
- com.yahoo.jdisc.Response
-
public class Response extends java.lang.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 theRequest
class, this has no active reference to the parentContainer
(this is tracked internally by counting the number of requests vs the number of responses seen). TheResponseHandler
of a Response is implicit in the invocation ofRequestHandler.handleRequest(Request, ResponseHandler)
.The usage pattern of the Response is similar to that of the Request in that the
ResponseHandler
returns aContentChannel
into which to write the Response content.- Author:
- Simon Thoresen Hult
- See Also:
Request
,ResponseHandler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Response.Status
This interface acts as a namespace for the built-in status codes of the jDISC core.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.Object>
context()
Returns the named application context objects.static void
dispatchTimeout(ResponseHandler handler)
This is a convenience method for creating a Response with statusResponse.Status.GATEWAY_TIMEOUT
and passing that to the givenResponseHandler.handleResponse(Response)
.java.lang.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(java.lang.Throwable error)
Sets the error of this response.Response
setStatus(int status)
Sets the status code of this response.
-
-
-
Constructor Detail
-
Response
public Response(int status)
Creates a new instance of this class.- Parameters:
status
- The status code to assign to this.
-
Response
public Response(int status, java.lang.Throwable error)
Creates a new instance of this class.- Parameters:
status
- The status code to assign to this.error
- The error to assign to this.
-
-
Method Detail
-
context
public java.util.Map<java.lang.String,java.lang.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.- Returns:
- The context map.
-
headers
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 callingResponseHandler.handleResponse(Response)
might never become visible to other threads, and might throw ConcurrentModificationExceptions in other threads.- Returns:
- The header fields.
-
getStatus
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-inResponse.Status
codes whenever possible.- Returns:
- The status code.
- See Also:
setStatus(int)
-
setStatus
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-inResponse.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.- Parameters:
status
- The status code to set.- Returns:
- This, to allow chaining.
- See Also:
getStatus()
-
getError
public java.lang.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.
- Returns:
- The error.
- See Also:
getError()
-
setError
public Response setError(java.lang.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.- Parameters:
error
- The error to set.- Returns:
- This, to allow chaining.
- See Also:
getError()
-
dispatchTimeout
public static void dispatchTimeout(ResponseHandler handler)
This is a convenience method for creating a Response with statusResponse.Status.GATEWAY_TIMEOUT
and passing that to the givenResponseHandler.handleResponse(Response)
. For trivial implementations ofRequestHandler.handleTimeout(Request, ResponseHandler)
, simply call this method.- Parameters:
handler
- The handler to pass the timeoutResponse
to.
-
-