Package org.restheart.exchange
Class Request<T>
java.lang.Object
org.restheart.exchange.Exchange<T>
org.restheart.exchange.Request<T>
- Type Parameters:
T- generic type
- Direct Known Subclasses:
ProxyRequest,ServiceRequest
The root class for implementing a Request providing the implementation for
common methods
- Author:
- Andrea Di Cesare <andrea@softinstigate.com>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final io.undertow.util.AttachmentKey<PipelineInfo> static final Stringstatic final StringFields 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddXForwardedHeader(String key, String value) Add the header X-Forwarded-[key] to the proxied request; use it to pass to the backend information otherwise lost proxying the request.voidIf called BEFORE authentication, the request will be aborted with a 429 Too Many Requests response.io.undertow.security.idm.Accountstatic StringgetContentType(io.undertow.server.HttpServerExchange exchange) io.undertow.server.handlers.Cookienote: an header can have multiple values.io.undertow.util.HeaderMapgetPath()getPathParam(String pathTemplate, String paramName) get a path parameter using a path template eg pathTemplate=/foo/{id}, paramName=id and URI=/foo/bar => returns bargetPathParams(String pathTemplate) get path parameters using a template pathTemplate=/foo/{id} and URI=/foo/bar => returns a map with id=barstatic PipelineInfogetPipelineInfo(io.undertow.server.HttpServerExchange exchange) getQueryParameterOfDefault(String name, String defaultValue) Deprecated.getQueryParameterOrDefault(String name, String defaultValue) longgetURL()booleanhelper method to check if request is authenticatedbooleanbooleanisDelete()helper method to check request methodbooleanisGet()helper method to check request methodbooleanhelper method to check request methodbooleanisPatch()helper method to check request methodbooleanisPost()helper method to check request methodbooleanisPut()helper method to check request methodstatic Requestof(io.undertow.server.HttpServerExchange exchange) static PipelineInfopipelineInfo(io.undertow.server.HttpServerExchange exchange) protected voidsetContentLength(int length) voidsetContentType(String responseContentType) voidsets Content-Type=application/jsonvoidnote: an header can have multiple values.voidnote: an header can have multiple values.static voidsetPipelineInfo(io.undertow.server.HttpServerExchange exchange, PipelineInfo pipelineInfo) voidsetPipelineInfo(PipelineInfo pipelineInfo) voidsetStartTime(Long requestStartTime) Methods 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
-
SLASH
- See Also:
-
PATCH
- See Also:
-
UNDERSCORE
- See Also:
-
PIPELINE_INFO_KEY
-
-
Constructor Details
-
Request
protected Request(io.undertow.server.HttpServerExchange exchange)
-
-
Method Details
-
of
-
getContentType
-
getPath
- Returns:
- the request path
-
getURL
- Returns:
- the request URL
-
getQueryString
- Returns:
- the query string
-
getMethod
- Returns:
- the request method
-
getRequestContentLength
public long getRequestContentLength()- Returns:
- a content lenght
-
getQueryParameters
- Returns:
- a mutable map of query parameters
-
getQueryParameterOfDefault
Deprecated.usegetQueryParameterOrDefault(java.lang.String, java.lang.String)instead This method contains a typo in the name and will be removed in a future release- Parameters:
name- the name of the query parameterdefaultValue- the default value of the query parameter to be used if request does not specifies it- Returns:
- the value of the query parameter or defaultValue if not present
-
getQueryParameterOrDefault
- Parameters:
name- the name of the query parameterdefaultValue- the default value to return if the query parameter is not present- Returns:
- the value of the query parameter or defaultValue if not present
-
getHeaders
public io.undertow.util.HeaderMap getHeaders()- Returns:
- the request headers
-
getHeader
note: an header can have multiple values. This only returns the first one. use getHeaders() to get all the header's values- Parameters:
name- the name of the header to return- Returns:
- the first value of the header
-
setHeader
note: an header can have multiple values. This sets the given value clearing existing ones. use getHeaders().add(value) to add the value without clearing.- Parameters:
name- the name of the header to returnvalue-
-
setHeader
note: an header can have multiple values. This sets the given value clearing existing ones. use getHeaders().add(value) to add the value without clearing.- Parameters:
name- the name of the header to returnvalue-
-
getCookie
- Parameters:
name- the name of the cookie to return- Returns:
- a the cookie
-
getPathParams
get path parameters using a template pathTemplate=/foo/{id} and URI=/foo/bar => returns a map with id=bar- Parameters:
pathTemplate- the path template- Returns:
- the path parameters
-
getPathParam
get a path parameter using a path template eg pathTemplate=/foo/{id}, paramName=id and URI=/foo/bar => returns bar- Parameters:
pathTemplate- the path templateparamName- name of parameter- Returns:
- the path parameter
-
getContentType
- Specified by:
getContentTypein classExchange<T>- Returns:
- the request ContentType
-
setContentType
- Parameters:
responseContentType- the responseContentType to set
-
setContentTypeAsJson
public void setContentTypeAsJson()sets Content-Type=application/json -
setContentLength
protected void setContentLength(int length) -
getStartTime
- Returns:
- the requestStartTime
-
setStartTime
- Parameters:
requestStartTime- the requestStartTime to set
-
getAuthenticatedAccount
public io.undertow.security.idm.Account getAuthenticatedAccount()- Returns:
- the authenticatedAccount
-
isAuthenticated
public boolean isAuthenticated()Description copied from class:Exchangehelper method to check if request is authenticated- Overrides:
isAuthenticatedin classExchange<T>- Returns:
- true if account is authenticated
-
addXForwardedHeader
Add the header X-Forwarded-[key] to the proxied request; use it to pass to the backend information otherwise lost proxying the request.- Parameters:
key-value-
-
getXForwardedHeaders
-
pipelineInfo
- Parameters:
exchange-- Returns:
- the PipelineInfo that allows to know which pipeline (service, proxy or static resource) is handling the exchange
-
setPipelineInfo
public static void setPipelineInfo(io.undertow.server.HttpServerExchange exchange, PipelineInfo pipelineInfo) - Parameters:
exchange- the exchange to bind the pipelineInfo topipelineInfo- the pipelineInfo to set
-
getPipelineInfo
- Returns:
- the PipelineInfo that allows to know which pipeline (service, proxy or static resource) is handling the exchange
-
getPipelineInfo
- Parameters:
exchange-- Returns:
- the PipelineInfo that allows to know which pipeline (service, proxy or static resource) is handling the exchange
-
setPipelineInfo
- Parameters:
pipelineInfo- the pipelineInfo to set
-
isDelete
public boolean isDelete()helper method to check request method- Returns:
- true if method is METHOD.DELETE
-
isGet
public boolean isGet()helper method to check request method- Returns:
- true if method is METHOD.GET
-
isOptions
public boolean isOptions()helper method to check request method- Returns:
- true if method is METHOD.OPTIONS
-
isPatch
public boolean isPatch()helper method to check request method- Returns:
- true if method is METHOD.PATCH
-
isPost
public boolean isPost()helper method to check request method- Returns:
- true if method is METHOD.POST
-
isPut
public boolean isPut()helper method to check request method- Returns:
- true if method is METHOD.PUT
-
blockForTooManyRequests
public void blockForTooManyRequests()If called BEFORE authentication, the request will be aborted with a 429 Too Many Requests response. -
isBlockForTooManyRequests
public boolean isBlockForTooManyRequests()- Returns:
- true if the request is blocked for too many requests
-
getQueryParameterOrDefault(java.lang.String, java.lang.String)instead This method contains a typo in the name and will be removed in a future release