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-8encoding.The Content-Type of the request, if any.Finds the bestContent-Typeto 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-Sinceheader as a Date ornullif it doesn't exist.Return the value of theIf-Unmodified-Sinceheader as a Date ornullif it doesn't exist.Returns theETagsfrom theIf-Matchheader, if any.Returns theETagsfrom theIf-None-Matchheader, if any.Gets the Flash message, if any.Gets the part of the submittedFORMbody that is scoped by the specifiedroot key.The data submitted as aFORMbody (in general via aPOSTmethod), as an immutableJsonObject.The data submitted as aFORMbody (in general via aPOSTmethod), as aMap.getFormOrCreate(String rootKey) Gets the part of the submittedFORMbody 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,hostandportas 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,hostandportas 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> TgetJsonBody(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 bestLocaleto 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'snameattribute.The key of the map if the HTML'snameattribute.getUploadedFiles(String htmlName) The uploaded files of the specified HTML'snameattribute.<T> TgetXmlBody(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>.booleanDid we validate that the current user has cookies enabled?booleanIs there a Flash message?booleanWill returntrueif the request specifies thatHTMLis the most appropriate format to return.booleanisHttps()Is the request a secure HTTPS one?booleanWill returntrueif the request specifies thatJsonis the most appropriate format to return.booleanWill returntrueif the request specifies thatplain-textis the most appropriate format to return.booleanWill returntrueif the request specifies thatXMLis the most appropriate format to return.
-
Method Details
-
getHttpMethod
HttpMethod getHttpMethod()Gets the request'sHTTP method. -
getContentTypeBestMatch
ContentTypeDefaults getContentTypeBestMatch()Finds the bestContent-Typeto use for a response using the"Accept"header of the request. It will fallback toContentTypeDefaults.TEXTif nothing more specific is found. -
isJsonShouldBeReturn
boolean isJsonShouldBeReturn()Will returntrueif the request specifies thatJsonis the most appropriate format to return. -
isHTMLShouldBeReturn
boolean isHTMLShouldBeReturn()Will returntrueif the request specifies thatHTMLis the most appropriate format to return. -
isXMLShouldBeReturn
boolean isXMLShouldBeReturn()Will returntrueif the request specifies thatXMLis the most appropriate format to return. -
isPlainTextShouldBeReturn
boolean isPlainTextShouldBeReturn()Will returntrueif the request specifies thatplain-textis the most appropriate format to return. -
getLocaleBestMatch
Locale getLocaleBestMatch()Find what the request tells should be the bestLocaleto use for a response, by looking at the"Accept-Language"header.Note that this will not necessarily be the absolute best
Localeto 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 bestLocaleto 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 aTreeMapwhich 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
nameis case insensitive.The list is immutable.
-
getHeaderFirst
The first value of the specified header from the current request.The
nameis case insensitive.Returns
nullif the header is not found. -
getContentType
String getContentType()The Content-Type of the request, if any.- Returns:
- the
Content-Typeof the request ornullif 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,hostandportfrom 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,hostandportfrom 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,hostandportfrom 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,hostandportfrom 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,hostandportas 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,hostandportas 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. Thenameis case sensitive, since you have easy control over it.- Returns:
- the path param value or
nullif not found.
-
getQueryString
The queryString of the request. Returns an empty String if there is no queryString.- Parameters:
withQuestionMark- iftrueand 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. Returnsnullif 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-8encoding. 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 validJsonbody 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 validJsonbody 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 validJsonbody 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 validXMLbody 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 validXMLbody 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 validXMLbody is expected. Note that once part of the InputStream is read, it can't be read again! -
getFormBodyRaw
The data submitted as aFORMbody (in general via aPOSTmethod), 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 aFORMbody (in general via aPOSTmethod), as an immutableJsonObject.The root keys of the field names and are case sensitive.
The root keys will be parsed as
JsonPathsto build the finalJsonObject. For example :user.books[1].namewill be converted to a "user"JsonObjectwith 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 submittedFORMbody 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 aFormobject containing the "userName" and the "userName" fields, but not the "csrfToken".A
Formobject is in fact aJsonObjectcontaining the submitted fields and aValidationSetto 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 submittedFORMbody 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 aFormobject containing the "userName" and the "userName" fields, but not the "csrfToken".A
Formobject is in fact aJsonObjectcontaining the submitted fields and aValidationSetto 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
nullotherwise.
-
getUploadedFiles
Map<String,List<UploadedFile>> getUploadedFiles()The key of the map if the HTML'snameattribute.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'snameattribute.More than one uploaded file with the same
nameis 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'snameattribute.The first (and often only) uploaded file of the specified name.
Returns
nullif no uploaded file of this name exists. -
isHttps
boolean isHttps()Is the request a secure HTTPS one? -
getEtagsFromIfNoneMatchHeader
Returns theETagsfrom theIf-None-Matchheader, if any.- Returns:
- the
If-None-MatchETags or an empty list if there is none.
-
getEtagsFromIfMatchHeader
Returns theETagsfrom theIf-Matchheader, if any.- Returns:
- the
If-MatchETags or an empty list if there is none.
-
getDateFromIfModifiedSinceHeader
Date getDateFromIfModifiedSinceHeader()Return the value of theIf-Modified-Sinceheader as a Date ornullif it doesn't exist. -
getDateFromIfUnmodifiedSinceHeader
Date getDateFromIfUnmodifiedSinceHeader()Return the value of theIf-Unmodified-Sinceheader as a Date ornullif it doesn't exist. -
getFlashMessage
FlashMessage getFlashMessage()Gets the Flash message, if any.- Returns:
- the Flash message or
nullif 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
nullif 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.
-