
public.javadoc.org.spincast.plugins.request.SpincastRequestRequestContextAddon.html Maven / Gradle / Ivy
Show all versions of spincast-website Show documentation
SpincastRequestRequestContextAddon (org.spincast:spincast-framework 1.7.1 API)
org.spincast.plugins.request
Class SpincastRequestRequestContextAddon<R extends RequestContext<?>>
- java.lang.Object
-
- org.spincast.plugins.request.SpincastRequestRequestContextAddon<R>
-
- All Implemented Interfaces:
- RequestRequestContextAddon<R>
public class SpincastRequestRequestContextAddon<R extends RequestContext<?>>
extends Object
implements RequestRequestContextAddon<R>
-
-
Field Summary
Fields
Modifier and Type
Field and Description
protected static org.slf4j.Logger
logger
-
Constructor Summary
Constructors
Constructor and Description
SpincastRequestRequestContextAddon(R requestContext,
Server server,
JsonManager jsonManager,
XmlManager xmlManager,
SpincastUtils spincastUtils,
SpincastConfig spincastConfig,
ETagFactory etagFactory,
FlashMessagesHolder flashMessagesHolder,
FormFactory formFactory,
Dictionary dictionary)
-
Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type
Method and Description
byte[]
getBodyAsByteArray()
The bytes of the request's body.
InputStream
getBodyAsInputStream()
The raw InputStream of the request's body.
String
getBodyAsString()
The request's body as a String, using the UTF-8
encoding.
String
getContentType()
The Content-Type of the request, if any.
ContentTypeDefaults
getContentTypeBestMatch()
Finds the best Content-Type
to use for a response
using the "Accept"
header of the request.
Map<String,String>
getCookiesValues()
Gets the the request cookies values as a Map,
using the names of the cookies as the keys.
String
getCookieValue(String name)
Gets the value of a request cookie by name.
Date
getDateFromIfModifiedSinceHeader()
Return the value of the If-Modified-Since
header as a Date or null
if it doesn't
exist.
Date
getDateFromIfUnmodifiedSinceHeader()
Return the value of the If-Unmodified-Since
header as a Date or null
if it doesn't
exist.
protected Dictionary
getDictionary()
protected ETagFactory
getEtagFactory()
List<ETag>
getEtagsFromIfMatchHeader()
Returns the ETags
from
the If-Match
header, if any.
List<ETag>
getEtagsFromIfNoneMatchHeader()
Returns the ETags
from
the If-None-Match
header, if any.
protected Object
getExchange()
FlashMessage
getFlashMessage()
Gets the Flash message, if any.
protected FlashMessage
getFlashMessage(boolean removeIt)
protected FlashMessagesHolder
getFlashMessagesHolder()
Form
getForm(String rootKey)
Gets the part of the submitted FORM
body
that is scoped by the specified root key
.
protected Form
getForm(String rootKey,
boolean createIfNotFound)
JsonObject
getFormBodyAsJsonObject()
The data submitted as a FORM
body
(in general via a POST
method),
as an immutable JsonObject
.
Map<String,List<String>>
getFormBodyRaw()
The data submitted as a FORM
body
(in general via a POST
method),
as a Map
.
protected Pattern
getFormDataArrayPattern()
protected FormFactory
getFormFactory()
Form
getFormOrCreate(String rootKey)
Gets the part of the submitted FORM
body
that is scoped by the specified root key
.
String
getFullUrl()
Returns the current full URL, including the queryString, if any.
String
getFullUrl(boolean keepCacheBusters)
Returns the current full URL, including the queryString, if any.
String
getFullUrlOriginal()
If the request has been forwarded, this is going to return the original
URL, not the current, forwarded, one.
String
getFullUrlOriginal(boolean keepCacheBusters)
If the request has been forwarded, this is going to return the original
URL, not the current, forwarded, one.
protected String
getFullUrlOriginalNoCacheBustersNonDecoded()
protected String
getFullUrlOriginalWithCacheBustersNonDecoded()
String
getFullUrlProxied()
If a reverse proxy has been used, this URL will contain the
scheme
, host
and port
as forwarded by the reserve proxy, not as seen by the user.
String
getFullUrlProxied(boolean keepCacheBusters)
If a reverse proxy has been used, this URL will contain the
scheme
, host
and port
as forwarded by the reserve proxy, not as seen by the user.
protected String
getFullUrlProxiedNoCacheBustersNonDecoded()
protected String
getFullUrlProxiedWithCacheBustersNonDecoded()
List<String>
getHeader(String name)
Returns the values of the specified header from the current request or
an empty list if not found.
String
getHeaderFirst(String name)
The first value of the specified header from the current request.
Map<String,List<String>>
getHeaders()
Returns all headers of the current request.
HttpMethod
getHttpMethod()
Gets the request's HTTP method
.
String
getIp()
Gets the IP of the current request.
JsonObject
getJsonBody()
The request's body deserialized to an immutable JsonObject
.
<T> T
getJsonBody(Class<T> clazz)
The request's body deserialized to the specified class
.
Map<String,Object>
getJsonBodyAsMap()
The request's body deserialized to a Map<String, Object>
.
protected JsonManager
getJsonManager()
Locale
getLocaleBestMatch()
Find what the request tells should be the best
Locale
to use for a response, by looking
at the "Accept-Language"
header.
String
getPathParam(String name)
A specific value parsed from a dynamic parameter of the route path.
Map<String,String>
getPathParams()
The values parsed from the dynamic parameters of the route path.
String
getQueryString(boolean withQuestionMark)
The queryString of the request.
List<String>
getQueryStringParam(String name)
A specific parameter taken from the queryString of the request.
String
getQueryStringParamFirst(String name)
The first (and often only) value of a specific parameter taken from the
queryString of the request.
Map<String,List<String>>
getQueryStringParams()
The parameters taken from the queryString of the request.
protected R
getRequestContext()
String
getRequestPath()
The path of the request (no querystring).
String
getRequestPath(boolean keepCacheBusters)
The path of the request (no querystring).
protected Server
getServer()
protected SpincastConfig
getSpincastConfig()
protected SpincastUtils
getSpincastUtils()
String
getStringBody(String encoding)
The request's body as a String, using the specified encoding.
UploadedFile
getUploadedFileFirst(String name)
The uploaded files of the specified HTML's name
attribute.
Map<String,List<UploadedFile>>
getUploadedFiles()
The key of the map if the HTML's name
attribute.
List<UploadedFile>
getUploadedFiles(String name)
The uploaded files of the specified HTML's name
attribute.
<T> T
getXmlBody(Class<T> clazz)
The request's body deserialized to the specified class
.
JsonObject
getXmlBodyAsJsonObject()
The request's body deserialized to an immutable JsonObject
.
Map<String,Object>
getXmlBodyAsMap()
The request's body deserialized to a Map<String, Object>
.
protected XmlManager
getXmlManager()
boolean
isCookiesEnabledValidated()
Did we validate that the current user has
cookies enabled?
boolean
isFlashMessageExists()
Is there a Flash message?
boolean
isHTMLShouldBeReturn()
Will return true
if the request specifies
that HTML
is the most appropriate format
to return.
boolean
isHttps()
Is the request a secure HTTPS one?
boolean
isJsonShouldBeReturn()
Will return true
if the request specifies
that Json
is the most appropriate format
to return.
boolean
isPlainTextShouldBeReturn()
Will return true
if the request specifies
that plain-text
is the most appropriate format
to return.
boolean
isXMLShouldBeReturn()
Will return true
if the request specifies
that XML
is the most appropriate format
to return.
protected Date
parseDateHeader(String headerName)
Returns NULL if the date is not there or not parsable.
protected List<ETag>
parseETagHeader(String headerName)
protected void
parseQueryString()
void
parseQueryStringParams()
protected void
parseRequestPath()
protected void
parseUrl()
protected void
validateFullUrlInfoCache()
-
-
Constructor Detail
-
SpincastRequestRequestContextAddon
@Inject
public SpincastRequestRequestContextAddon(R requestContext,
Server server,
JsonManager jsonManager,
XmlManager xmlManager,
SpincastUtils spincastUtils,
SpincastConfig spincastConfig,
ETagFactory etagFactory,
FlashMessagesHolder flashMessagesHolder,
FormFactory formFactory,
Dictionary dictionary)
-
Method Detail
-
getRequestContext
protected R getRequestContext()
-
getServer
protected Server getServer()
-
getJsonManager
protected JsonManager getJsonManager()
-
getXmlManager
protected XmlManager getXmlManager()
-
getSpincastUtils
protected SpincastUtils getSpincastUtils()
-
getSpincastConfig
protected SpincastConfig getSpincastConfig()
-
getEtagFactory
protected ETagFactory getEtagFactory()
-
getFlashMessagesHolder
protected FlashMessagesHolder getFlashMessagesHolder()
-
getFormFactory
protected FormFactory getFormFactory()
-
getDictionary
protected Dictionary getDictionary()
-
getExchange
protected Object getExchange()
-
getHttpMethod
public HttpMethod getHttpMethod()
Description copied from interface: RequestRequestContextAddon
Gets the request's HTTP method
.
- Specified by:
getHttpMethod
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getContentTypeBestMatch
public ContentTypeDefaults getContentTypeBestMatch()
Description copied from interface: RequestRequestContextAddon
Finds the best Content-Type
to use for a response
using the "Accept"
header of the request. It will
fallback to ContentTypeDefaults.TEXT
if nothing more specific
is found.
- Specified by:
getContentTypeBestMatch
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
isJsonShouldBeReturn
public boolean isJsonShouldBeReturn()
Description copied from interface: RequestRequestContextAddon
Will return true
if the request specifies
that Json
is the most appropriate format
to return.
- Specified by:
isJsonShouldBeReturn
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
isHTMLShouldBeReturn
public boolean isHTMLShouldBeReturn()
Description copied from interface: RequestRequestContextAddon
Will return true
if the request specifies
that HTML
is the most appropriate format
to return.
- Specified by:
isHTMLShouldBeReturn
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
isXMLShouldBeReturn
public boolean isXMLShouldBeReturn()
Description copied from interface: RequestRequestContextAddon
Will return true
if the request specifies
that XML
is the most appropriate format
to return.
- Specified by:
isXMLShouldBeReturn
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
isPlainTextShouldBeReturn
public boolean isPlainTextShouldBeReturn()
Description copied from interface: RequestRequestContextAddon
Will return true
if the request specifies
that plain-text
is the most appropriate format
to return.
- Specified by:
isPlainTextShouldBeReturn
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getFormDataArrayPattern
protected Pattern getFormDataArrayPattern()
-
getCookieValue
public String getCookieValue(String name)
Description copied from interface: RequestRequestContextAddon
Gets the value of a request cookie by name.
- Specified by:
getCookieValue
in interface RequestRequestContextAddon<R extends RequestContext<?>>
- Returns:
- the value or
null
if not found.
-
getCookiesValues
public Map<String,String> getCookiesValues()
Description copied from interface: RequestRequestContextAddon
Gets the the request cookies values as a Map,
using the names of the cookies as the keys.
- Specified by:
getCookiesValues
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
isCookiesEnabledValidated
public boolean isCookiesEnabledValidated()
Description copied from interface: RequestRequestContextAddon
Did we validate that the current user has
cookies enabled?
- Specified by:
isCookiesEnabledValidated
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getHeaders
public Map<String,List<String>> getHeaders()
Description copied from interface: RequestRequestContextAddon
Returns all headers of the current request. A single header can have multiple values.
The implementation is a TreeMap
which iscase insensitive for the keys.
The map is immutable.
- Specified by:
getHeaders
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getHeader
public List<String> getHeader(String name)
Description copied from interface: RequestRequestContextAddon
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.
- Specified by:
getHeader
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getHeaderFirst
public String getHeaderFirst(String name)
Description copied from interface: RequestRequestContextAddon
The first value of the specified header from the current request.
The name
is case insensitive.
Returns null
if the header is not found.
- Specified by:
getHeaderFirst
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getFullUrlOriginalNoCacheBustersNonDecoded
protected String getFullUrlOriginalNoCacheBustersNonDecoded()
-
getFullUrlOriginalWithCacheBustersNonDecoded
protected String getFullUrlOriginalWithCacheBustersNonDecoded()
-
getFullUrlProxiedNoCacheBustersNonDecoded
protected String getFullUrlProxiedNoCacheBustersNonDecoded()
-
getFullUrlProxiedWithCacheBustersNonDecoded
protected String getFullUrlProxiedWithCacheBustersNonDecoded()
-
getFullUrlOriginal
public String getFullUrlOriginal()
Description copied from interface: RequestRequestContextAddon
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
and port
from the
original URL, as seen by the user.
In general, this is what you want to use in your application.
- Specified by:
getFullUrlOriginal
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getFullUrlOriginal
public String getFullUrlOriginal(boolean keepCacheBusters)
Description copied from interface: RequestRequestContextAddon
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
and port
from the
original URL, as seen by the user.
In general, this is what you want to use in your application.
- Specified by:
getFullUrlOriginal
in interface RequestRequestContextAddon<R extends RequestContext<?>>
- Parameters:
keepCacheBusters
- if true
, the returned URL will contain
the cache buster codes, if there were any. The default behavior is to
automatically remove them.
-
getFullUrlProxied
public String getFullUrlProxied()
Description copied from interface: RequestRequestContextAddon
If a reverse proxy has been used, this URL will contain the
scheme
, host
and port
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()
or getFullUrlOriginal()
instead of this
one.
- Specified by:
getFullUrlProxied
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getFullUrlProxied
public String getFullUrlProxied(boolean keepCacheBusters)
Description copied from interface: RequestRequestContextAddon
If a reverse proxy has been used, this URL will contain the
scheme
, host
and port
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()
or getFullUrlOriginal()
instead of this
one.
- Specified by:
getFullUrlProxied
in interface RequestRequestContextAddon<R extends RequestContext<?>>
- Parameters:
keepCacheBusters
- if true
, the returned URL will contain
the cache buster codes, if there were any. The default behavior is to
automatically remove them.
-
getFullUrl
public String getFullUrl()
Description copied from interface: RequestRequestContextAddon
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
and port
from the
original URL, as seen by the user.
In general, this is what you want to use in your application.
- Specified by:
getFullUrl
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getFullUrl
public String getFullUrl(boolean keepCacheBusters)
Description copied from interface: RequestRequestContextAddon
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
and port
from the
original URL, as seen by the user.
In general, this is what you want to use in your application.
- Specified by:
getFullUrl
in interface RequestRequestContextAddon<R extends RequestContext<?>>
- Parameters:
keepCacheBusters
- if true
, the returned URL will contain
the cache buster codes, if there were any. The default behavior is to
automatically remove them.
-
validateFullUrlInfoCache
protected void validateFullUrlInfoCache()
-
parseUrl
protected void parseUrl()
-
parseRequestPath
protected void parseRequestPath()
-
parseQueryString
protected void parseQueryString()
-
parseQueryStringParams
public void parseQueryStringParams()
-
getRequestPath
public String getRequestPath()
Description copied from interface: RequestRequestContextAddon
The path of the request (no querystring).
- Specified by:
getRequestPath
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getRequestPath
public String getRequestPath(boolean keepCacheBusters)
Description copied from interface: RequestRequestContextAddon
The path of the request (no querystring).
- Specified by:
getRequestPath
in interface RequestRequestContextAddon<R extends RequestContext<?>>
- Parameters:
keepCacheBusters
- if true
, the returned path will contain
the cache buster codes, if there were any. The default behavior is to
automatically remove them.
-
getQueryString
public String getQueryString(boolean withQuestionMark)
Description copied from interface: RequestRequestContextAddon
The queryString of the request.
Returns an empty String if there is no queryString.
- Specified by:
getQueryString
in interface RequestRequestContextAddon<R extends RequestContext<?>>
- Parameters:
withQuestionMark
- if true
and the queryString
is not empty, the result will be prefixed with "?".
-
getQueryStringParams
public Map<String,List<String>> getQueryStringParams()
Description copied from interface: RequestRequestContextAddon
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.
- Specified by:
getQueryStringParams
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getQueryStringParam
public List<String> getQueryStringParam(String name)
Description copied from interface: RequestRequestContextAddon
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.
- Specified by:
getQueryStringParam
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getQueryStringParamFirst
public String getQueryStringParamFirst(String name)
Description copied from interface: RequestRequestContextAddon
The first (and often only) value of a specific parameter taken from the
queryString of the request.
Returns null
if the parameter doesn't exist.
- Specified by:
getQueryStringParamFirst
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getPathParams
public Map<String,String> getPathParams()
Description copied from interface: RequestRequestContextAddon
The values parsed from the dynamic parameters of the route path.
The map is immutable.
- Specified by:
getPathParams
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getPathParam
public String getPathParam(String name)
Description copied from interface: RequestRequestContextAddon
A specific value parsed from a dynamic parameter of the route path.
The name
is case sensitive, since you have easy control over it.
- Specified by:
getPathParam
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getBodyAsInputStream
public InputStream getBodyAsInputStream()
Description copied from interface: RequestRequestContextAddon
The raw InputStream of the request's body.
Note that once part of the InputStream is read, it can't be read again!
- Specified by:
getBodyAsInputStream
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getBodyAsString
public String getBodyAsString()
Description copied from interface: RequestRequestContextAddon
The request's body as a String, using the UTF-8
encoding.
Note that once part of the InputStream is read, it can't be read again!
- Specified by:
getBodyAsString
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getStringBody
public String getStringBody(String encoding)
Description copied from interface: RequestRequestContextAddon
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!
- Specified by:
getStringBody
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getBodyAsByteArray
public byte[] getBodyAsByteArray()
Description copied from interface: RequestRequestContextAddon
The bytes of the request's body.
Note that once part of the InputStream is read, it can't be read again!
- Specified by:
getBodyAsByteArray
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getJsonBody
public JsonObject getJsonBody()
Description copied from interface: RequestRequestContextAddon
The request's body deserialized to an immutable JsonObject
.
A valid Json
body
is expected.
Note that once part of the InputStream is read, it can't be read again!
- Specified by:
getJsonBody
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getJsonBodyAsMap
public Map<String,Object> getJsonBodyAsMap()
Description copied from interface: RequestRequestContextAddon
The request's body deserialized to a Map<String, Object>
. A valid Json
body
is expected.
Note that once part of the InputStream is read, it can't be read again!
- Specified by:
getJsonBodyAsMap
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getJsonBody
public <T> T getJsonBody(Class<T> clazz)
Description copied from interface: RequestRequestContextAddon
The request's body deserialized to the specified class
. A valid Json
body
is expected.
Note that once part of the InputStream is read, it can't be read again!
- Specified by:
getJsonBody
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getXmlBodyAsJsonObject
public JsonObject getXmlBodyAsJsonObject()
Description copied from interface: RequestRequestContextAddon
The request's body deserialized to an immutable JsonObject
.
A valid XML
body
is expected.
Note that once part of the InputStream is read, it can't be read again!
- Specified by:
getXmlBodyAsJsonObject
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getXmlBodyAsMap
public Map<String,Object> getXmlBodyAsMap()
Description copied from interface: RequestRequestContextAddon
The request's body deserialized to a Map<String, Object>
. A valid XML
body
is expected.
Note that once part of the InputStream is read, it can't be read again!
- Specified by:
getXmlBodyAsMap
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getXmlBody
public <T> T getXmlBody(Class<T> clazz)
Description copied from interface: RequestRequestContextAddon
The request's body deserialized to the specified class
. A valid XML
body
is expected.
Note that once part of the InputStream is read, it can't be read again!
- Specified by:
getXmlBody
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getFormBodyRaw
public Map<String,List<String>> getFormBodyRaw()
Description copied from interface: RequestRequestContextAddon
The data submitted as a FORM
body
(in general via a POST
method),
as a Map
.
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.
- Specified by:
getFormBodyRaw
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getFormBodyAsJsonObject
public JsonObject getFormBodyAsJsonObject()
Description copied from interface: RequestRequestContextAddon
The data submitted as a FORM
body
(in general via a POST
method),
as an immutable JsonObject
.
The root keys of the field names and are case sensitive.
The root keys will be parsed as JsonPaths
to build the final
JsonObject
. 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.
- Specified by:
getFormBodyAsJsonObject
in interface RequestRequestContextAddon<R extends RequestContext<?>>
- Returns:
- an immutable instance of
JsonObject
.
If you want to get a mutable instance, you can call .clone(true)
on this object.
-
getFormOrCreate
public Form getFormOrCreate(String rootKey)
Description copied from interface: RequestRequestContextAddon
Gets the part of the submitted FORM
body
that is scoped by the specified root 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 RequestRequestContextAddon.getFormOrCreate(String)
you only get the fields which names start with the specified
root 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 a Form
object containing the "userName" and the "userName"
fields, but not the "csrfToken".
A Form
object is in fact a JsonObject
containing the submitted
fields and a ValidationSet
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.
- Specified by:
getFormOrCreate
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getForm
public Form getForm(String rootKey)
Description copied from interface: RequestRequestContextAddon
Gets the part of the submitted FORM
body
that is scoped by the specified root 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 RequestRequestContextAddon.getFormOrCreate(String)
you only get the fields which names start with the specified
root 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 a Form
object containing the "userName" and the "userName"
fields, but not the "csrfToken".
A Form
object is in fact a JsonObject
containing the submitted
fields and a ValidationSet
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.
- Specified by:
getForm
in interface RequestRequestContextAddon<R extends RequestContext<?>>
- Returns:
- the form if it exists or
null
otherwise.
-
getUploadedFiles
public Map<String,List<UploadedFile>> getUploadedFiles()
Description copied from interface: RequestRequestContextAddon
The key of the map if the HTML's name
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.
- Specified by:
getUploadedFiles
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getUploadedFiles
public List<UploadedFile> getUploadedFiles(String name)
Description copied from interface: RequestRequestContextAddon
The uploaded files of the specified HTML's name
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.
- Specified by:
getUploadedFiles
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getUploadedFileFirst
public UploadedFile getUploadedFileFirst(String name)
Description copied from interface: RequestRequestContextAddon
The uploaded files of the specified HTML's name
attribute.
The first (and often only) uploaded file of the specified name.
Returns null
if no uploaded file of this name exists.
- Specified by:
getUploadedFileFirst
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getLocaleBestMatch
public Locale getLocaleBestMatch()
Description copied from interface: RequestRequestContextAddon
Find what the request tells should be the best
Locale
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()
or
LocaleResolver.getLocaleToUse()
directly if you want
to know the absolute best Locale
to use for the user!
- Specified by:
getLocaleBestMatch
in interface RequestRequestContextAddon<R extends RequestContext<?>>
- Returns:
- the default
Locale
(taken from the configurations)
if nothing more specific is found on the request.
-
getContentType
public String getContentType()
Description copied from interface: RequestRequestContextAddon
The Content-Type of the request, if any.
- Specified by:
getContentType
in interface RequestRequestContextAddon<R extends RequestContext<?>>
- Returns:
- the
Content-Type
of the request or null
if none was specified.
-
isHttps
public boolean isHttps()
Description copied from interface: RequestRequestContextAddon
Is the request a secure HTTPS one?
- Specified by:
isHttps
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getEtagsFromIfMatchHeader
public List<ETag> getEtagsFromIfMatchHeader()
Description copied from interface: RequestRequestContextAddon
Returns the ETags
from
the If-Match
header, if any.
- Specified by:
getEtagsFromIfMatchHeader
in interface RequestRequestContextAddon<R extends RequestContext<?>>
- Returns:
- the
If-Match
ETags or an empty list
if there is none.
-
getEtagsFromIfNoneMatchHeader
public List<ETag> getEtagsFromIfNoneMatchHeader()
Description copied from interface: RequestRequestContextAddon
Returns the ETags
from
the If-None-Match
header, if any.
- Specified by:
getEtagsFromIfNoneMatchHeader
in interface RequestRequestContextAddon<R extends RequestContext<?>>
- Returns:
- the
If-None-Match
ETags or an empty
list if there is none.
-
getDateFromIfModifiedSinceHeader
public Date getDateFromIfModifiedSinceHeader()
Description copied from interface: RequestRequestContextAddon
Return the value of the If-Modified-Since
header as a Date or null
if it doesn't
exist.
- Specified by:
getDateFromIfModifiedSinceHeader
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getDateFromIfUnmodifiedSinceHeader
public Date getDateFromIfUnmodifiedSinceHeader()
Description copied from interface: RequestRequestContextAddon
Return the value of the If-Unmodified-Since
header as a Date or null
if it doesn't
exist.
- Specified by:
getDateFromIfUnmodifiedSinceHeader
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
parseDateHeader
protected Date parseDateHeader(String headerName)
Returns NULL if the date is not there or not parsable.
-
isFlashMessageExists
public boolean isFlashMessageExists()
Description copied from interface: RequestRequestContextAddon
Is there a Flash message?
- Specified by:
isFlashMessageExists
in interface RequestRequestContextAddon<R extends RequestContext<?>>
-
getFlashMessage
public FlashMessage getFlashMessage()
Description copied from interface: RequestRequestContextAddon
Gets the Flash message, if any.
- Specified by:
getFlashMessage
in interface RequestRequestContextAddon<R extends RequestContext<?>>
- Returns:
- the Flash message or
null
if there
is none.
-
getFlashMessage
protected FlashMessage getFlashMessage(boolean removeIt)
-
getIp
public String getIp()
Description copied from interface: RequestRequestContextAddon
Gets the IP of the current request.
- Specified by:
getIp
in interface RequestRequestContextAddon<R extends RequestContext<?>>
Copyright © 2019. All rights reserved.