- All Known Subinterfaces:
SpiContext
public interface Context
Provides access to functions for handling the request and response.
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classContext.Cookie -
Method Summary
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()Deprecated.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.Contextcookie(Context.Cookie cookie)Sets a Cookie.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.Map<String,String>cookieMap()Returns a map with all the cookie keys and values on the request.default StringformParam(String key)Return the first form param value for the specified key or null.default 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.default List<String>formParams(String key)Return the form params for the specified key, or empty list.default StringfullUrl()Return the full request url, including query string (if present)Stringheader(String key)Return the request header.Contextheader(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.<E> ContextjsonStream(Iterator<E> iterator)Write the stream as a JSON stream with new line delimiters application/x-json-stream.<E> ContextjsonStream(Stream<E> stream)Write the stream as a JSON stream with new line delimiters application/x-json-stream.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.default 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.StringresponseHeader(String key)Return the response header.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()Return a list of all UploadedFiles.List<UploadedFile>uploadedFiles(String name)Return a list of UploadedFiles for the specified name, or empty list.Stringurl()Return the request url.default StringuserAgent()Return the request user agent, or null.Contextwrite(String content)Write raw content to the response.
-
Method Details
-
matchedPath
String matchedPath()Return the matched path as a raw expression. -
attribute
Sets an attribute on the request.Attributes are available to other handlers in the request lifecycle
-
attribute
Get the specified attribute from the request. -
attributeMap
Deprecated.Deprecated for removal - not supported by JDK http server.Gets a map with all the attribute keys and values on the request.
-
cookie
Return a request cookie by name, or null. -
cookieMap
Returns a map with all the cookie keys and values on the request. -
cookie
Sets a cookie with name, value with unlimited age. -
cookie
Sets a cookie with name, value, and max-age. -
cookie
Sets a Cookie. -
removeCookie
Remove a cookie by name. -
removeCookie
Remove a cookie by name and path. -
redirect
Redirect to the specified location using 302 status code. -
redirect
Redirect to the location specifying the response status code. -
bodyAsBytes
byte[] bodyAsBytes()Return the request body as bytes. -
bodyAsClass
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. -
contentType
Set the response content type. -
pathParamMap
Return all the path parameters as a map. -
pathParam
Return the path parameter.- Parameters:
name- The path parameter name.
-
queryParam
Return the first query parameter value.- Parameters:
name- The query parameter name
-
queryParams
Return all the query parameters for the given parameter name. -
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
Return the first form param value for the specified key or null. -
formParam
Return the first form param value for the specified key or the default value. -
formParams
Return the form params for the specified key, or empty list. -
formParamMap
Returns a map with all the form param keys and values. -
scheme
String scheme()Return the request scheme. -
sessionAttribute
Sets an attribute for the user session. -
sessionAttribute
Gets specified attribute from the user session, or null. -
sessionAttributeMap
Return a map of all the attributes in the user session. -
url
String url()Return the request url. -
fullUrl
Return the full request url, including query string (if present) -
contextPath
String contextPath()Return the request context path. -
userAgent
Return the request user agent, or null. -
status
Set the status code on the response. -
status
int status()Return the current response status. -
text
Write plain text content to the response. -
html
Write html content to the response. -
json
Set the response body as JSON for the given bean. -
jsonStream
Write the stream as a JSON stream with new line delimiters application/x-json-stream.- Parameters:
stream- The stream of beans to write as json
-
jsonStream
Write the stream as a JSON stream with new line delimiters application/x-json-stream.- Parameters:
iterator- The iterator of beans to write as json
-
write
Write raw content to the response. -
render
Render a template typically as html.- Parameters:
name- The template name
-
render
Render a template typically as html with the given model.- Parameters:
name- The template namemodel- The model used with the template
-
headerMap
Return all the request headers as a map. -
header
Return the request header.- Parameters:
key- The header key
-
header
Set the response header.- Parameters:
key- The header keyvalue- The header value
-
responseHeader
Return the response header. -
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. -
uploadedFile
Return the first UploadedFile for the specified name or null. -
uploadedFiles
Return a list of UploadedFiles for the specified name, or empty list. -
uploadedFiles
List<UploadedFile> uploadedFiles()Return a list of all UploadedFiles.
-