public class SpincastRequestRequestContextAddon<R extends IRequestContext<?>> extends Object implements IRequestRequestContextAddon<R>
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger |
| Constructor and Description |
|---|
SpincastRequestRequestContextAddon(R requestContext,
IServer server,
IJsonManager jsonManager,
IXmlManager xmlManager,
ISpincastUtils spincastUtils,
ISpincastConfig spincastConfig,
IETagFactory etagFactory) |
| 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. |
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 IETagFactory |
getEtagFactory() |
List<IETag> |
getEtagsFromIfMatchHeader()
Returns the
ETags from
the If-Match header, if any. |
List<IETag> |
getEtagsFromIfNoneMatchHeader()
Returns the
ETags from
the If-None-Match header, if any. |
protected Object |
getExchange() |
List<String> |
getFormData(String name)
A specific parameter submitted from a
FORM via a POST method. |
String |
getFormDataFirst(String name)
The first (and often only) value of a specific parameter submitted from a
FORM via a POST method. |
Map<String,List<String>> |
getFormDatas()
The parameters submitted from a
FORM via a POST method. |
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. |
<T> T |
getJsonBody(Class<T> clazz)
The request's body deserialized to the specified
class. |
IJsonObject |
getJsonBodyAsJsonObject()
The request's body deserialized to a
IJsonObject. |
Map<String,Object> |
getJsonBodyAsMap()
The request's body deserialized to a
Map<String, Object>. |
protected IJsonManager |
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 IServer |
getServer() |
protected ISpincastConfig |
getSpincastConfig() |
protected ISpincastUtils |
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. |
IJsonObject |
getXmlBodyAsJsonObject()
The request's body deserialized to a
IJsonObject. |
Map<String,Object> |
getXmlBodyAsMap()
The request's body deserialized to a
Map<String, Object>. |
protected IXmlManager |
getXmlManager() |
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<IETag> |
parseETagHeader(String headerName) |
protected void |
parseQueryString() |
void |
parseQueryStringParams() |
protected void |
parseRequestPath() |
protected void |
parseUrl() |
protected void |
validateFullUrlInfoCache() |
@Inject public SpincastRequestRequestContextAddon(R requestContext, IServer server, IJsonManager jsonManager, IXmlManager xmlManager, ISpincastUtils spincastUtils, ISpincastConfig spincastConfig, IETagFactory etagFactory)
protected R getRequestContext()
protected IServer getServer()
protected IJsonManager getJsonManager()
protected IXmlManager getXmlManager()
protected ISpincastUtils getSpincastUtils()
protected ISpincastConfig getSpincastConfig()
protected IETagFactory getEtagFactory()
protected Object getExchange()
public HttpMethod getHttpMethod()
IRequestRequestContextAddonHTTP method.getHttpMethod in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public ContentTypeDefaults getContentTypeBestMatch()
IRequestRequestContextAddonContent-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 IRequestRequestContextAddon<R extends IRequestContext<?>>public boolean isJsonShouldBeReturn()
IRequestRequestContextAddontrue if the request specifies
that Json is the most appropriate format
to return.isJsonShouldBeReturn in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public boolean isHTMLShouldBeReturn()
IRequestRequestContextAddontrue if the request specifies
that HTML is the most appropriate format
to return.isHTMLShouldBeReturn in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public boolean isXMLShouldBeReturn()
IRequestRequestContextAddontrue if the request specifies
that XML is the most appropriate format
to return.isXMLShouldBeReturn in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public boolean isPlainTextShouldBeReturn()
IRequestRequestContextAddontrue if the request specifies
that plain-text is the most appropriate format
to return.isPlainTextShouldBeReturn in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public Map<String,List<String>> getHeaders()
IRequestRequestContextAddonTreeMap which iscase insensitive for the keys.
The map is immutable.getHeaders in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public List<String> getHeader(String name)
IRequestRequestContextAddonname is case insensitive.
The list is immutable.getHeader in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public String getHeaderFirst(String name)
IRequestRequestContextAddonname is case insensitive.
Returns null if the header is not found.getHeaderFirst in interface IRequestRequestContextAddon<R extends IRequestContext<?>>protected String getFullUrlOriginalNoCacheBustersNonDecoded()
protected String getFullUrlOriginalWithCacheBustersNonDecoded()
protected String getFullUrlProxiedNoCacheBustersNonDecoded()
protected String getFullUrlProxiedWithCacheBustersNonDecoded()
public String getFullUrlOriginal()
IRequestRequestContextAddon
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 IRequestRequestContextAddon<R extends IRequestContext<?>>public String getFullUrlOriginal(boolean keepCacheBusters)
IRequestRequestContextAddon
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 IRequestRequestContextAddon<R extends IRequestContext<?>>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()
IRequestRequestContextAddonscheme, 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 IRequestRequestContextAddon<R extends IRequestContext<?>>public String getFullUrlProxied(boolean keepCacheBusters)
IRequestRequestContextAddonscheme, 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 IRequestRequestContextAddon<R extends IRequestContext<?>>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()
IRequestRequestContextAddon
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 IRequestRequestContextAddon<R extends IRequestContext<?>>public String getFullUrl(boolean keepCacheBusters)
IRequestRequestContextAddon
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 IRequestRequestContextAddon<R extends IRequestContext<?>>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()
IRequestRequestContextAddongetRequestPath in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public String getRequestPath(boolean keepCacheBusters)
IRequestRequestContextAddongetRequestPath in interface IRequestRequestContextAddon<R extends IRequestContext<?>>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)
IRequestRequestContextAddongetQueryString in interface IRequestRequestContextAddon<R extends IRequestContext<?>>withQuestionMark - if true and the queryString
is not empty, the result will be prefixed with "?".public Map<String,List<String>> getQueryStringParams()
IRequestRequestContextAddongetQueryStringParams in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public List<String> getQueryStringParam(String name)
IRequestRequestContextAddongetQueryStringParam in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public String getQueryStringParamFirst(String name)
IRequestRequestContextAddonnull if the parameter doesn't exist.getQueryStringParamFirst in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public Map<String,String> getPathParams()
IRequestRequestContextAddongetPathParams in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public String getPathParam(String name)
IRequestRequestContextAddonname is case sensitive, since you have easy control over it.getPathParam in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public InputStream getBodyAsInputStream()
IRequestRequestContextAddongetBodyAsInputStream in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public String getBodyAsString()
IRequestRequestContextAddonUTF-8 encoding.
Note that the characters read cannot be read again!getBodyAsString in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public String getBodyAsString(String encoding)
IRequestRequestContextAddongetBodyAsString in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public byte[] getBodyAsByteArray()
IRequestRequestContextAddongetBodyAsByteArray in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public IJsonObject getJsonBodyAsJsonObject()
IRequestRequestContextAddonIJsonObject. A valid Json body
is expected.
Note that this can only be called once.getJsonBodyAsJsonObject in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public Map<String,Object> getJsonBodyAsMap()
IRequestRequestContextAddonMap<String, Object>. A valid Json body
is expected.
Note that this can only be called once.getJsonBodyAsMap in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public <T> T getJsonBody(Class<T> clazz)
IRequestRequestContextAddonclass. A valid Json body
is expected.
Note that this can only be called once.getJsonBody in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public IJsonObject getXmlBodyAsJsonObject()
IRequestRequestContextAddonIJsonObject. A valid XML body
is expected.
Note that this can only be called once.getXmlBodyAsJsonObject in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public Map<String,Object> getXmlBodyAsMap()
IRequestRequestContextAddonMap<String, Object>. A valid XML body
is expected.
Note that this can only be called once.getXmlBodyAsMap in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public <T> T getXmlBody(Class<T> clazz)
IRequestRequestContextAddonclass. A valid XML body
is expected.
Note that this can only be called once.getXmlBody in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public Map<String,List<String>> getFormDatas()
IRequestRequestContextAddonFORM via a POST method.
More than one value with the same key is possible.
The names are case sensitive.
The map is immutable.getFormDatas in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public List<String> getFormData(String name)
IRequestRequestContextAddonFORM via a POST method.
More than one value with the same name is possible.
The name is case sensitive.
The list is immutable.getFormData in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public String getFormDataFirst(String name)
IRequestRequestContextAddonFORM via a POST method.
The name is case sensitive.
Returns null if the parameter doesn't exist.getFormDataFirst in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public Map<String,List<File>> getUploadedFiles()
IRequestRequestContextAddongetUploadedFiles in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public List<File> getUploadedFiles(String name)
IRequestRequestContextAddonname is possible.
The list is immutable.
Returns an empty list if no uploaded files of this name exists.getUploadedFiles in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public File getUploadedFileFirst(String name)
IRequestRequestContextAddonnull if no uploaded file of this name exists.getUploadedFileFirst in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public Locale getLocaleBestMatch()
IRequestRequestContextAddonLocale 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 IRequestRequestContextAddon<R extends IRequestContext<?>>public String getContentType()
IRequestRequestContextAddongetContentType in interface IRequestRequestContextAddon<R extends IRequestContext<?>>Content-Type of the request or null
if none was specified.public boolean isHttps()
IRequestRequestContextAddonisHttps in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public List<IETag> getEtagsFromIfMatchHeader()
IRequestRequestContextAddonETags from
the If-Match header, if any.getEtagsFromIfMatchHeader in interface IRequestRequestContextAddon<R extends IRequestContext<?>>If-Match ETags or an empty list
if there is none.public List<IETag> getEtagsFromIfNoneMatchHeader()
IRequestRequestContextAddonETags from
the If-None-Match header, if any.getEtagsFromIfNoneMatchHeader in interface IRequestRequestContextAddon<R extends IRequestContext<?>>If-None-Match ETags or an empty
list if there is none.public Date getDateFromIfModifiedSinceHeader()
IRequestRequestContextAddonIf-Modified-Since
header as a Date or null if it doesn't
exist.getDateFromIfModifiedSinceHeader in interface IRequestRequestContextAddon<R extends IRequestContext<?>>public Date getDateFromIfUnmodifiedSinceHeader()
IRequestRequestContextAddonIf-Unmodified-Since
header as a Date or null if it doesn't
exist.getDateFromIfUnmodifiedSinceHeader in interface IRequestRequestContextAddon<R extends IRequestContext<?>>Copyright © 2016. All rights reserved.