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 booleanTrue if the given type matches the `Accept` header.default MediaTypeCheck if the accept type list matches the given produces list and return the most specific media type from produces list.default <T> TConvert the HTTP body to the given type.default <T> TConvert the HTTP body to the given type.default <T> TconvertOrNull(ValueNode value, Class<T> type) Converts a value (single or hash) into the given type.default ValueGet a cookie matching the given name.default <T> TConvert the HTTP body to the given type.default MessageDecoderGet a decoder for the given content type or get anStatusCode.UNSUPPORTED_MEDIA_TYPE.default FileUploadA 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 FlashMapflash()Flash map.default ValueGet a flash attribute.default <T> TConvert form data to the given type.default ValueNodeGet a form field that matches the given name.formMap()Form data as single-value map.default ObjectForward executing to another route.default <T> TgetAttribute(String key) Get an attribute by his key.default DataBufferFactorydefault StringgetHost()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 StringReturn the host and port that this request was sent to, in general this will be the value of the Host.default intgetPort()Return the port that this request was sent to.default longRequestContent-Lengthheader or-1when missing.default MediaTypeRequestContent-Typeheader ornullwhen missing.default MediaTypegetRequestType(MediaType defaults) RequestContent-Typeheader ornullwhen missing.default StringRecreates full/entire url of the current request using theHostheader.default StringgetRequestURL(String path) Recreates full/entire request url using theHostheader with a custom path/suffix.default StringServer host.default intServer port for current request.default <T> TgetUser()Current user ornullif none was set.default ValueGet a header that matches the given name.Header as single-value map.default booleanisSecure()Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.default booleanCheck if the request path matches the given pattern.default ValueNodepath()ConvertContext.pathMap()to aValueNodeobject.default <T> TConvert theContext.pathMap()to the given type.default ValuePath variable.default <T> TConvert the queryString to the given type.default ValueNodeGet a query parameter that matches the given name.queryMap()Query string as simple map.default StringQuery string with the leading?default ContextRender a value and send the response to client.default <T> Trequire(ServiceKey<T> key) Provides an instance of the given type.default <T> TProvides an instance of the given type.default <T> TProvides an instance of the given type where name matches it.default OutputStreamresponseStream(MediaType contentType) HTTP response channel as output stream.default ContextresponseStream(MediaType contentType, SneakyThrows.Consumer<OutputStream> consumer) HTTP response channel as output stream.default ContextresponseStream(SneakyThrows.Consumer<OutputStream> consumer) HTTP response channel as output stream.default PrintWriterHTTP response channel as response writer.default PrintWriterresponseWriter(MediaType contentType) HTTP response channel as response writer.default ContextresponseWriter(MediaType contentType, SneakyThrows.Consumer<PrintWriter> consumer) HTTP response channel as response writer.default ContextresponseWriter(MediaType contentType, Charset charset, SneakyThrows.Consumer<PrintWriter> consumer) HTTP response channel as response writer.default ContextresponseWriter(SneakyThrows.Consumer<PrintWriter> consumer) HTTP response channel as response writer.default Contextsend(byte[]... data) Send response data.default Contextsend(FileDownload file) Send a file download response.default ContextSend response data.default ContextSend a file response.default ContextSend an error response.default ContextsendError(Throwable cause, StatusCode code) Send an error response.default ContextsendRedirect(StatusCode redirect, String location) Send a redirect response.default ContextsendRedirect(String location) Send a302response.default Sessionsession()Find a session or creates a new session.default ValueFind a session attribute using the given name.default SessionFind an existing session.default ContextsetAttribute(String key, Object value) Set an application attribute.default ContextsetResponseCode(StatusCode statusCode) Set response status code.default ContextsetResponseHeader(String name, Object value) Set response header.default ContextsetResponseHeader(String name, Instant value) Set response header.default ContextsetResponseHeader(String name, Date value) Set response header.default ContextsetResponseType(MediaType contentType) Set response content type header.default ContextSet 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:RegistryProvides an instance of the given type where name matches it.- Specified by:
requirein 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:RegistryProvides an instance of the given type.- Specified by:
requirein 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:RegistryProvides an instance of the given type.- Specified by:
requirein 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:ContextCurrent user ornullif none was set. -
setUser
Description copied from interface:ContextSet current user. -
matches
Description copied from interface:ContextCheck 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:
getAttributein interfaceContext- Type Parameters:
T- Attribute type.- Parameters:
key- Attribute key.- Returns:
- Attribute value.
-
setAttribute
Description copied from interface:ContextSet an application attribute.- Specified by:
setAttributein interfaceContext- Parameters:
key- Attribute key.value- Attribute value.- Returns:
- This router.
-
flash
Description copied from interface:ContextFlash map. -
flash
Get a flash attribute. -
session
Description copied from interface:ContextFind 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:ContextFind a session or creates a new session. -
sessionOrNull
Description copied from interface:ContextFind an existing session.- Specified by:
sessionOrNullin interfaceContext- Returns:
- Existing session or
null.
-
forward
Description copied from interface:ContextForward 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:ContextGet a cookie matching the given name. -
path
Description copied from interface:ContextPath variable. Value is decoded. -
path
Description copied from interface:ContextConvert theContext.pathMap()to the given type. -
path
Description copied from interface:ContextConvertContext.pathMap()to aValueNodeobject. -
query
Description copied from interface:ContextGet a query parameter that matches the given name.{ get("/search", ctx -> { String q = ctx.query("q").value(); ... }); } -
queryString
Description copied from interface:ContextQuery string with the leading?or empty string. This is the raw query string, without decoding it.- Specified by:
queryStringin interfaceContext- Returns:
- Query string with the leading
?or empty string. This is the raw query string, without decoding it.
-
query
Description copied from interface:ContextConvert the queryString to the given type. -
queryMap
Description copied from interface:ContextQuery string as simple map.
Produces/search?q=jooby&sort=name{q: jooby, sort: name} -
header
Description copied from interface:ContextGet a header that matches the given name. -
headerMap
Description copied from interface:ContextHeader as single-value map. -
accept
Description copied from interface:ContextTrue if the given type matches the `Accept` header. This method returnstrueif there is no accept header. -
accept
Description copied from interface:ContextCheck 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:ContextRecreates full/entire url of the current request using theHostheader.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:
getRequestURLin interfaceContext- Returns:
- Full/entire request url using the
Hostheader.
-
getRequestURL
Description copied from interface:ContextRecreates full/entire request url using theHostheader 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:
getRequestURLin interfaceContext- Parameters:
path- Path or suffix to use, can also include query string parameters.- Returns:
- Full/entire request url using the
Hostheader.
-
getRequestType
Description copied from interface:ContextRequestContent-Typeheader ornullwhen missing.- Specified by:
getRequestTypein interfaceContext- Returns:
- Request
Content-Typeheader ornullwhen missing.
-
getRequestType
Description copied from interface:ContextRequestContent-Typeheader ornullwhen missing.- Specified by:
getRequestTypein interfaceContext- Parameters:
defaults- Default content type to use when the header is missing.- Returns:
- Request
Content-Typeheader ornullwhen missing.
-
getRequestLength
default long getRequestLength()Description copied from interface:ContextRequestContent-Lengthheader or-1when missing.- Specified by:
getRequestLengthin interfaceContext- Returns:
- Request
Content-Lengthheader or-1when missing.
-
getHostAndPort
Description copied from interface:ContextReturn 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:
getHostAndPortin 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:ContextServer host.- Specified by:
getServerHostin interfaceContext- Returns:
- Server host.
-
getServerPort
default int getServerPort()Description copied from interface:ContextServer port for current request.- Specified by:
getServerPortin interfaceContext- Returns:
- Server port for current request.
-
getPort
default int getPort()Description copied from interface:ContextReturn 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:ContextReturn 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:ContextReturns a boolean indicating whether this request was made using a secure channel, such as HTTPS. -
form
Description copied from interface:ContextGet a form field that matches the given name.File upload retrieval is available using
Context.file(String).Only for
multipart/form-datarequest. -
form
Description copied from interface:ContextConvert form data to the given type.Only for
application/x-www-form-urlencodedormultipart/form-datarequest. -
formMap
Description copied from interface:ContextForm data as single-value map.Only for
application/x-www-form-urlencodedormultipart/form-datarequest. -
files
Description copied from interface:ContextAll file uploads. Only formultipart/form-datarequest. -
files
Description copied from interface:ContextAll file uploads that matches the given field name.Only for
multipart/form-datarequest. -
file
Description copied from interface:ContextA file upload that matches the given field name.Only for
multipart/form-datarequest. -
body
Description copied from interface:ContextConvert the HTTP body to the given type. -
body
Description copied from interface:ContextConvert the HTTP body to the given type. -
convertOrNull
Description copied from interface:ContextConverts a value (single or hash) into the given type.- Specified by:
convertOrNullin interfaceContext- Type Parameters:
T- Generic type.- Parameters:
value- Value to convert.type- Expected type.- Returns:
- Converted value or
null.
-
decode
Description copied from interface:ContextConvert the HTTP body to the given type. -
decoder
Description copied from interface:ContextGet a decoder for the given content type or get anStatusCode.UNSUPPORTED_MEDIA_TYPE. -
setResponseHeader
Description copied from interface:ContextSet response header.- Specified by:
setResponseHeaderin interfaceContext- Parameters:
name- Header name.value- Header value.- Returns:
- This context.
-
setResponseHeader
Description copied from interface:ContextSet response header.- Specified by:
setResponseHeaderin interfaceContext- Parameters:
name- Header name.value- Header value.- Returns:
- This context.
-
setResponseHeader
Description copied from interface:ContextSet response header.- Specified by:
setResponseHeaderin interfaceContext- Parameters:
name- Header name.value- Header value.- Returns:
- This context.
-
setResponseType
Description copied from interface:ContextSet response content type header.- Specified by:
setResponseTypein interfaceContext- Parameters:
contentType- Content type.- Returns:
- This context.
-
setResponseCode
Description copied from interface:ContextSet response status code.- Specified by:
setResponseCodein interfaceContext- Parameters:
statusCode- Status code.- Returns:
- This context.
-
render
Description copied from interface:ContextRender a value and send the response to client. -
responseStream
Description copied from interface:ContextHTTP response channel as output stream. Usually for chunked responses.- Specified by:
responseStreamin 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:ContextHTTP response channel as output stream. Usually for chunked responses.- Specified by:
responseStreamin 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:ContextHTTP response channel as output stream. Usually for chunked responses.- Specified by:
responseStreamin 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:ContextHTTP response channel as response writer.- Specified by:
responseWriterin interfaceContext- Returns:
- HTTP channel as response writer. Usually for chunked response.
-
responseWriter
Description copied from interface:ContextHTTP response channel as response writer.- Specified by:
responseWriterin 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:ContextHTTP response channel as response writer.- Specified by:
responseWriterin 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:ContextHTTP response channel as response writer.- Specified by:
responseWriterin 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:ContextHTTP response channel as response writer.- Specified by:
responseWriterin interfaceContext- Parameters:
contentType- Content type.charset- Charset.consumer- Writer consumer.- Returns:
- This context.
- Throws:
Exception- Is something goes wrong.
-
sendRedirect
Description copied from interface:ContextSend a302response.- Specified by:
sendRedirectin interfaceContext- Parameters:
location- Location.- Returns:
- This context.
-
sendRedirect
Description copied from interface:ContextSend a redirect response.- Specified by:
sendRedirectin interfaceContext- Parameters:
redirect- Redirect status code.location- Location.- Returns:
- This context.
-
send
Description copied from interface:ContextSend response data. -
send
Description copied from interface:ContextSend response data. -
send
Description copied from interface:ContextSend a file download response. -
send
Description copied from interface:ContextSend a file response. -
sendError
Description copied from interface:ContextSend an error response. Status code is computed viaRouter.errorCode(Throwable). -
sendError
Send an error response. This method set the error code. -
getBufferFactory
- Specified by:
getBufferFactoryin interfaceContext
-