public class SpincastRequestRequestContextAddon<R extends RequestContext<?>> extends Object implements RequestRequestContextAddon<R>
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger |
| Constructor and Description |
|---|
SpincastRequestRequestContextAddon(R requestContext,
Server server,
JsonManager jsonManager,
XmlManager xmlManager,
SpincastUtils spincastUtils,
SpincastConfig spincastConfig,
ETagFactory etagFactory,
FlashMessagesHolder flashMessagesHolder) |
| 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 |
getBodyAsString(String encoding)
The request's body as a String, using the specified 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. |
String |
getCookie(String name)
Gets the value of a request cookie by name.
|
Map<String,String> |
getCookies()
Gets the the request cookies values as a Map,
using the names of the cookies as the keys.
|
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 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() |
JsonObject |
getFormData()
The data submitted from a
FORM via a POST method,
as an immutable JsonObject. |
protected Pattern |
getFormDataArrayPattern() |
Map<String,List<String>> |
getFormDataRaw()
The raw datas submitted from a
FORM via a
POST method, as a Map. |
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. |
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 the best
Locale to use for a response
using the "Accept-Language" header of
the request. |
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() |
File |
getUploadedFileFirst(String name)
The first (and often only) uploaded file of the specified name.
|
Map<String,List<File>> |
getUploadedFiles()
The uploaded files, with their names as the keys.
|
List<File> |
getUploadedFiles(String name)
The uploaded files of the specified name.
|
<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() |
@Inject public SpincastRequestRequestContextAddon(R requestContext, Server server, JsonManager jsonManager, XmlManager xmlManager, SpincastUtils spincastUtils, SpincastConfig spincastConfig, ETagFactory etagFactory, FlashMessagesHolder flashMessagesHolder)
protected R getRequestContext()
protected Server getServer()
protected JsonManager getJsonManager()
protected XmlManager getXmlManager()
protected SpincastUtils getSpincastUtils()
protected SpincastConfig getSpincastConfig()
protected ETagFactory getEtagFactory()
protected FlashMessagesHolder getFlashMessagesHolder()
protected Object getExchange()
public HttpMethod getHttpMethod()
RequestRequestContextAddonHTTP method.getHttpMethod in interface RequestRequestContextAddon<R extends RequestContext<?>>public ContentTypeDefaults getContentTypeBestMatch()
RequestRequestContextAddonContent-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.getContentTypeBestMatch in interface RequestRequestContextAddon<R extends RequestContext<?>>public boolean isJsonShouldBeReturn()
RequestRequestContextAddontrue if the request specifies
that Json is the most appropriate format
to return.isJsonShouldBeReturn in interface RequestRequestContextAddon<R extends RequestContext<?>>public boolean isHTMLShouldBeReturn()
RequestRequestContextAddontrue if the request specifies
that HTML is the most appropriate format
to return.isHTMLShouldBeReturn in interface RequestRequestContextAddon<R extends RequestContext<?>>public boolean isXMLShouldBeReturn()
RequestRequestContextAddontrue if the request specifies
that XML is the most appropriate format
to return.isXMLShouldBeReturn in interface RequestRequestContextAddon<R extends RequestContext<?>>public boolean isPlainTextShouldBeReturn()
RequestRequestContextAddontrue if the request specifies
that plain-text is the most appropriate format
to return.isPlainTextShouldBeReturn in interface RequestRequestContextAddon<R extends RequestContext<?>>protected Pattern getFormDataArrayPattern()
public String getCookie(String name)
RequestRequestContextAddongetCookie in interface RequestRequestContextAddon<R extends RequestContext<?>>null if not found.public Map<String,String> getCookies()
RequestRequestContextAddongetCookies in interface RequestRequestContextAddon<R extends RequestContext<?>>public boolean isCookiesEnabledValidated()
RequestRequestContextAddonisCookiesEnabledValidated in interface RequestRequestContextAddon<R extends RequestContext<?>>public Map<String,List<String>> getHeaders()
RequestRequestContextAddonTreeMap which iscase insensitive for the keys.
The map is immutable.getHeaders in interface RequestRequestContextAddon<R extends RequestContext<?>>public List<String> getHeader(String name)
RequestRequestContextAddonname is case insensitive.
The list is immutable.getHeader in interface RequestRequestContextAddon<R extends RequestContext<?>>public String getHeaderFirst(String name)
RequestRequestContextAddonname is case insensitive.
Returns null if the header is not found.getHeaderFirst in interface RequestRequestContextAddon<R extends RequestContext<?>>protected String getFullUrlOriginalNoCacheBustersNonDecoded()
protected String getFullUrlOriginalWithCacheBustersNonDecoded()
protected String getFullUrlProxiedNoCacheBustersNonDecoded()
protected String getFullUrlProxiedWithCacheBustersNonDecoded()
public String getFullUrlOriginal()
RequestRequestContextAddon
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.
getFullUrlOriginal in interface RequestRequestContextAddon<R extends RequestContext<?>>public String getFullUrlOriginal(boolean keepCacheBusters)
RequestRequestContextAddon
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.
getFullUrlOriginal in interface RequestRequestContextAddon<R extends RequestContext<?>>keepCacheBusters - if true, the returned URL will contain
the cache buster codes, if there were any. The default behavior is to
automatically remove them.public String getFullUrlProxied()
RequestRequestContextAddonscheme, 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.
getFullUrlProxied in interface RequestRequestContextAddon<R extends RequestContext<?>>public String getFullUrlProxied(boolean keepCacheBusters)
RequestRequestContextAddonscheme, 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.
getFullUrlProxied in interface RequestRequestContextAddon<R extends RequestContext<?>>keepCacheBusters - if true, the returned URL will contain
the cache buster codes, if there were any. The default behavior is to
automatically remove them.public String getFullUrl()
RequestRequestContextAddon
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.
getFullUrl in interface RequestRequestContextAddon<R extends RequestContext<?>>public String getFullUrl(boolean keepCacheBusters)
RequestRequestContextAddon
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.
getFullUrl in interface RequestRequestContextAddon<R extends RequestContext<?>>keepCacheBusters - if true, the returned URL will contain
the cache buster codes, if there were any. The default behavior is to
automatically remove them.protected void validateFullUrlInfoCache()
protected void parseUrl()
protected void parseRequestPath()
protected void parseQueryString()
public void parseQueryStringParams()
public String getRequestPath()
RequestRequestContextAddongetRequestPath in interface RequestRequestContextAddon<R extends RequestContext<?>>public String getRequestPath(boolean keepCacheBusters)
RequestRequestContextAddongetRequestPath in interface RequestRequestContextAddon<R extends RequestContext<?>>keepCacheBusters - if true, the returned path will contain
the cache buster codes, if there were any. The default behavior is to
automatically remove them.public String getQueryString(boolean withQuestionMark)
RequestRequestContextAddongetQueryString in interface RequestRequestContextAddon<R extends RequestContext<?>>withQuestionMark - if true and the queryString
is not empty, the result will be prefixed with "?".public Map<String,List<String>> getQueryStringParams()
RequestRequestContextAddongetQueryStringParams in interface RequestRequestContextAddon<R extends RequestContext<?>>public List<String> getQueryStringParam(String name)
RequestRequestContextAddongetQueryStringParam in interface RequestRequestContextAddon<R extends RequestContext<?>>public String getQueryStringParamFirst(String name)
RequestRequestContextAddonnull if the parameter doesn't exist.getQueryStringParamFirst in interface RequestRequestContextAddon<R extends RequestContext<?>>public Map<String,String> getPathParams()
RequestRequestContextAddongetPathParams in interface RequestRequestContextAddon<R extends RequestContext<?>>public String getPathParam(String name)
RequestRequestContextAddonname is case sensitive, since you have easy control over it.getPathParam in interface RequestRequestContextAddon<R extends RequestContext<?>>public InputStream getBodyAsInputStream()
RequestRequestContextAddongetBodyAsInputStream in interface RequestRequestContextAddon<R extends RequestContext<?>>public String getBodyAsString()
RequestRequestContextAddonUTF-8 encoding.
Note that once part of the InputStream is read, it can't be read again!getBodyAsString in interface RequestRequestContextAddon<R extends RequestContext<?>>public String getBodyAsString(String encoding)
RequestRequestContextAddongetBodyAsString in interface RequestRequestContextAddon<R extends RequestContext<?>>public byte[] getBodyAsByteArray()
RequestRequestContextAddongetBodyAsByteArray in interface RequestRequestContextAddon<R extends RequestContext<?>>public JsonObject getJsonBody()
RequestRequestContextAddonJsonObject.
A valid Json body
is expected.
Note that once part of the InputStream is read, it can't be read again!getJsonBody in interface RequestRequestContextAddon<R extends RequestContext<?>>public Map<String,Object> getJsonBodyAsMap()
RequestRequestContextAddonMap<String, Object>. A valid Json body
is expected.
Note that once part of the InputStream is read, it can't be read again!getJsonBodyAsMap in interface RequestRequestContextAddon<R extends RequestContext<?>>public <T> T getJsonBody(Class<T> clazz)
RequestRequestContextAddonclass. A valid Json body
is expected.
Note that once part of the InputStream is read, it can't be read again!getJsonBody in interface RequestRequestContextAddon<R extends RequestContext<?>>public JsonObject getXmlBodyAsJsonObject()
RequestRequestContextAddonJsonObject.
A valid XML body
is expected.
Note that once part of the InputStream is read, it can't be read again!getXmlBodyAsJsonObject in interface RequestRequestContextAddon<R extends RequestContext<?>>public Map<String,Object> getXmlBodyAsMap()
RequestRequestContextAddonMap<String, Object>. A valid XML body
is expected.
Note that once part of the InputStream is read, it can't be read again!getXmlBodyAsMap in interface RequestRequestContextAddon<R extends RequestContext<?>>public <T> T getXmlBody(Class<T> clazz)
RequestRequestContextAddonclass. A valid XML body
is expected.
Note that once part of the InputStream is read, it can't be read again!getXmlBody in interface RequestRequestContextAddon<R extends RequestContext<?>>public Map<String,List<String>> getFormDataRaw()
RequestRequestContextAddonFORM via a
POST method, as a Map.
More than one value with the same key is possible.
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.
getFormDataRaw in interface RequestRequestContextAddon<R extends RequestContext<?>>public JsonObject getFormData()
RequestRequestContextAddonFORM via a POST method,
as an immutable JsonObject.
The keys are case sensitive.
The 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.
getFormData in interface RequestRequestContextAddon<R extends RequestContext<?>>JsonObject.
If you want to get a mutable instance, you can call .clone(true)
on this object.public Map<String,List<File>> getUploadedFiles()
RequestRequestContextAddongetUploadedFiles in interface RequestRequestContextAddon<R extends RequestContext<?>>public List<File> getUploadedFiles(String name)
RequestRequestContextAddonname is possible.
The list is immutable.
Returns an empty list if no uploaded files of this name exists.getUploadedFiles in interface RequestRequestContextAddon<R extends RequestContext<?>>public File getUploadedFileFirst(String name)
RequestRequestContextAddonnull if no uploaded file of this name exists.getUploadedFileFirst in interface RequestRequestContextAddon<R extends RequestContext<?>>public Locale getLocaleBestMatch()
RequestRequestContextAddonLocale to use for a response
using the "Accept-Language" header of
the request.
Returns the default Locale (taken from the configurations)
if nothing more specific is found.getLocaleBestMatch in interface RequestRequestContextAddon<R extends RequestContext<?>>public String getContentType()
RequestRequestContextAddongetContentType in interface RequestRequestContextAddon<R extends RequestContext<?>>Content-Type of the request or null
if none was specified.public boolean isHttps()
RequestRequestContextAddonisHttps in interface RequestRequestContextAddon<R extends RequestContext<?>>public List<ETag> getEtagsFromIfMatchHeader()
RequestRequestContextAddonETags from
the If-Match header, if any.getEtagsFromIfMatchHeader in interface RequestRequestContextAddon<R extends RequestContext<?>>If-Match ETags or an empty list
if there is none.public List<ETag> getEtagsFromIfNoneMatchHeader()
RequestRequestContextAddonETags from
the If-None-Match header, if any.getEtagsFromIfNoneMatchHeader in interface RequestRequestContextAddon<R extends RequestContext<?>>If-None-Match ETags or an empty
list if there is none.public Date getDateFromIfModifiedSinceHeader()
RequestRequestContextAddonIf-Modified-Since
header as a Date or null if it doesn't
exist.getDateFromIfModifiedSinceHeader in interface RequestRequestContextAddon<R extends RequestContext<?>>public Date getDateFromIfUnmodifiedSinceHeader()
RequestRequestContextAddonIf-Unmodified-Since
header as a Date or null if it doesn't
exist.getDateFromIfUnmodifiedSinceHeader in interface RequestRequestContextAddon<R extends RequestContext<?>>protected Date parseDateHeader(String headerName)
public boolean isFlashMessageExists()
RequestRequestContextAddonisFlashMessageExists in interface RequestRequestContextAddon<R extends RequestContext<?>>public FlashMessage getFlashMessage()
RequestRequestContextAddongetFlashMessage in interface RequestRequestContextAddon<R extends RequestContext<?>>null if there
is none.protected FlashMessage getFlashMessage(boolean removeIt)
Copyright © 2017. All rights reserved.