Context
but with couple of default methods.- Since:
- 2.0.2
- Author:
- edgar
-
Field Summary
Fields inherited from interface io.jooby.Context
ACCEPT, GMT, PORT, RFC1123, RFC1123_PATTERN, SECURE_PORT
-
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
True if the given type matches the `Accept` header.default MediaType
Check if the accept type list matches the given produces list and return the most specific media type from produces list.default <T> T
Convert the HTTP body to the given type.default <T> T
Convert the HTTP body to the given type.default <T> T
convertOrNull
(ValueNode value, Class<T> type) Converts a value (single or hash) into the given type.default Value
Get a cookie matching the given name.default <T> T
Convert the HTTP body to the given type.default MessageDecoder
Get a decoder for the given content type or get anStatusCode.UNSUPPORTED_MEDIA_TYPE
.default FileUpload
A file upload that matches the given field name.default List<FileUpload>
files()
All file uploads.default List<FileUpload>
All file uploads that matches the given field name.default FlashMap
flash()
Flash map.default Value
Get a flash attribute.default <T> T
Convert form data to the given type.default ValueNode
Get a form field that matches the given name.formMap()
Form data as single-value map.default Object
Forward executing to another route.default <T> T
getAttribute
(String key) Get an attribute by his key.default DataBufferFactory
default String
getHost()
Return the host that this request was sent to, in general this will be the value of the Host header, minus the port specifier.default String
Return the host and port that this request was sent to, in general this will be the value of the Host.default int
getPort()
Return the port that this request was sent to.default long
RequestContent-Length
header or-1
when missing.default MediaType
RequestContent-Type
header ornull
when missing.default MediaType
getRequestType
(MediaType defaults) RequestContent-Type
header ornull
when missing.default String
Recreates full/entire url of the current request using theHost
header.default String
getRequestURL
(String path) Recreates full/entire request url using theHost
header with a custom path/suffix.default String
Server host.default int
Server port for current request.default <T> T
getUser()
Current user ornull
if none was set.default Value
Get a header that matches the given name.Header as single-value map.default boolean
isSecure()
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.default boolean
Check if the request path matches the given pattern.default ValueNode
path()
ConvertContext.pathMap()
to aValueNode
object.default <T> T
Convert theContext.pathMap()
to the given type.default Value
Path variable.default <T> T
Convert the queryString to the given type.default ValueNode
Get a query parameter that matches the given name.queryMap()
Query string as simple map.default String
Query string with the leading?
default Context
Render a value and send the response to client.default <T> T
require
(ServiceKey<T> key) Provides an instance of the given type.default <T> T
Provides an instance of the given type.default <T> T
Provides an instance of the given type where name matches it.default OutputStream
responseStream
(MediaType contentType) HTTP response channel as output stream.default Context
responseStream
(MediaType contentType, SneakyThrows.Consumer<OutputStream> consumer) HTTP response channel as output stream.default Context
responseStream
(SneakyThrows.Consumer<OutputStream> consumer) HTTP response channel as output stream.default PrintWriter
HTTP response channel as response writer.default PrintWriter
responseWriter
(MediaType contentType) HTTP response channel as response writer.default Context
responseWriter
(MediaType contentType, SneakyThrows.Consumer<PrintWriter> consumer) HTTP response channel as response writer.default Context
responseWriter
(MediaType contentType, Charset charset, SneakyThrows.Consumer<PrintWriter> consumer) HTTP response channel as response writer.default Context
responseWriter
(SneakyThrows.Consumer<PrintWriter> consumer) HTTP response channel as response writer.default Context
send
(byte[]... data) Send response data.default Context
send
(FileDownload file) Send a file download response.default Context
Send response data.default Context
Send a file response.default Context
Send an error response.default Context
sendError
(Throwable cause, StatusCode code) Send an error response.default Context
sendRedirect
(StatusCode redirect, String location) Send a redirect response.default Context
sendRedirect
(String location) Send a302
response.default Session
session()
Find a session or creates a new session.default Value
Find a session attribute using the given name.default Session
Find an existing session.default Context
setAttribute
(String key, Object value) Set an application attribute.default Context
setResponseCode
(StatusCode statusCode) Set response status code.default Context
setResponseHeader
(String name, Object value) Set response header.default Context
setResponseHeader
(String name, Instant value) Set response header.default Context
setResponseHeader
(String name, Date value) Set response header.default Context
setResponseType
(MediaType contentType) Set response content type header.default Context
Set current user.Methods inherited from interface io.jooby.Context
body, convert, cookieMap, detach, dispatch, dispatch, form, getAttributes, getClientCertificates, getContextPath, getMethod, getProtocol, getRemoteAddress, getRequestPath, getResetHeadersOnError, getResponseCode, getResponseHeader, getResponseLength, getResponseType, getRoute, getRouter, getScheme, header, isInIoThread, isPreflight, isResponseStarted, locale, locale, locales, locales, lookup, lookup, lookup, onComplete, pathMap, query, removeResponseHeader, removeResponseHeaders, responseSender, responseStream, responseWriter, send, send, send, send, send, send, send, send, send, setDefaultResponseType, setHost, setMethod, setPathMap, setPort, setRemoteAddress, setRequestPath, setResetHeadersOnError, setResponseCode, setResponseCookie, setResponseHeader, setResponseLength, setResponseType, setResponseType, setRoute, setScheme, upgrade, upgrade
-
Method Details
-
require
@NonNull default <T> T require(@NonNull Class<T> type, @NonNull String name) throws RegistryException Description copied from interface:Registry
Provides an instance of the given type where name matches it.- Specified by:
require
in interfaceRegistry
- Type Parameters:
T
- Object type.- Parameters:
type
- Object type.name
- Object name.- Returns:
- Instance of this type.
- Throws:
RegistryException
- If there was a runtime failure while providing an instance.
-
require
Description copied from interface:Registry
Provides an instance of the given type.- Specified by:
require
in interfaceRegistry
- Type Parameters:
T
- Object type.- Parameters:
type
- Object type.- Returns:
- Instance of this type.
- Throws:
RegistryException
- If there was a runtime failure while providing an instance.
-
require
Description copied from interface:Registry
Provides an instance of the given type.- Specified by:
require
in interfaceRegistry
- Type Parameters:
T
- Object type.- Parameters:
key
- Object key.- Returns:
- Instance of this type.
- Throws:
RegistryException
- If there was a runtime failure while providing an instance.
-
getUser
@Nullable default <T> T getUser()Description copied from interface:Context
Current user ornull
if none was set. -
setUser
Description copied from interface:Context
Set current user. -
matches
Description copied from interface:Context
Check if the request path matches the given pattern. -
getAttribute
Get an attribute by his key. This is just an utility method aroundContext.getAttributes()
. This method look first in current context and fallback to application attributes.- Specified by:
getAttribute
in interfaceContext
- Type Parameters:
T
- Attribute type.- Parameters:
key
- Attribute key.- Returns:
- Attribute value.
-
setAttribute
Description copied from interface:Context
Set an application attribute.- Specified by:
setAttribute
in interfaceContext
- Parameters:
key
- Attribute key.value
- Attribute value.- Returns:
- This router.
-
flash
Description copied from interface:Context
Flash map. -
flash
Get a flash attribute. -
session
Description copied from interface:Context
Find a session attribute using the given name. If there is no session or attribute under that name a missing value is returned. -
session
Description copied from interface:Context
Find a session or creates a new session. -
sessionOrNull
Description copied from interface:Context
Find an existing session.- Specified by:
sessionOrNull
in interfaceContext
- Returns:
- Existing session or
null
.
-
forward
Description copied from interface:Context
Forward executing to another route. We use the given path to find a matching route.NOTE: the entire handler pipeline is executed (filter, decorator, etc.).
-
cookie
Description copied from interface:Context
Get a cookie matching the given name. -
path
Description copied from interface:Context
Path variable. Value is decoded. -
path
Description copied from interface:Context
Convert theContext.pathMap()
to the given type. -
path
Description copied from interface:Context
ConvertContext.pathMap()
to aValueNode
object. -
query
Description copied from interface:Context
Get a query parameter that matches the given name.{ get("/search", ctx -> { String q = ctx.query("q").value(); ... }); }
-
queryString
Description copied from interface:Context
Query string with the leading?
or empty string. This is the raw query string, without decoding it.- Specified by:
queryString
in interfaceContext
- Returns:
- Query string with the leading
?
or empty string. This is the raw query string, without decoding it.
-
query
Description copied from interface:Context
Convert the queryString to the given type. -
queryMap
Description copied from interface:Context
Query string as simple map.
Produces/search?q=jooby&sort=name
{q: jooby, sort: name}
-
header
Description copied from interface:Context
Get a header that matches the given name. -
headerMap
Description copied from interface:Context
Header as single-value map. -
accept
Description copied from interface:Context
True if the given type matches the `Accept` header. This method returnstrue
if there is no accept header. -
accept
Description copied from interface:Context
Check if the accept type list matches the given produces list and return the most specific media type from produces list. -
getRequestURL
Description copied from interface:Context
Recreates full/entire url of the current request using theHost
header.If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set
Router.setTrustProxy(boolean)
option.- Specified by:
getRequestURL
in interfaceContext
- Returns:
- Full/entire request url using the
Host
header.
-
getRequestURL
Description copied from interface:Context
Recreates full/entire request url using theHost
header with a custom path/suffix.If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set
Router.setTrustProxy(boolean)
option.- Specified by:
getRequestURL
in interfaceContext
- Parameters:
path
- Path or suffix to use, can also include query string parameters.- Returns:
- Full/entire request url using the
Host
header.
-
getRequestType
Description copied from interface:Context
RequestContent-Type
header ornull
when missing.- Specified by:
getRequestType
in interfaceContext
- Returns:
- Request
Content-Type
header ornull
when missing.
-
getRequestType
Description copied from interface:Context
RequestContent-Type
header ornull
when missing.- Specified by:
getRequestType
in interfaceContext
- Parameters:
defaults
- Default content type to use when the header is missing.- Returns:
- Request
Content-Type
header ornull
when missing.
-
getRequestLength
default long getRequestLength()Description copied from interface:Context
RequestContent-Length
header or-1
when missing.- Specified by:
getRequestLength
in interfaceContext
- Returns:
- Request
Content-Length
header or-1
when missing.
-
getHostAndPort
Description copied from interface:Context
Return the host and port that this request was sent to, in general this will be the value of the Host.If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set
Router.setTrustProxy(boolean)
option.- Specified by:
getHostAndPort
in interfaceContext
- Returns:
- Return the host that this request was sent to, in general this will be the value of the Host header.
-
getServerHost
Description copied from interface:Context
Server host.- Specified by:
getServerHost
in interfaceContext
- Returns:
- Server host.
-
getServerPort
default int getServerPort()Description copied from interface:Context
Server port for current request.- Specified by:
getServerPort
in interfaceContext
- Returns:
- Server port for current request.
-
getPort
default int getPort()Description copied from interface:Context
Return the port that this request was sent to. In general this will be the value of the Host header, minus the host name.If no host header is present, this method returns the value of
Context.getServerPort()
. -
getHost
Description copied from interface:Context
Return the host that this request was sent to, in general this will be the value of the Host header, minus the port specifier. Unless, it is set manually using theContext.setHost(String)
method.If you run behind a reverse proxy that has been configured to send the X-Forwarded-* header, please consider to set
Router.setTrustProxy(boolean)
option. -
isSecure
default boolean isSecure()Description copied from interface:Context
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS. -
form
Description copied from interface:Context
Get a form field that matches the given name.File upload retrieval is available using
Context.file(String)
.Only for
multipart/form-data
request. -
form
Description copied from interface:Context
Convert form data to the given type.Only for
application/x-www-form-urlencoded
ormultipart/form-data
request. -
formMap
Description copied from interface:Context
Form data as single-value map.Only for
application/x-www-form-urlencoded
ormultipart/form-data
request. -
files
Description copied from interface:Context
All file uploads. Only formultipart/form-data
request. -
files
Description copied from interface:Context
All file uploads that matches the given field name.Only for
multipart/form-data
request. -
file
Description copied from interface:Context
A file upload that matches the given field name.Only for
multipart/form-data
request. -
body
Description copied from interface:Context
Convert the HTTP body to the given type. -
body
Description copied from interface:Context
Convert the HTTP body to the given type. -
convertOrNull
Description copied from interface:Context
Converts a value (single or hash) into the given type.- Specified by:
convertOrNull
in interfaceContext
- Type Parameters:
T
- Generic type.- Parameters:
value
- Value to convert.type
- Expected type.- Returns:
- Converted value or
null
.
-
decode
Description copied from interface:Context
Convert the HTTP body to the given type. -
decoder
Description copied from interface:Context
Get a decoder for the given content type or get anStatusCode.UNSUPPORTED_MEDIA_TYPE
. -
setResponseHeader
Description copied from interface:Context
Set response header.- Specified by:
setResponseHeader
in interfaceContext
- Parameters:
name
- Header name.value
- Header value.- Returns:
- This context.
-
setResponseHeader
Description copied from interface:Context
Set response header.- Specified by:
setResponseHeader
in interfaceContext
- Parameters:
name
- Header name.value
- Header value.- Returns:
- This context.
-
setResponseHeader
Description copied from interface:Context
Set response header.- Specified by:
setResponseHeader
in interfaceContext
- Parameters:
name
- Header name.value
- Header value.- Returns:
- This context.
-
setResponseType
Description copied from interface:Context
Set response content type header.- Specified by:
setResponseType
in interfaceContext
- Parameters:
contentType
- Content type.- Returns:
- This context.
-
setResponseCode
Description copied from interface:Context
Set response status code.- Specified by:
setResponseCode
in interfaceContext
- Parameters:
statusCode
- Status code.- Returns:
- This context.
-
render
Description copied from interface:Context
Render a value and send the response to client. -
responseStream
Description copied from interface:Context
HTTP response channel as output stream. Usually for chunked responses.- Specified by:
responseStream
in interfaceContext
- Parameters:
contentType
- Media type.- Returns:
- HTTP channel as output stream. Usually for chunked responses.
-
responseStream
@NonNull default Context responseStream(@NonNull MediaType contentType, @NonNull SneakyThrows.Consumer<OutputStream> consumer) throws Exception Description copied from interface:Context
HTTP response channel as output stream. Usually for chunked responses.- Specified by:
responseStream
in interfaceContext
- Parameters:
contentType
- Content type.consumer
- Output stream consumer.- Returns:
- HTTP channel as output stream. Usually for chunked responses.
- Throws:
Exception
- Is something goes wrong.
-
responseStream
@NonNull default Context responseStream(@NonNull SneakyThrows.Consumer<OutputStream> consumer) throws Exception Description copied from interface:Context
HTTP response channel as output stream. Usually for chunked responses.- Specified by:
responseStream
in interfaceContext
- Parameters:
consumer
- Output stream consumer.- Returns:
- HTTP channel as output stream. Usually for chunked responses.
- Throws:
Exception
- Is something goes wrong.
-
responseWriter
Description copied from interface:Context
HTTP response channel as response writer.- Specified by:
responseWriter
in interfaceContext
- Returns:
- HTTP channel as response writer. Usually for chunked response.
-
responseWriter
Description copied from interface:Context
HTTP response channel as response writer.- Specified by:
responseWriter
in interfaceContext
- Parameters:
contentType
- Content type.- Returns:
- HTTP channel as response writer. Usually for chunked response.
-
responseWriter
@NonNull default Context responseWriter(@NonNull SneakyThrows.Consumer<PrintWriter> consumer) throws Exception Description copied from interface:Context
HTTP response channel as response writer.- Specified by:
responseWriter
in interfaceContext
- Parameters:
consumer
- Writer consumer.- Returns:
- This context.
- Throws:
Exception
- Is something goes wrong.
-
responseWriter
@NonNull default Context responseWriter(@NonNull MediaType contentType, @NonNull SneakyThrows.Consumer<PrintWriter> consumer) throws Exception Description copied from interface:Context
HTTP response channel as response writer.- Specified by:
responseWriter
in interfaceContext
- Parameters:
contentType
- Content type.consumer
- Writer consumer.- Returns:
- This context.
- Throws:
Exception
- Is something goes wrong.
-
responseWriter
@NonNull default Context responseWriter(@NonNull MediaType contentType, @Nullable Charset charset, @NonNull SneakyThrows.Consumer<PrintWriter> consumer) throws Exception Description copied from interface:Context
HTTP response channel as response writer.- Specified by:
responseWriter
in interfaceContext
- Parameters:
contentType
- Content type.charset
- Charset.consumer
- Writer consumer.- Returns:
- This context.
- Throws:
Exception
- Is something goes wrong.
-
sendRedirect
Description copied from interface:Context
Send a302
response.- Specified by:
sendRedirect
in interfaceContext
- Parameters:
location
- Location.- Returns:
- This context.
-
sendRedirect
Description copied from interface:Context
Send a redirect response.- Specified by:
sendRedirect
in interfaceContext
- Parameters:
redirect
- Redirect status code.location
- Location.- Returns:
- This context.
-
send
Description copied from interface:Context
Send response data. -
send
Description copied from interface:Context
Send response data. -
send
Description copied from interface:Context
Send a file download response. -
send
Description copied from interface:Context
Send a file response. -
sendError
Description copied from interface:Context
Send an error response. Status code is computed viaRouter.errorCode(Throwable)
. -
sendError
Send an error response. This method set the error code. -
getBufferFactory
- Specified by:
getBufferFactory
in interfaceContext
-