Package org.restheart.exchange
Class ServiceRequest<T>
java.lang.Object
org.restheart.exchange.Exchange<T>
org.restheart.exchange.Request<T>
org.restheart.exchange.ServiceRequest<T>
- Type Parameters:
T- generic type
- Direct Known Subclasses:
BsonFromCsvRequest,BsonRequest,ByteArrayRequest,GraphQLRequest,JsonRequest,StringRequest,UninitializedRequest
Base class for Request implementations that can be used in service requests.
Only one request object can be instantiated per exchage. The request object
is instantiated by ServiceExchangeInitializer using the requestInitializer()
function defined by the handling service
- Author:
- Andrea Di Cesare <andrea@softinstigate.com>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Tstatic final io.undertow.util.AttachmentKey<Boolean> CONTENT_INJECTED is true if the request body has been already injected. calling setContent() and setFileInputStream() sets CONTENT_INJECTED to true.Fields inherited from class org.restheart.exchange.Request
PATCH, PIPELINE_INFO_KEY, SLASH, UNDERSCOREFields inherited from class org.restheart.exchange.Exchange
APPLICATION_PDF_TYPE, FORM_URLENCODED, HAL_JSON_MEDIA_TYPE, IN_ERROR_KEY, JSON_MEDIA_TYPE, MAX_BUFFERS, MAX_CONTENT_SIZE, MULTIPART, TEXT_PLAIN_CONTENT_TYPE, wrapped -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedServiceRequest(io.undertow.server.HttpServerExchange exchange) -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the content of the request.final booleanbooleanisHandledBy(String serviceName) static ServiceRequest<?> of(io.undertow.server.HttpServerExchange exchange) static <R extends ServiceRequest<?>>
Rabstract TParses the content from the exchange and converts it into an instance of the specified typeT.voidsetContent(T content) final voidsetContentInjected(boolean value) Methods inherited from class org.restheart.exchange.Request
addXForwardedHeader, blockForTooManyRequests, getAuthenticatedAccount, getContentType, getContentType, getCookie, getHeader, getHeaders, getMethod, getPath, getPathParam, getPathParams, getPipelineInfo, getPipelineInfo, getQueryParameterOfDefault, getQueryParameterOrDefault, getQueryParameters, getQueryString, getRequestContentLength, getStartTime, getURL, getXForwardedHeaders, isAuthenticated, isBlockForTooManyRequests, isDelete, isGet, isOptions, isPatch, isPost, isPut, pipelineInfo, setContentLength, setContentType, setContentTypeAsJson, setHeader, setHeader, setPipelineInfo, setPipelineInfo, setStartTimeMethods inherited from class org.restheart.exchange.Exchange
getExchange, getWrappedExchange, isAccountInRole, isAuthenticated, isContentTypeFormOrMultipart, isContentTypeFormOrMultipart, isContentTypeJson, isContentTypeJson, isContentTypeText, isContentTypeXml, isInError, isInError, responseInterceptorsExecuted, setInError, setInError, setResponseInterceptorsExecuted, updateBufferSize
-
Field Details
-
-
CONTENT_INJECTED
CONTENT_INJECTED is true if the request body has been already injected. calling setContent() and setFileInputStream() sets CONTENT_INJECTED to true. calling getContent() or getFileInputStream() when CONTENT_INJECTED=false triggers content injection via MongoRequestContentInjector
-
-
Constructor Details
-
ServiceRequest
protected ServiceRequest(io.undertow.server.HttpServerExchange exchange)
-
-
Method Details
-
of
-
of
public static <R extends ServiceRequest<?>> R of(io.undertow.server.HttpServerExchange exchange, Class<R> type) -
getContent
Retrieves the content of the request. If the content has not been previously read, this method invokesparseContent()to parse and attach the content to the request. If an error occurs during the parsing of the content, the request is marked as errored, indicating that the content could not be successfully parsed and attached.- Returns:
- the content of the request, which may be newly parsed or previously retrieved
- Throws:
BadRequestException
-
setContent
-
parseContent
Parses the content from the exchange and converts it into an instance of the specified typeT. This method retrieves data from the exchange, interprets it according to the expected format, and attempts to convert this data into an object of typeT.- Returns:
- an instance of
Trepresenting the parsed content - Throws:
IOException- if an IO error occursBadRequestException- if the content does not match the expected format for typeT
-
isHandledBy
- Parameters:
serviceName-- Returns:
- true if the request is handled by the specified Service
-
isContentInjected
public final boolean isContentInjected() -
setContentInjected
public final void setContentInjected(boolean value)
-