Context.HTTP_STATUS, Context.Impl
CONTENT_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()
Context
getRequestUri
in interface Context
public String getHostname()
Context
getHostname
in interface Context
public String getScheme()
Context
public String getRemoteAddr()
Context
REMOTE_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 Context
String
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()
Context
getFlashCookie
in interface Context
public Session getSessionCookie()
Context
getSessionCookie
in interface Context
public FlashScope getFlashScope()
Context
getFlashScope
in interface Context
public Session getSession()
Context
getSession
in interface Context
public String getParameter(String key)
Context
When the parameter is multivalued, returns the first value.
The parameter is decoded by default.
getParameter
in interface Context
key
- The key of the parameterContext.getParameterValues(java.lang.String)
public List<String> getParameterValues(String name)
Context
The parameter is decoded by default.
getParameterValues
in interface Context
name
- The key of the parameterpublic String getParameter(String key, String defaultValue)
Context
Context.getParameter(String)
, but returns given defaultValue
instead of null in case parameter cannot be found.
The parameter is decoded by default.getParameter
in interface Context
key
- The name of the post or query parameterdefaultValue
- A default value if parameter not found.public Integer getParameterAsInteger(String key)
Context
Context.getParameter(String)
, but converts the parameter to
Integer if found.
The parameter is decoded by default.getParameterAsInteger
in interface Context
key
- The name of the post or query parameterpublic Integer getParameterAsInteger(String key, Integer defaultValue)
Context
Context.getParameter(String, String)
, but converts the
parameter to Integer if found.
The parameter is decoded by default.getParameterAsInteger
in interface Context
key
- The name of the post or query parameterdefaultValue
- A default value if parameter not found.public FileItem getParameterAsFileItem(String key)
Context
Context.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 Context
key
- The name of the post or query parameterpublic List<FileItem> getParameterAsFileItems(String name)
Context
getParameterAsFileItems
in interface Context
name
- The key of the parameterpublic Map<String,List<FileItem>> getParameterFileItems()
Context
getParameterFileItems
in interface Context
public <T> T getParameterAs(String key, Class<T> clazz)
Context
Context.getParameter(String)
, but converts the parameter to
Class type if found.
The parameter is decoded by default.getParameterAs
in interface Context
key
- The name of the post or query parameterpublic <T> T getParameterAs(String key, Class<T> clazz, T defaultValue)
Context
Context.getParameter(String, String)
, but converts the
parameter to Class type if found.
The parameter is decoded by default.getParameterAs
in interface Context
key
- The name of the post or query parameterdefaultValue
- A default value if parameter not found.public String getPathParameter(String key)
Context
getPathParameter
in interface Context
key
- The name of the path parameter in a route. Eg
/{myName}/rest/of/urlpublic Integer getPathParameterAsInteger(String key)
Context
getPathParameterAsInteger
in interface Context
key
- the key of the path parameterpublic Map<String,String[]> getParameters()
Context
getParameters
in interface Context
public String getHeader(String name)
Context
public List<String> getHeaders(String name)
Context
getHeaders
in interface Context
public Map<String,List<String>> getHeaders()
Context
getHeaders
in interface Context
public String getCookieValue(String name)
Context
getCookieValue
in interface Context
name
- The name of the cookiepublic <T> T parseBody(Class<T> classOfT)
Context
BodyParserEngine
BodyParserEngineJson
BodyParserEngineXml
and BodyParserEngineManager
public void handleAsync()
Context
handleAsync
in interface Context
public void returnResultAsync(Result result)
Context
returnResultAsync
in interface Context
public void asyncRequestComplete()
Context
asyncRequestComplete
in interface Context
public Result controllerReturned()
controllerReturned
in interface Context
public ResponseStreams finalizeHeaders(Result result)
Context
finalizeHeaders
in interface Context
public ResponseStreams finalizeHeadersWithoutFlashAndSessionCookie(Result result)
Context
finalizeHeadersWithoutFlashAndSessionCookie
in interface Context
public InputStream getInputStream() throws IOException
Context
getInputStream
in interface Context
IOException
public BufferedReader getReader() throws IOException
Context
getReader
in interface Context
IOException
public String getRequestContentType()
Context
Content-Type: text/html;
charset=ISO-8859-4
getRequestContentType
in interface Context
public Route getRoute()
Context
public boolean isMultipart()
Context
isMultipart
in interface Context
public org.apache.commons.fileupload.FileItemIterator getFileItemIterator()
Context
getFileItemIterator
in interface Context
public String getRequestPath()
Context
getRequestPath
in interface Context
public Validation getValidation()
Context
getValidation
in interface Context
public String getPathParameterEncoded(String key)
Context
getPathParameterEncoded
in interface Context
key
- The name of the path parameter in a route. Eg
/{myName}/rest/of/urlpublic String getAcceptContentType()
Context
Result.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 Context
Result
mime types that is acceptable for the
client or Result.TEXT_HTML
if not setpublic String getAcceptEncoding()
Context
getAcceptEncoding
in interface Context
public String getAcceptLanguage()
Context
getAcceptLanguage
in interface Context
public String getAcceptCharset()
Context
getAcceptCharset
in interface Context
public Cookie getCookie(String cookieName)
Context
public boolean hasCookie(String cookieName)
Context
public List<Cookie> getCookies()
Context
getCookies
in interface Context
public String getMethod()
Context
public Object getAttribute(String name)
Context
Context.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 Context
null
if the attribute does
not existpublic <T> T getAttribute(String name, Class<T> clazz)
Context
Context.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 Context
null
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 Context
Context.getAttribute(String)
,
Context.getAttribute(String, Class)
public Map<String,Object> getAttributes()
Context
getAttributes
in interface Context
public String getContextPath()
Context
getContextPath
in interface Context
public boolean isRequestJson()
Context
Checks to see if the request content type has been set application/json
isRequestJson
in interface Context
application/json
public boolean isRequestXml()
Context
Checks to see if the request content type has been set application/xml
isRequestXml
in interface Context
application/xml
public void addCookie(Cookie cookie)
Context
public void unsetCookie(Cookie cookie)
Context
unsetCookie
in interface Context
cookie
- Ninja CookieCopyright © 2019 ninjaframework. All rights reserved.