Package org.restheart.exchange
Class ServiceResponse<T>
java.lang.Object
org.restheart.exchange.Exchange<T>
org.restheart.exchange.Response<T>
org.restheart.exchange.ServiceResponse<T>
- Type Parameters:
T
- generic type
- Direct Known Subclasses:
BsonResponse
,ByteArrayResponse
,JsonResponse
,StringResponse
Base class for Response implementations that can be used in service requests.
Only one response object can be instantiated per request. The response object
is instantiated by ServiceExchangeInitializer using the responseInitializer()
function defined by the handling service
- Author:
- Andrea Di Cesare <[email protected]>
-
Field Summary
Fields inherited from class org.restheart.exchange.Exchange
APP_FORM_URLENCODED_TYPE, APPLICATION_PDF_TYPE, HAL_JSON_MEDIA_TYPE, IN_ERROR_KEY, JSON_MEDIA_TYPE, LOGGER, MAX_BUFFERS, MAX_CONTENT_SIZE, MULTIPART_FORM_DATA_TYPE, wrapped
-
Constructor Summary
ModifierConstructorDescriptionprotected
ServiceResponse(io.undertow.server.HttpServerExchange exchange)
-
Method Summary
Modifier and TypeMethodDescriptionSeesetCustomerSender()static ServiceResponse<?>
of(io.undertow.server.HttpServerExchange exchange)
static <R extends ServiceResponse<?>>
Rabstract String
Reads the content as a String.void
setContent(T content)
void
setCustomerSender(Runnable customSender)
If a customSender is set (not null), the handler ResponseSender will delegate to customSender.run() the responsability to send the response content to the clientabstract void
setInError(int code, String message, Throwable t)
Methods inherited from class org.restheart.exchange.Response
getContentType, getContentType, getHeader, getHeader, getHeaders, getMDCContext, getStatusCode, setContentType, setContentTypeAsJson, setHeader, setHeader, setInError, setMDCContext, setStatusCode, type
Methods inherited from class org.restheart.exchange.Exchange
getExchange, getWrappedExchange, isAccountInRole, isAuthenticated, isAuthenticated, isContentTypeJson, isContentTypeText, isContentTypeXml, isInError, isInError, responseInterceptorsExecuted, setInError, setInError, setResponseInterceptorsExecuted, updateBufferSize
-
Field Details
-
-
Constructor Details
-
ServiceResponse
protected ServiceResponse(io.undertow.server.HttpServerExchange exchange)
-
-
Method Details
-
of
-
of
public static <R extends ServiceResponse<?>> R of(io.undertow.server.HttpServerExchange exchange, Class<R> type) -
getContent
-
setContent
-
readContent
Reads the content as a String. This method is used by ResponseSender to generate the response content to send to the client.- Returns:
- the content as string
-
setCustomerSender
If a customSender is set (not null), the handler ResponseSender will delegate to customSender.run() the responsability to send the response content to the client- Parameters:
customSender
-
-
getCustomerSender
SeesetCustomerSender()- Returns:
- the customSender
-
setInError
- Specified by:
setInError
in classResponse<T>
- Parameters:
code
-message
-t
-
-