Context.HTTP_STATUS, Context.ImplCONTENT_TYPE, NINJA_PROPERTIES_X_FORWARDED_FOR, X_FORWARD_HEADER| Constructor and Description |
|---|
WrappedContext(Context wrapped) |
| Modifier and Type | Method and Description |
|---|---|
void |
addCookie(Cookie cookie)
Adds a cookie to the response
|
void |
asyncRequestComplete()
Indicate that processing this request is complete.
|
void |
cleanup()
Cleanup context
|
Result |
controllerReturned() |
ResponseStreams |
finalizeHeaders(Result result)
Finalizing the headers copies all stuff into the headers.
|
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.
|
Object |
getAttribute(String name)
Gets an attribute value previously set by
Context.setAttribute(java.lang.String, java.lang.Object). |
<T> T |
getAttribute(String name,
Class<T> clazz)
Gets an attribute value previously set by
Context.setAttribute(java.lang.String, java.lang.Object). |
Map<String,Object> |
getAttributes()
Get all the attributes from the request
|
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.
|
Cookie |
getCookie(String cookieName)
Get cookie from context.
|
List<Cookie> |
getCookies()
Get all cookies from the context.
|
String |
getCookieValue(String name)
Get the cookie value from the request, if defined
|
org.apache.commons.fileupload.FileItemIterator |
getFileItemIterator()
Gets the FileItemIterator of the input.
|
FlashScope |
getFlashCookie()
Deprecated => please use getFlashScope()
|
FlashScope |
getFlashScope()
Returns the flash cookie.
|
String |
getHeader(String name)
Get the (first) request header with the given name
|
Map<String,List<String>> |
getHeaders()
Get all the headers from the request
|
List<String> |
getHeaders(String name)
Get all the request headers with the given name.
|
String |
getHostname()
Returns the hostname as seen by the server.
|
InputStream |
getInputStream()
Get the input stream to read the request.
|
String |
getMethod()
Returns the name of the HTTP method with which this
request was made, for example, GET, POST, or PUT.
|
String |
getParameter(String key)
Get the parameter with the given key from the request.
|
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. |
FileItem |
getParameterAsFileItem(String key)
Same like
Context.getParameter(String, String), but converts the
parameter to File if found. |
List<FileItem> |
getParameterAsFileItems(String name)
Get the files parameter with the given key from the request.
|
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. |
Map<String,List<FileItem>> |
getParameterFileItems()
Get all the file parameters from the request
|
Map<String,String[]> |
getParameters()
Get all the parameters from the request
|
List<String> |
getParameterValues(String name)
Get the parameter with the given key from the request.
|
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.
|
BufferedReader |
getReader()
Get the reader to read the request.
|
String |
getRemoteAddr()
Returns the Internet Protocol (IP) address of the client
or last proxy that sent the request.
|
String |
getRequestContentType()
The Content-Type header field indicates the media type of the request
body sent to the recipient.
|
String |
getRequestPath()
Returns the path that Ninja should act upon.
|
String |
getRequestUri()
Returns the uri as seen by the server.
|
Route |
getRoute()
Get the route for this context
|
String |
getScheme()
For instance:
http://example.com/index returns "http".
|
Session |
getSession()
Returns the client side session.
|
Session |
getSessionCookie()
Deprecated => please use getSession();
|
Validation |
getValidation()
Get the validation context
|
void |
handleAsync()
Indicate that this request is going to be handled asynchronously
|
boolean |
hasCookie(String cookieName)
Checks whether the context contains a given cookie.
|
boolean |
isAsync() |
boolean |
isMultipart()
Check if request is of type multipart.
|
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 |
returnResultAsync(Result result)
Indicate that request processing of an async request is complete.
|
void |
setAttribute(String name,
Object value)
Sets an attribute value.
|
void |
unsetCookie(Cookie cookie)
Removes a cookie from the response
|
public WrappedContext(Context wrapped)
public String getRequestUri()
ContextgetRequestUri in interface Contextpublic String getHostname()
ContextgetHostname in interface Contextpublic String getScheme()
Contextpublic 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 FlashScope getFlashCookie()
ContextgetFlashCookie in interface Contextpublic Session getSessionCookie()
ContextgetSessionCookie in interface Contextpublic FlashScope getFlashScope()
ContextgetFlashScope in interface Contextpublic Session getSession()
ContextgetSession in interface Contextpublic String getParameter(String key)
ContextWhen the parameter is multivalued, returns the first value.
The parameter is decoded by default.
getParameter in interface Contextkey - The key of the parameterContext.getParameterValues(java.lang.String)public List<String> getParameterValues(String name)
ContextThe parameter is decoded by default.
getParameterValues in interface Contextname - The key of the 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 FileItem getParameterAsFileItem(String key)
ContextContext.getParameter(String, String), but converts the
parameter to File if found.
The parameter is read from the multipart stream, using the FileProvider declared
on the route method, class.getParameterAsFileItem in interface Contextkey - The name of the post or query parameterpublic List<FileItem> getParameterAsFileItems(String name)
ContextgetParameterAsFileItems in interface Contextname - The key of the parameterpublic Map<String,List<FileItem>> getParameterFileItems()
ContextgetParameterFileItems in interface Contextpublic <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 String getPathParameter(String key)
ContextgetPathParameter 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 Map<String,String[]> getParameters()
ContextgetParameters in interface Contextpublic String getHeader(String name)
Contextpublic List<String> getHeaders(String name)
ContextgetHeaders in interface Contextpublic Map<String,List<String>> getHeaders()
ContextgetHeaders in interface Contextpublic String getCookieValue(String name)
ContextgetCookieValue in interface Contextname - The name of the cookiepublic <T> T parseBody(Class<T> classOfT)
ContextBodyParserEngine
BodyParserEngineJson BodyParserEngineXml
and BodyParserEngineManagerpublic void handleAsync()
ContexthandleAsync in interface Contextpublic void returnResultAsync(Result result)
ContextreturnResultAsync in interface Contextpublic void asyncRequestComplete()
ContextasyncRequestComplete in interface Contextpublic Result controllerReturned()
controllerReturned in interface Contextpublic ResponseStreams finalizeHeaders(Result result)
ContextfinalizeHeaders in interface Contextpublic ResponseStreams finalizeHeadersWithoutFlashAndSessionCookie(Result result)
ContextfinalizeHeadersWithoutFlashAndSessionCookie in interface Contextpublic InputStream getInputStream() throws IOException
ContextgetInputStream in interface ContextIOExceptionpublic BufferedReader getReader() throws IOException
ContextgetReader in interface ContextIOExceptionpublic String getRequestContentType()
ContextContent-Type: text/html;
charset=ISO-8859-4getRequestContentType in interface Contextpublic Route getRoute()
Contextpublic boolean isMultipart()
ContextisMultipart in interface Contextpublic org.apache.commons.fileupload.FileItemIterator getFileItemIterator()
ContextgetFileItemIterator in interface Contextpublic String getRequestPath()
ContextgetRequestPath in interface Contextpublic Validation getValidation()
ContextgetValidation in interface Contextpublic String getPathParameterEncoded(String key)
ContextgetPathParameterEncoded in interface Contextkey - The name of the path parameter in a route. Eg
/{myName}/rest/of/urlpublic 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 Cookie getCookie(String cookieName)
Contextpublic boolean hasCookie(String cookieName)
Contextpublic List<Cookie> getCookies()
ContextgetCookies in interface Contextpublic String getMethod()
Contextpublic Object getAttribute(String name)
ContextContext.setAttribute(java.lang.String, java.lang.Object).
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 <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 void setAttribute(String name, Object value)
Context
Attributes are shared state for the duration of the request;
useful to pass values between filters and
controllers.
setAttribute in interface ContextContext.getAttribute(String),
Context.getAttribute(String, Class)public Map<String,Object> getAttributes()
ContextgetAttributes in interface Contextpublic String getContextPath()
ContextgetContextPath 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/xmlpublic void addCookie(Cookie cookie)
Contextpublic void unsetCookie(Cookie cookie)
ContextunsetCookie in interface Contextcookie - Ninja CookieCopyright © 2019 ninjaframework. All rights reserved.