Interface RequestRequestContextAddon<R extends RequestContext<?>>
- All Known Implementing Classes:
SpincastRequestRequestContextAddon
request
.-
Method Summary
Modifier and TypeMethodDescriptionbyte[]
The bytes of the request's body.The raw InputStream of the request's body.The request's body as a String, using theUTF-8
encoding.The Content-Type of the request, if any.Finds the bestContent-Type
to use for a response using the"Accept"
header of the request.Gets the the request cookies values as a Map, using the names of the cookies as the keys.getCookieValue
(String name) Gets the value of a request cookie by name.Return the value of theIf-Modified-Since
header as a Date ornull
if it doesn't exist.Return the value of theIf-Unmodified-Since
header as a Date ornull
if it doesn't exist.Returns theETags
from theIf-Match
header, if any.Returns theETags
from theIf-None-Match
header, if any.Gets the Flash message, if any.Gets the part of the submittedFORM
body that is scoped by the specifiedroot key
.The data submitted as aFORM
body (in general via aPOST
method), as an immutableJsonObject
.The data submitted as aFORM
body (in general via aPOST
method), as aMap
.getFormOrCreate
(String rootKey) Gets the part of the submittedFORM
body that is scoped by the specifiedroot key
.Returns the current full URL, including the queryString, if any.getFullUrl
(boolean keepCacheBusters) Returns the current full URL, including the queryString, if any.If the request has been forwarded, this is going to return the original URL, not the current, forwarded, one.getFullUrlOriginal
(boolean keepCacheBusters) If the request has been forwarded, this is going to return the original URL, not the current, forwarded, one.If a reverse proxy has been used, this URL will contain thescheme
,host
andport
as forwarded by the reserve proxy, not as seen by the user.getFullUrlProxied
(boolean keepCacheBusters) If a reverse proxy has been used, this URL will contain thescheme
,host
andport
as forwarded by the reserve proxy, not as seen by the user.Returns the values of the specified header from the current request or an empty list if not found.getHeaderFirst
(String name) The first value of the specified header from the current request.Returns all headers of the current request.Gets the request'sHTTP method
.getIp()
Gets the IP of the current request.The request's body deserialized to an immutableJsonObject
.<T> T
getJsonBody
(Class<T> clazz) The request's body deserialized to the specifiedclass
.The request's body deserialized to aMap<String, Object>
.Find what the request tells should be the bestLocale
to use for a response, by looking at the"Accept-Language"
header.getPathParam
(String name) A specific value parsed from a dynamic parameter of the route path.The values parsed from the dynamic parameters of the route path.getQueryString
(boolean withQuestionMark) The queryString of the request.getQueryStringParam
(String name) A specific parameter taken from the queryString of the request.The first (and often only) value of a specific parameter taken from the queryString of the request.The parameters taken from the queryString of the request.The path of the request (no querystring).getRequestPath
(boolean keepCacheBusters) The path of the request (no querystring).getStringBody
(String encoding) The request's body as a String, using the specified encoding.getUploadedFileFirst
(String htmlName) The uploaded files of the specified HTML'sname
attribute.The key of the map if the HTML'sname
attribute.getUploadedFiles
(String htmlName) The uploaded files of the specified HTML'sname
attribute.<T> T
getXmlBody
(Class<T> clazz) The request's body deserialized to the specifiedclass
.The request's body deserialized to an immutableJsonObject
.The request's body deserialized to aMap<String, Object>
.boolean
Did we validate that the current user has cookies enabled?boolean
Is there a Flash message?boolean
Will returntrue
if the request specifies thatHTML
is the most appropriate format to return.boolean
isHttps()
Is the request a secure HTTPS one?boolean
Will returntrue
if the request specifies thatJson
is the most appropriate format to return.boolean
Will returntrue
if the request specifies thatplain-text
is the most appropriate format to return.boolean
Will returntrue
if the request specifies thatXML
is the most appropriate format to return.
-
Method Details
-
getHttpMethod
HttpMethod getHttpMethod()Gets the request'sHTTP method
. -
getContentTypeBestMatch
ContentTypeDefaults getContentTypeBestMatch()Finds the bestContent-Type
to use for a response using the"Accept"
header of the request. It will fallback toContentTypeDefaults.TEXT
if nothing more specific is found. -
isJsonShouldBeReturn
boolean isJsonShouldBeReturn()Will returntrue
if the request specifies thatJson
is the most appropriate format to return. -
isHTMLShouldBeReturn
boolean isHTMLShouldBeReturn()Will returntrue
if the request specifies thatHTML
is the most appropriate format to return. -
isXMLShouldBeReturn
boolean isXMLShouldBeReturn()Will returntrue
if the request specifies thatXML
is the most appropriate format to return. -
isPlainTextShouldBeReturn
boolean isPlainTextShouldBeReturn()Will returntrue
if the request specifies thatplain-text
is the most appropriate format to return. -
getLocaleBestMatch
Locale getLocaleBestMatch()Find what the request tells should be the bestLocale
to use for a response, by looking at the"Accept-Language"
header.Note that this will not necessarily be the absolute best
Locale
to used for the user: it will not look at cookies or at any other ways the user may have specified its langague preference! It only look at the request itself.Use
RequestContext.getLocaleToUse()
orLocaleResolver.getLocaleToUse()
directly if you want to know the absolute bestLocale
to use for the user!- Returns:
- the default
Locale
(taken from the configurations) if nothing more specific is found on the request.
-
getHeaders
Returns all headers of the current request. A single header can have multiple values. The implementation is aTreeMap
which iscase insensitive for the keys. The map is immutable. -
getHeader
Returns the values of the specified header from the current request or an empty list if not found.The
name
is case insensitive.The list is immutable.
-
getHeaderFirst
The first value of the specified header from the current request.The
name
is case insensitive.Returns
null
if the header is not found. -
getContentType
String getContentType()The Content-Type of the request, if any.- Returns:
- the
Content-Type
of the request ornull
if none was specified.
-
getFullUrl
String getFullUrl()Returns the current full URL, including the queryString, if any. Cache buster codes are removed, if there were any.In case the request has been forwarded, this will be the *new*, the current URL. Use
getFullUrlOriginal()
to get the original URL, before the request was forwarded.If a reverse proxy has been used, this URL will contain the
scheme
,host
andport
from the original URL, as seen by the user. In general, this is what you want to use in your application. -
getFullUrl
Returns the current full URL, including the queryString, if any.In case the request has been forwarded, this will be the *new*, the current URL. Use
getFullUrlOriginal()
to get the original URL, before the request was forwarded.If a reverse proxy has been used, this URL will contain the
scheme
,host
andport
from the original URL, as seen by the user. In general, this is what you want to use in your application.- Parameters:
keepCacheBusters
- iftrue
, the returned URL will contain the cache buster codes, if there were any. The default behavior is to automatically remove them.
-
getFullUrlOriginal
String getFullUrlOriginal()If the request has been forwarded, this is going to return the original URL, not the current, forwarded, one. Cache buster codes are removed, if there were any.Use
getFullUrl()
to get the current, potentially forwarded URL.If a reverse proxy has been used, this URL will contain the
scheme
,host
andport
from the original URL, as seen by the user. In general, this is what you want to use in your application. -
getFullUrlOriginal
If the request has been forwarded, this is going to return the original URL, not the current, forwarded, one.Use
getFullUrl()
to get the current, potentially forwarded URL.If a reverse proxy has been used, this URL will contain the
scheme
,host
andport
from the original URL, as seen by the user. In general, this is what you want to use in your application.- Parameters:
keepCacheBusters
- iftrue
, the returned URL will contain the cache buster codes, if there were any. The default behavior is to automatically remove them.
-
getFullUrlProxied
String getFullUrlProxied()If a reverse proxy has been used, this URL will contain thescheme
,host
andport
as forwarded by the reserve proxy, not as seen by the user. Cache buster codes are removed, if there were any.If the request has been forwarded, this is going to return the original URL, not the current, forwarded, one.
In general, you should probably use
getFullUrl()
orgetFullUrlOriginal()
instead of this one. -
getFullUrlProxied
If a reverse proxy has been used, this URL will contain thescheme
,host
andport
as forwarded by the reserve proxy, not as seen by the user. Cache buster codes are removed, if there were any.If the request has been forwarded, this is going to return the original URL, not the current, forwarded, one.
In general, you should probably use
getFullUrl()
orgetFullUrlOriginal()
instead of this one.- Parameters:
keepCacheBusters
- iftrue
, the returned URL will contain the cache buster codes, if there were any. The default behavior is to automatically remove them.
-
getRequestPath
String getRequestPath()The path of the request (no querystring). -
getRequestPath
The path of the request (no querystring).- Parameters:
keepCacheBusters
- iftrue
, the returned path will contain the cache buster codes, if there were any. The default behavior is to automatically remove them.
-
getPathParams
The values parsed from the dynamic parameters of the route path. The map is immutable. -
getPathParam
A specific value parsed from a dynamic parameter of the route path. Thename
is case sensitive, since you have easy control over it.- Returns:
- the path param value or
null
if not found.
-
getQueryString
The queryString of the request. Returns an empty String if there is no queryString.- Parameters:
withQuestionMark
- iftrue
and the queryString is not empty, the result will be prefixed with "?".
-
getQueryStringParams
The parameters taken from the queryString of the request. A queryString parameter may have multiple values. Returns an empty list if there is no queryString. The map is immutable. -
getQueryStringParam
A specific parameter taken from the queryString of the request. A queryString parameter may have multiple values. Returns an empty list if the parameter doesn't exist. The list is immutable. -
getQueryStringParamFirst
The first (and often only) value of a specific parameter taken from the queryString of the request. Returnsnull
if the parameter doesn't exist. -
getBodyAsInputStream
InputStream getBodyAsInputStream()The raw InputStream of the request's body. Note that once part of the InputStream is read, it can't be read again! -
getBodyAsByteArray
byte[] getBodyAsByteArray()The bytes of the request's body. Note that once part of the InputStream is read, it can't be read again! -
getBodyAsString
String getBodyAsString()The request's body as a String, using theUTF-8
encoding. Note that once part of the InputStream is read, it can't be read again! -
getStringBody
The request's body as a String, using the specified encoding. Note that once part of the InputStream is read, it can't be read again! -
getJsonBody
JsonObject getJsonBody()The request's body deserialized to an immutableJsonObject
. A validJson
body is expected. Note that once part of the InputStream is read, it can't be read again! -
getJsonBodyAsMap
The request's body deserialized to aMap<String, Object>
. A validJson
body is expected. Note that once part of the InputStream is read, it can't be read again! -
getJsonBody
The request's body deserialized to the specifiedclass
. A validJson
body is expected. Note that once part of the InputStream is read, it can't be read again! -
getXmlBodyAsJsonObject
JsonObject getXmlBodyAsJsonObject()The request's body deserialized to an immutableJsonObject
. A validXML
body is expected. Note that once part of the InputStream is read, it can't be read again! -
getXmlBodyAsMap
The request's body deserialized to aMap<String, Object>
. A validXML
body is expected. Note that once part of the InputStream is read, it can't be read again! -
getXmlBody
The request's body deserialized to the specifiedclass
. A validXML
body is expected. Note that once part of the InputStream is read, it can't be read again! -
getFormBodyRaw
The data submitted as aFORM
body (in general via aPOST
method), as aMap
.The names are case sensitive.
This returns the keys/values as is, without trying to parse the keys as
JsonPaths
.This returns an immutable object! You won't be able to add or remove elements.
-
getFormBodyAsJsonObject
JsonObject getFormBodyAsJsonObject()The data submitted as aFORM
body (in general via aPOST
method), as an immutableJsonObject
.The root keys of the field names and are case sensitive.
The root keys will be parsed as
JsonPaths
to build the finalJsonObject
. For example :user.books[1].name
will be converted to a "user"JsonObject
with a "books" arrays with one book at index "1" and this book has a "name" property.- Returns:
- an immutable instance of
JsonObject
. If you want to get a mutable instance, you can call.clone(true)
on this object.
-
getFormOrCreate
Gets the part of the submittedFORM
body that is scoped by the specifiedroot key
.When an HTML form is submitted, there may be utility fields (such as a CSRF token, etc.) in addition to business logic fields. By using this
getFormOrCreate(String)
you only get the fields which names start with the specifiedroot key
. For example, if this HTML form was submitted:<form> <input type="text" name="csrfToken" value="12345" /> <input type="text" name="myUser.userName" value="Stromgol" /> <input type="text" name="myUser.lastNameName" value="LaPierre" /> ...
... then calling
getFormWithRootKey("myUser")
would return aForm
object containing the "userName" and the "userName" fields, but not the "csrfToken".A
Form
object is in fact aJsonObject
containing the submitted fields and aValidationSet
to store validations performed on it.The same field is returned, everytime this method is called with the same
name
.If the root key is not found in the POSTed data, an empty form will be created.
Never returns
null
.The key are case sensitive.
-
getForm
Gets the part of the submittedFORM
body that is scoped by the specifiedroot key
.When an HTML form is submitted, there may be utility fields (such as a CSRF token, etc.) in addition to business logic fields. By using this
getFormOrCreate(String)
you only get the fields which names start with the specifiedroot key
. For example, if this HTML form was submitted:<form> <input type="text" name="csrfToken" value="12345" /> <input type="text" name="myUser.userName" value="Stromgol" /> <input type="text" name="myUser.lastNameName" value="LaPierre" /> ...
... then calling
getFormWithRootKey("myUser")
would return aForm
object containing the "userName" and the "userName" fields, but not the "csrfToken".A
Form
object is in fact aJsonObject
containing the submitted fields and aValidationSet
to store validations performed on it.The same field is returned, everytime this method is called with the same
name
.If the root key is not found in the POSTed data, an empty form will be created.
The key are case sensitive.
- Returns:
- the form if it exists or
null
otherwise.
-
getUploadedFiles
Map<String,List<UploadedFile>> getUploadedFiles()The key of the map if the HTML'sname
attribute.More than one uploaded file with the same name is possible. The map is immutable.
Returns an empty map if there are no uploadded file.
-
getUploadedFiles
The uploaded files of the specified HTML'sname
attribute.More than one uploaded file with the same
name
is possible. The list is immutable. Returns an empty list if no uploaded files of this name exists. -
getUploadedFileFirst
The uploaded files of the specified HTML'sname
attribute.The first (and often only) uploaded file of the specified name.
Returns
null
if no uploaded file of this name exists. -
isHttps
boolean isHttps()Is the request a secure HTTPS one? -
getEtagsFromIfNoneMatchHeader
Returns theETags
from theIf-None-Match
header, if any.- Returns:
- the
If-None-Match
ETags or an empty list if there is none.
-
getEtagsFromIfMatchHeader
Returns theETags
from theIf-Match
header, if any.- Returns:
- the
If-Match
ETags or an empty list if there is none.
-
getDateFromIfModifiedSinceHeader
Date getDateFromIfModifiedSinceHeader()Return the value of theIf-Modified-Since
header as a Date ornull
if it doesn't exist. -
getDateFromIfUnmodifiedSinceHeader
Date getDateFromIfUnmodifiedSinceHeader()Return the value of theIf-Unmodified-Since
header as a Date ornull
if it doesn't exist. -
getFlashMessage
FlashMessage getFlashMessage()Gets the Flash message, if any.- Returns:
- the Flash message or
null
if there is none.
-
isFlashMessageExists
boolean isFlashMessageExists()Is there a Flash message? -
getCookiesValues
Gets the the request cookies values as a Map, using the names of the cookies as the keys. -
getCookieValue
Gets the value of a request cookie by name.- Returns:
- the value or
null
if not found.
-
isCookiesEnabledValidated
boolean isCookiesEnabledValidated()Did we validate that the current user has cookies enabled? -
getIp
String getIp()Gets the IP of the current request.
-