public abstract class AbstractContext extends Object implements Context.Impl
getHeader() method, but this class could
supply a default implementation of getAcceptContentType() since
it only needs to fetch a value from getHeader().
When adding features to a Context please think about whether
it should be fully or partially implemented here or in the concrete implementation.Context.HTTP_STATUS, Context.Impl| Modifier and Type | Field and Description |
|---|---|
protected BodyParserEngineManager |
bodyParserEngineManager |
protected FlashScope |
flashScope |
protected com.google.inject.Injector |
injector |
protected NinjaProperties |
ninjaProperties |
protected ParamParsers |
paramParsers |
protected Route |
route |
protected Session |
session |
protected Validation |
validation |
CONTENT_TYPE, NINJA_PROPERTIES_X_FORWARDED_FOR, X_FORWARD_HEADER| Constructor and Description |
|---|
AbstractContext(BodyParserEngineManager bodyParserEngineManager,
FlashScope flashScope,
NinjaProperties ninjaProperties,
Session session,
Validation validation,
com.google.inject.Injector injector,
ParamParsers paramParsers) |
| Modifier and Type | Method and Description |
|---|---|
void |
asyncRequestComplete()
Indicate that processing this request is complete.
|
ResponseStreams |
finalizeHeaders(Result result)
Finalizing the headers copies all stuff into the headers.
|
protected ResponseStreams |
finalizeHeaders(Result result,
Boolean handleFlashAndSessionCookie) |
ResponseStreams |
finalizeHeadersWithoutFlashAndSessionCookie(Result result)
Finalizing the headers copies all stuff into the headers.
|
String |
getAcceptCharset()
Get the charset that is acceptable for the client.
|
String |
getAcceptContentType()
Get the content type that is acceptable for the client.
|
String |
getAcceptEncoding()
Get the encoding that is acceptable for the client.
|
String |
getAcceptLanguage()
Get the language that is acceptable for the client.
|
<T> T |
getAttribute(String name,
Class<T> clazz)
Gets an attribute value previously set by
Context.setAttribute(java.lang.String, java.lang.Object). |
String |
getContextPath()
Get the context path on which the application is running
That means:
- when running on root the context path is empty
- when running on context there is NEVER a trailing slash
We conform to the following rules:
Returns the portion of the request URI that indicates the context of the
request.
|
String |
getCookieValue(String name)
Get the cookie value from the request, if defined
|
FlashScope |
getFlashCookie()
Deprecated.
|
FlashScope |
getFlashScope()
Returns the flash cookie.
|
String |
getParameter(String key,
String defaultValue)
Same like
Context.getParameter(String), but returns given defaultValue
instead of null in case parameter cannot be found. |
<T> T |
getParameterAs(String key,
Class<T> clazz)
Same like
Context.getParameter(String), but converts the parameter to
Class type if found. |
<T> T |
getParameterAs(String key,
Class<T> clazz,
T defaultValue)
Same like
Context.getParameter(String, String), but converts the
parameter to Class type if found. |
Integer |
getParameterAsInteger(String key)
Same like
Context.getParameter(String), but converts the parameter to
Integer if found. |
Integer |
getParameterAsInteger(String key,
Integer defaultValue)
Same like
Context.getParameter(String, String), but converts the
parameter to Integer if found. |
String |
getPathParameter(String key)
Get the path parameter for the given key.
|
Integer |
getPathParameterAsInteger(String key)
Get the path parameter for the given key and convert it to Integer.
|
String |
getPathParameterEncoded(String key)
Get the path parameter for the given key.
|
protected abstract String |
getRealRemoteAddr()
Get the "real" address of the client connection.
|
String |
getRemoteAddr()
Returns the Internet Protocol (IP) address of the client
or last proxy that sent the request.
|
String |
getRequestPath()
Returns the path that Ninja should act upon.
|
Route |
getRoute()
Get the route for this context
|
Session |
getSession()
Returns the client side session.
|
Session |
getSessionCookie()
Deprecated.
|
Validation |
getValidation()
Get the validation context
|
protected void |
init(String contextPath,
String requestPath) |
boolean |
isRequestJson()
Check to see if the request content type is JSON.
|
boolean |
isRequestXml()
Check to see if the request content type is XML.
|
<T> T |
parseBody(Class<T> classOfT)
This will give you the request body nicely parsed.
|
void |
setRoute(Route route) |
void |
unsetCookie(Cookie cookie)
Removes a cookie from the response
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddCookie, cleanup, controllerReturned, getAttribute, getAttributes, getCookie, getCookies, getFileItemIterator, getHeader, getHeaders, getHeaders, getHostname, getInputStream, getMethod, getParameter, getParameterAsFileItem, getParameterAsFileItems, getParameterFileItems, getParameters, getParameterValues, getReader, getRequestContentType, getRequestUri, getScheme, handleAsync, hasCookie, isAsync, isMultipart, returnResultAsync, setAttributeprotected final BodyParserEngineManager bodyParserEngineManager
protected final FlashScope flashScope
protected final NinjaProperties ninjaProperties
protected final Session session
protected final Validation validation
protected final com.google.inject.Injector injector
protected final ParamParsers paramParsers
protected Route route
@Inject public AbstractContext(BodyParserEngineManager bodyParserEngineManager, FlashScope flashScope, NinjaProperties ninjaProperties, Session session, Validation validation, com.google.inject.Injector injector, ParamParsers paramParsers)
public void setRoute(Route route)
setRoute in interface Context.Implpublic Route getRoute()
Contextpublic Validation getValidation()
ContextgetValidation in interface Context@Deprecated public FlashScope getFlashCookie()
ContextgetFlashCookie in interface Contextpublic FlashScope getFlashScope()
ContextgetFlashScope in interface Context@Deprecated public Session getSessionCookie()
ContextgetSessionCookie in interface Contextpublic Session getSession()
ContextgetSession in interface Contextpublic String getContextPath()
ContextgetContextPath in interface Contextpublic String getRequestPath()
ContextgetRequestPath in interface Contextprotected abstract String getRealRemoteAddr()
public String getRemoteAddr()
ContextREMOTE_ADDR.
To honour the X-Forwarded-For flag make sure you set
"ninja.x_forwarded_for_enabled=true" in your application.conf. Default
behavior is NOT to take X-Forwarded-For flag into account.getRemoteAddr in interface ContextString containing the
IP address of the client that sent the request. Takes into
account X-Forwarded-For header if configured to do so.public <T> T getAttribute(String name, Class<T> clazz)
ContextContext.setAttribute(java.lang.String, java.lang.Object).
This is a convenience method, equivalent to:
return clazz.cast(getAttribute(name));
Attributes are shared state for the duration of the request;
useful to pass values between filters and
controllers.
getAttribute in interface Contextnull if the attribute does
not existpublic String getPathParameter(String key)
ContextgetPathParameter in interface Contextkey - The name of the path parameter in a route. Eg
/{myName}/rest/of/urlpublic String getPathParameterEncoded(String key)
ContextgetPathParameterEncoded in interface Contextkey - The name of the path parameter in a route. Eg
/{myName}/rest/of/urlpublic Integer getPathParameterAsInteger(String key)
ContextgetPathParameterAsInteger in interface Contextkey - the key of the path parameterpublic String getParameter(String key, String defaultValue)
ContextContext.getParameter(String), but returns given defaultValue
instead of null in case parameter cannot be found.
The parameter is decoded by default.getParameter in interface Contextkey - The name of the post or query parameterdefaultValue - A default value if parameter not found.public Integer getParameterAsInteger(String key)
ContextContext.getParameter(String), but converts the parameter to
Integer if found.
The parameter is decoded by default.getParameterAsInteger in interface Contextkey - The name of the post or query parameterpublic Integer getParameterAsInteger(String key, Integer defaultValue)
ContextContext.getParameter(String, String), but converts the
parameter to Integer if found.
The parameter is decoded by default.getParameterAsInteger in interface Contextkey - The name of the post or query parameterdefaultValue - A default value if parameter not found.public <T> T getParameterAs(String key, Class<T> clazz)
ContextContext.getParameter(String), but converts the parameter to
Class type if found.
The parameter is decoded by default.getParameterAs in interface Contextkey - The name of the post or query parameterpublic <T> T getParameterAs(String key, Class<T> clazz, T defaultValue)
ContextContext.getParameter(String, String), but converts the
parameter to Class type if found.
The parameter is decoded by default.getParameterAs in interface Contextkey - The name of the post or query parameterdefaultValue - A default value if parameter not found.public <T> T parseBody(Class<T> classOfT)
ContextBodyParserEngine
BodyParserEngineJson BodyParserEngineXml
and BodyParserEngineManagerpublic String getCookieValue(String name)
ContextgetCookieValue in interface Contextname - The name of the cookiepublic void unsetCookie(Cookie cookie)
ContextunsetCookie in interface Contextcookie - Ninja Cookiepublic void asyncRequestComplete()
ContextasyncRequestComplete in interface Contextprotected ResponseStreams finalizeHeaders(Result result, Boolean handleFlashAndSessionCookie)
public ResponseStreams finalizeHeadersWithoutFlashAndSessionCookie(Result result)
ContextfinalizeHeadersWithoutFlashAndSessionCookie in interface Contextpublic ResponseStreams finalizeHeaders(Result result)
ContextfinalizeHeaders in interface Contextpublic String getAcceptContentType()
ContextResult.TEXT_HTML > Result.APPLICATION_XML > Result.APPLICATION_JSON > Result.TEXT_PLAIN > Result.APPLICATION_OCTET_STREAM level- or quality-parameter are ignored
with this method.) E.g. Accept: text/*;q=0.3, text/html;q=0.7,
text/html;level=1,text/html;level=2;q=0.4
The Accept request-header field can be used to specify certain media
types which are acceptable for the response. Accept headers can be used
to indicate that the request is specifically limited to a small set of
desired types, as in the case of a request for an in-line image.getAcceptContentType in interface ContextResult mime types that is acceptable for the
client or Result.TEXT_HTML if not setpublic String getAcceptEncoding()
ContextgetAcceptEncoding in interface Contextpublic String getAcceptLanguage()
ContextgetAcceptLanguage in interface Contextpublic String getAcceptCharset()
ContextgetAcceptCharset in interface Contextpublic boolean isRequestJson()
ContextChecks to see if the request content type has been set application/json
isRequestJson in interface Contextapplication/jsonpublic boolean isRequestXml()
ContextChecks to see if the request content type has been set application/xml
isRequestXml in interface Contextapplication/xmlCopyright © 2019 ninjaframework. All rights reserved.