public interface Context
Modifier and Type | Interface and Description |
---|---|
static class |
Context.HTTP_STATUS
Deprecated.
|
static interface |
Context.Impl
Impl is used to hide stuff that a user should not see on
code completion.
|
Modifier and Type | Field and Description |
---|---|
static String |
CONTENT_TYPE
Content-Type: ...
|
static String |
NINJA_PROPERTIES_X_FORWARDED_FOR
Used to enable or disable usage of X-Forwarded-For header in
getRemoteAddr().
|
static String |
X_FORWARD_HEADER
X Forwarded for header, used when behind fire walls and proxies.
|
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
setAttribute(java.lang.String, java.lang.Object) . |
<T> T |
getAttribute(String name,
Class<T> clazz)
Gets an attribute value previously set by
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()
Deprecated.
This method is kept for backward compatibility, use
FileProvider
to specify which FileItemProvider should be used to handle uploaded files, and
access them using getParameterAsFileItem(String) . |
FlashScope |
getFlashCookie()
Deprecated.
|
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 name)
Get the parameter with the given key from the request.
|
String |
getParameter(String name,
String defaultValue)
Same like
getParameter(String) , but returns given defaultValue
instead of null in case parameter cannot be found. |
<T> T |
getParameterAs(String name,
Class<T> clazz)
Same like
getParameter(String) , but converts the parameter to
Class type if found. |
<T> T |
getParameterAs(String name,
Class<T> clazz,
T defaultValue)
Same like
getParameter(String, String) , but converts the
parameter to Class type if found. |
FileItem |
getParameterAsFileItem(String name)
Same like
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 name)
Same like
getParameter(String) , but converts the parameter to
Integer if found. |
Integer |
getParameterAsInteger(String name,
Integer defaultValue)
Same like
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 name)
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 name)
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()
Deprecated.
|
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.
|
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
|
static final String CONTENT_TYPE
static final String X_FORWARD_HEADER
static final String NINJA_PROPERTIES_X_FORWARDED_FOR
String getRequestContentType()
Content-Type: text/html;
charset=ISO-8859-4
@Deprecated String getRequestUri()
String getHostname()
String getScheme()
String getRemoteAddr()
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.String
containing the
IP address of the client that sent the request. Takes into
account X-Forwarded-For header if configured to do so.String getRequestPath()
FlashScope getFlashScope()
@Deprecated FlashScope getFlashCookie()
Session getSession()
@Deprecated Session getSessionCookie()
Cookie getCookie(String cookieName)
cookieName
- Name of the cookie to retrieveboolean hasCookie(String cookieName)
cookieName
- Name of the cookie to check fortrue
if the context has a cookie with that name.List<Cookie> getCookies()
String getContextPath()
String getParameter(String name)
When the parameter is multivalued, returns the first value.
The parameter is decoded by default.
name
- The key of the parametergetParameterValues(java.lang.String)
List<String> getParameterValues(String name)
The parameter is decoded by default.
name
- The key of the parameterString getParameter(String name, String defaultValue)
getParameter(String)
, but returns given defaultValue
instead of null in case parameter cannot be found.
The parameter is decoded by default.name
- The name of the post or query parameterdefaultValue
- A default value if parameter not found.Integer getParameterAsInteger(String name)
getParameter(String)
, but converts the parameter to
Integer if found.
The parameter is decoded by default.name
- The name of the post or query parameterInteger getParameterAsInteger(String name, Integer defaultValue)
getParameter(String, String)
, but converts the
parameter to Integer if found.
The parameter is decoded by default.name
- The name of the post or query parameterdefaultValue
- A default value if parameter not found.FileItem getParameterAsFileItem(String name)
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.name
- The name of the post or query parameterList<FileItem> getParameterAsFileItems(String name)
name
- The key of the parameterMap<String,List<FileItem>> getParameterFileItems()
<T> T getParameterAs(String name, Class<T> clazz)
getParameter(String)
, but converts the parameter to
Class type if found.
The parameter is decoded by default.name
- The name of the post or query parameter<T> T getParameterAs(String name, Class<T> clazz, T defaultValue)
getParameter(String, String)
, but converts the
parameter to Class type if found.
The parameter is decoded by default.name
- The name of the post or query parameterdefaultValue
- A default value if parameter not found.String getPathParameter(String name)
name
- The name of the path parameter in a route. Eg
/{myName}/rest/of/urlString getPathParameterEncoded(String name)
name
- The name of the path parameter in a route. Eg
/{myName}/rest/of/urlInteger getPathParameterAsInteger(String key)
key
- the key of the path parameterMap<String,String[]> getParameters()
String getHeader(String name)
List<String> getHeaders(String name)
Map<String,List<String>> getHeaders()
String getCookieValue(String name)
name
- The name of the cookie<T> T parseBody(Class<T> classOfT)
BodyParserEngine
BodyParserEngineJson
BodyParserEngineXml
and BodyParserEngineManager
classOfT
- The class of the result.boolean isAsync()
void handleAsync()
void returnResultAsync(Result result)
void asyncRequestComplete()
Result controllerReturned()
ResponseStreams finalizeHeaders(Result result)
ResponseStreams finalizeHeadersWithoutFlashAndSessionCookie(Result result)
InputStream getInputStream() throws IOException
IOException
BufferedReader getReader() throws IOException
IOException
Route getRoute()
boolean isMultipart()
@Deprecated org.apache.commons.fileupload.FileItemIterator getFileItemIterator()
FileProvider
to specify which FileItemProvider
should be used to handle uploaded files, and
access them using getParameterAsFileItem(String)
.Validation getValidation()
String getAcceptContentType()
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.Result
mime types that is acceptable for the
client or Result.TEXT_HTML
if not setString getAcceptEncoding()
String getAcceptLanguage()
String getAcceptCharset()
String getMethod()
String
specifying the name
of the method with which
this request was made (eg GET, POST, PUT...)Object getAttribute(String name)
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.
null
if the attribute does
not exist<T> T getAttribute(String name, Class<T> clazz)
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.
null
if the attribute does
not existvoid setAttribute(String name, Object value)
Attributes are shared state for the duration of the request;
useful to pass values between filters
and
controllers.
getAttribute(String)
,
getAttribute(String, Class)
Map<String,Object> getAttributes()
boolean isRequestJson()
Checks to see if the request content type has been set application/json
application/json
boolean isRequestXml()
Checks to see if the request content type has been set application/xml
application/xml
void addCookie(Cookie cookie)
cookie
- Ninja cookievoid unsetCookie(Cookie cookie)
cookie
- Ninja Cookievoid cleanup()
Copyright © 2019 ninjaframework. All rights reserved.