-
- All Known Subinterfaces:
SpiContext
public interface ContextProvides access to functions for handling the request and response.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> Tattribute(String key)Get the specified attribute from the request.Contextattribute(String key, Object value)Sets an attribute on the request.Map<String,Object>attributeMap()Gets a map with all the attribute keys and values on the request.Stringbody()Return the request body as String.byte[]bodyAsBytes()Return the request body as bytes.<T> TbodyAsClass(Class<T> beanType)Return the request body as bean.longcontentLength()Return the request content length.StringcontentType()Return the request content type.ContextcontentType(String contentType)Set the response content type.StringcontextPath()Return the request context path.Stringcookie(String name)Return a request cookie by name, or null.Contextcookie(String name, String value)Sets a cookie with name, value with unlimited age.Contextcookie(String name, String value, int maxAge)Sets a cookie with name, value, and max-age.Contextcookie(javax.servlet.http.Cookie cookie)Sets a Cookie.Map<String,String>cookieMap()Returns a map with all the cookie keys and values on the request.StringformParam(String key)Return the first form param value for the specified key or null.StringformParam(String key, String defaultValue)Return the first form param value for the specified key or the default value.Map<String,List<String>>formParamMap()Returns a map with all the form param keys and values.List<String>formParams(String key)Return the form params for the specified key, or empty list.StringfullUrl()Return the full request url, including query string (if present)Stringheader(String key)Return the request header.voidheader(String key, String value)Set the response header.Map<String,String>headerMap()Return all the request headers as a map.Stringhost()Returns the request host, or null.Contexthtml(String content)Write html content to the response.Stringip()Returns the request IP.booleanisMultipart()Returns true if request is multipart.booleanisMultipartFormData()Returns true if request is multipart/form-data.Contextjson(Object bean)Set the response body as JSON for the given bean.StringmatchedPath()Return the matched path as a raw expression.Stringmethod()Returns the request method.Stringpath()Return the request path.StringpathParam(String name)Return the path parameter.Map<String,String>pathParamMap()Return all the path parameters as a map.intport()Return the request port.Stringprotocol()Return the request protocol.StringqueryParam(String name)Return the first query parameter value.Map<String,String>queryParamMap()Return all the query parameters as a map.List<String>queryParams(String name)Return all the query parameters for the given parameter name.StringqueryString()Return the request query string, or null.voidredirect(String location)Redirect to the specified location using 302 status code.voidredirect(String location, int httpStatusCode)Redirect to the location specifying the response status code.ContextremoveCookie(String name)Remove a cookie by name.ContextremoveCookie(String name, String path)Remove a cookie by name and path.Contextrender(String name)Render a template typically as html.Contextrender(String name, Map<String,Object> model)Render a template typically as html with the given model.javax.servlet.http.HttpServletRequestreq()Return the underlying http servlet request.javax.servlet.http.HttpServletResponseres()Return the underlying http servlet response.Stringscheme()Return the request scheme.<T> TsessionAttribute(String key)Gets specified attribute from the user session, or null.ContextsessionAttribute(String key, Object value)Sets an attribute for the user session.Map<String,Object>sessionAttributeMap()Return a map of all the attributes in the user session.intstatus()Return the current response status.Contextstatus(int statusCode)Set the status code on the response.Contexttext(String content)Write plain text content to the response.UploadedFileuploadedFile(String name)Return the first UploadedFile for the specified name or null.List<UploadedFile>uploadedFiles(String name)Return a list of UploadedFiles for the specified name, or empty list.Stringurl()Return the request url.StringuserAgent()Return the request user agent, or null.Contextwrite(String content)Write raw content to the response.
-
-
-
Method Detail
-
matchedPath
String matchedPath()
Return the matched path as a raw expression.
-
attribute
Context attribute(String key, Object value)
Sets an attribute on the request. Attributes are available to other handlers in the request lifecycle
-
attribute
<T> T attribute(String key)
Get the specified attribute from the request.
-
attributeMap
Map<String,Object> attributeMap()
Gets a map with all the attribute keys and values on the request.
-
cookieMap
Map<String,String> cookieMap()
Returns a map with all the cookie keys and values on the request.
-
cookie
Context cookie(String name, String value)
Sets a cookie with name, value with unlimited age.
-
cookie
Context cookie(String name, String value, int maxAge)
Sets a cookie with name, value, and max-age.
-
cookie
Context cookie(javax.servlet.http.Cookie cookie)
Sets a Cookie.
-
redirect
void redirect(String location)
Redirect to the specified location using 302 status code.
-
redirect
void redirect(String location, int httpStatusCode)
Redirect to the location specifying the response status code.
-
bodyAsBytes
byte[] bodyAsBytes()
Return the request body as bytes.
-
bodyAsClass
<T> T bodyAsClass(Class<T> beanType)
Return the request body as bean.- Parameters:
beanType- The bean type
-
body
String body()
Return the request body as String.
-
contentLength
long contentLength()
Return the request content length.
-
contentType
String contentType()
Return the request content type.
-
pathParam
String pathParam(String name)
Return the path parameter.- Parameters:
name- The path parameter name.
-
queryParam
String queryParam(String name)
Return the first query parameter value.- Parameters:
name- The query parameter name
-
queryParams
List<String> queryParams(String name)
Return all the query parameters for the given parameter name.
-
queryParamMap
Map<String,String> queryParamMap()
Return all the query parameters as a map.Note this returns the first value for any given key if that key has multiple values.
-
queryString
String queryString()
Return the request query string, or null.
-
formParam
String formParam(String key)
Return the first form param value for the specified key or null.
-
formParam
String formParam(String key, String defaultValue)
Return the first form param value for the specified key or the default value.
-
formParams
List<String> formParams(String key)
Return the form params for the specified key, or empty list.
-
formParamMap
Map<String,List<String>> formParamMap()
Returns a map with all the form param keys and values.
-
scheme
String scheme()
Return the request scheme.
-
sessionAttribute
Context sessionAttribute(String key, Object value)
Sets an attribute for the user session.
-
sessionAttribute
<T> T sessionAttribute(String key)
Gets specified attribute from the user session, or null.
-
sessionAttributeMap
Map<String,Object> sessionAttributeMap()
Return a map of all the attributes in the user session.
-
url
String url()
Return the request url.
-
fullUrl
String fullUrl()
Return the full request url, including query string (if present)
-
contextPath
String contextPath()
Return the request context path.
-
userAgent
String userAgent()
Return the request user agent, or null.
-
status
Context status(int statusCode)
Set the status code on the response.
-
status
int status()
Return the current response status.
-
render
Context render(String name)
Render a template typically as html.- Parameters:
name- The template name
-
render
Context render(String name, Map<String,Object> model)
Render a template typically as html with the given model.- Parameters:
name- The template namemodel- The model used with the template
-
header
void header(String key, String value)
Set the response header.- Parameters:
key- The header keyvalue- The header value
-
host
String host()
Returns the request host, or null.
-
ip
String ip()
Returns the request IP.
-
isMultipart
boolean isMultipart()
Returns true if request is multipart.
-
isMultipartFormData
boolean isMultipartFormData()
Returns true if request is multipart/form-data.
-
method
String method()
Returns the request method.
-
path
String path()
Return the request path.
-
port
int port()
Return the request port.
-
protocol
String protocol()
Return the request protocol.
-
req
javax.servlet.http.HttpServletRequest req()
Return the underlying http servlet request.
-
res
javax.servlet.http.HttpServletResponse res()
Return the underlying http servlet response.
-
uploadedFile
UploadedFile uploadedFile(String name)
Return the first UploadedFile for the specified name or null.
-
uploadedFiles
List<UploadedFile> uploadedFiles(String name)
Return a list of UploadedFiles for the specified name, or empty list.
-
-