public interface DefaultContext extends Context
Context
but with couple of default methods.ACCEPT, GMT, PORT, RFC1123, RFC1123_PATTERN, SECURE_PORT
Modifier and Type | Method and Description |
---|---|
default MediaType |
accept(List<MediaType> produceTypes)
Check if the accept type list matches the given produces list and return the most
specific media type from produces list.
|
default boolean |
accept(MediaType contentType)
True if the given type matches the `Accept` header.
|
default <T> T |
attribute(String key)
Get an attribute by his key.
|
default Context |
attribute(String key,
Object value)
Set an application attribute.
|
default <T> T |
body(Class<T> type)
Convert the HTTP body to the given type.
|
default <T> T |
body(Type type)
Convert the HTTP body to the given type.
|
default <T> T |
convert(ValueNode value,
Class<T> type)
Converts a value (single or hash) into the given type.
|
default Value |
cookie(String name)
Get a cookie matching the given name.
|
default <T> T |
decode(Type type,
MediaType contentType)
Convert the HTTP body to the given type.
|
default MessageDecoder |
decoder(MediaType contentType)
Get a decoder for the given content type or get an
StatusCode.UNSUPPORTED_MEDIA_TYPE . |
default FileUpload |
file(String name)
A file upload that matches the given field name.
|
default List<FileUpload> |
files()
All file uploads.
|
default List<FileUpload> |
files(String name)
All file uploads that matches the given field name.
|
default FlashMap |
flash()
Flash map.
|
default Value |
flash(String name)
Get a flash attribute.
|
default <T> T |
form(Class<T> type)
Convert formdata to the given type.
|
default ValueNode |
form(String name)
Form field that matches the given name.
|
default Map<String,String> |
formMap()
Formdata as single-value map.
|
default Map<String,List<String>> |
formMultimap()
Formdata as multi-value map.
|
default Context |
forward(String path)
Forward executing to another route.
|
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 |
getHostAndPort()
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 |
getRequestLength()
Request
Content-Length header or -1 when missing. |
default MediaType |
getRequestType()
Request
Content-Type header or null when missing. |
default MediaType |
getRequestType(MediaType defaults)
Request
Content-Type header or null when missing. |
default String |
getRequestURL()
Recreates full/entire request url using the
Host header. |
default String |
getRequestURL(String path)
Recreates full/entire request url using the
Host header. |
default String |
getServerHost()
Server host.
|
default int |
getServerPort()
Server port for current request.
|
default <T> T |
getUser()
Current user or
null if none was set. |
default Value |
header(String name)
Get a header that matches the given name.
|
default Map<String,String> |
headerMap()
Header as single-value map.
|
default Map<String,List<String>> |
headerMultimap()
Header as multi-value map.
|
default boolean |
isSecure()
Returns a boolean indicating whether this request was made using a secure channel, such as
HTTPS.
|
default boolean |
matches(String pattern)
Check if the request path matches the given pattern.
|
default <T> T |
multipart(Class<T> type)
Convert multipart data to the given type.
|
default ValueNode |
multipart(String name)
Get a multipart field that matches the given name.
|
default Map<String,String> |
multipartMap()
Multipart data as single-value map.
|
default Map<String,List<String>> |
multipartMultimap()
Multipart data as multi-value map.
|
default ValueNode |
path()
Convert
Context.pathMap() to a ValueNode object. |
default <T> T |
path(Class<T> type)
Convert the
Context.pathMap() to the given type. |
default Value |
path(String name)
Path variable.
|
default <T> T |
query(Class<T> type)
Convert the queryString to the given type.
|
default ValueNode |
query(String name)
Get a query parameter that matches the given name.
|
default Map<String,String> |
queryMap()
Query string as simple map.
|
default Map<String,List<String>> |
queryMultimap()
Query string as multi-value map.
|
default String |
queryString()
Query string with the leading
? or empty string. |
default Context |
render(Object value)
Render a value and send the response to client.
|
default <T> T |
require(Class<T> type)
Provides an instance of the given type.
|
default <T> T |
require(Class<T> type,
String name)
Provides an instance of the given type where name matches it.
|
default <T> T |
require(ServiceKey<T> key)
Provides an instance of the given type.
|
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 |
responseWriter()
HTTP response channel as response writer.
|
default PrintWriter |
responseWriter(MediaType contentType)
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(MediaType contentType,
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(AttachedFile file)
Send a file attached response.
|
default Context |
send(byte[]... data)
Send response data.
|
default Context |
send(Path file)
Send a file response.
|
default Context |
send(String data)
Send response data.
|
default Context |
sendError(Throwable cause)
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 a
302 response. |
default Session |
session()
Find a session or creates a new session.
|
default Value |
session(String name)
Find a session attribute using the given name.
|
default Session |
sessionOrNull()
Find an existing session.
|
default Context |
setResponseCode(StatusCode statusCode)
Set response status code.
|
default Context |
setResponseHeader(String name,
Date value)
Set response header.
|
default Context |
setResponseHeader(String name,
Instant value)
Set response header.
|
default Context |
setResponseHeader(String name,
Object value)
Set response header.
|
default Context |
setResponseType(MediaType contentType)
Set response content type header.
|
default Context |
setUser(Object user)
Set current user.
|
body, cookieMap, detach, dispatch, dispatch, form, getAttributes, getContextPath, getMethod, getProtocol, getRemoteAddress, getRequestPath, getResetHeadersOnError, getResponseCode, getResponseHeader, getResponseLength, getResponseType, getRoute, getRouter, getScheme, header, isInIoThread, isResponseStarted, multipart, onComplete, pathMap, query, readOnly, removeResponseHeader, removeResponseHeaders, responseSender, responseStream, responseWriter, 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, websocket
@Nonnull default <T> T require(@Nonnull Class<T> type, @Nonnull String name) throws RegistryException
Registry
require
in interface Registry
T
- Object type.type
- Object type.name
- Object name.RegistryException
- If there was a runtime failure while providing an instance.@Nonnull default <T> T require(@Nonnull Class<T> type) throws RegistryException
Registry
require
in interface Registry
T
- Object type.type
- Object type.RegistryException
- If there was a runtime failure while providing an instance.@Nonnull default <T> T require(@Nonnull ServiceKey<T> key) throws RegistryException
Registry
require
in interface Registry
T
- Object type.key
- Object key.RegistryException
- If there was a runtime failure while providing an instance.@Nullable default <T> T getUser()
Context
null
if none was set.@Nonnull default Context setUser(@Nullable Object user)
Context
default boolean matches(String pattern)
Context
@Nonnull default <T> T attribute(@Nonnull String key)
Context.getAttributes()
.
This method look first in current context and fallback to application attributes.@Nonnull default Context attribute(@Nonnull String key, Object value)
Context
@Nonnull default Value session(@Nonnull String name)
Context
@Nonnull default Session session()
Context
@Nullable default Session sessionOrNull()
Context
sessionOrNull
in interface Context
null
.@Nonnull default Context forward(@Nonnull String path)
Context
@Nonnull default Value cookie(@Nonnull String name)
Context
@Nonnull default Value path(@Nonnull String name)
Context
@Nonnull default <T> T path(@Nonnull Class<T> type)
Context
Context.pathMap()
to the given type.@Nonnull default ValueNode path()
Context
Context.pathMap()
to a ValueNode
object.@Nonnull default ValueNode query(@Nonnull String name)
Context
{
get("/search", ctx -> {
String q = ctx.query("q").value();
...
});
}
@Nonnull default String queryString()
Context
?
or empty string. This is the raw query string,
without decoding it.queryString
in interface Context
?
or empty string. This is the raw query
string, without decoding it.@Nonnull default <T> T query(@Nonnull Class<T> type)
Context
@Nonnull default Map<String,String> queryMap()
Context
{q: jooby, sort: name}
@Nonnull default Map<String,List<String>> queryMultimap()
Context
{q: [jooby], sort: [name, id]}
queryMultimap
in interface Context
@Nonnull default Value header(@Nonnull String name)
Context
@Nonnull default Map<String,String> headerMap()
Context
@Nonnull default Map<String,List<String>> headerMultimap()
Context
headerMultimap
in interface Context
default boolean accept(@Nonnull MediaType contentType)
Context
true
if there is no accept header.default MediaType accept(@Nonnull List<MediaType> produceTypes)
Context
@Nonnull default String getRequestURL()
Context
Host
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.getRequestURL
in interface Context
Host
header.@Nonnull default String getRequestURL(@Nonnull String path)
Context
Host
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.getRequestURL
in interface Context
path
- Path to use.Host
header.@Nullable default MediaType getRequestType()
Context
Content-Type
header or null
when missing.getRequestType
in interface Context
Content-Type
header or null
when missing.@Nonnull default MediaType getRequestType(MediaType defaults)
Context
Content-Type
header or null
when missing.getRequestType
in interface Context
defaults
- Default content type to use when the header is missing.Content-Type
header or null
when missing.default long getRequestLength()
Context
Content-Length
header or -1
when missing.getRequestLength
in interface Context
Content-Length
header or -1
when missing.@Nullable default String getHostAndPort()
Context
Router.setTrustProxy(boolean)
option.getHostAndPort
in interface Context
@Nonnull default String getServerHost()
Context
getServerHost
in interface Context
default int getServerPort()
Context
getServerPort
in interface Context
default int getPort()
Context
Context.getServerPort()
.@Nonnull default String getHost()
Context
Context.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.default boolean isSecure()
Context
@Nonnull default Map<String,List<String>> formMultimap()
Context
application/form-url-encoded
request.formMultimap
in interface Context
application/form-url-encoded
request.@Nonnull default Map<String,String> formMap()
Context
application/form-url-encoded
request.@Nonnull default ValueNode form(@Nonnull String name)
Context
application/form-url-encoded
request.@Nonnull default <T> T form(@Nonnull Class<T> type)
Context
application/form-url-encoded
request.@Nonnull default ValueNode multipart(@Nonnull String name)
Context
Context.file(String)
.
Only for multipart/form-data
request.@Nonnull default <T> T multipart(@Nonnull Class<T> type)
Context
multipart/form-data
request.@Nonnull default Map<String,List<String>> multipartMultimap()
Context
multipart/form-data
request.multipartMultimap
in interface Context
@Nonnull default Map<String,String> multipartMap()
Context
multipart/form-data
request.multipartMap
in interface Context
@Nonnull default List<FileUpload> files()
Context
multipart/form-data
request.@Nonnull default List<FileUpload> files(@Nonnull String name)
Context
multipart/form-data
request.@Nonnull default FileUpload file(@Nonnull String name)
Context
multipart/form-data
request.@Nonnull default <T> T body(@Nonnull Class<T> type)
Context
@Nonnull default <T> T body(@Nonnull Type type)
Context
@Nullable default <T> T convert(ValueNode value, Class<T> type)
Context
@Nonnull default <T> T decode(@Nonnull Type type, @Nonnull MediaType contentType)
Context
@Nonnull default MessageDecoder decoder(@Nonnull MediaType contentType)
Context
StatusCode.UNSUPPORTED_MEDIA_TYPE
.@Nonnull default Context setResponseHeader(@Nonnull String name, @Nonnull Date value)
Context
setResponseHeader
in interface Context
name
- Header name.value
- Header value.@Nonnull default Context setResponseHeader(@Nonnull String name, @Nonnull Instant value)
Context
setResponseHeader
in interface Context
name
- Header name.value
- Header value.@Nonnull default Context setResponseHeader(@Nonnull String name, @Nonnull Object value)
Context
setResponseHeader
in interface Context
name
- Header name.value
- Header value.@Nonnull default Context setResponseType(@Nonnull MediaType contentType)
Context
setResponseType
in interface Context
contentType
- Content type.@Nonnull default Context setResponseCode(@Nonnull StatusCode statusCode)
Context
setResponseCode
in interface Context
statusCode
- Status code.@Nonnull default Context render(@Nonnull Object value)
Context
@Nonnull default OutputStream responseStream(@Nonnull MediaType contentType)
Context
responseStream
in interface Context
contentType
- Media type.@Nonnull default Context responseStream(@Nonnull MediaType contentType, @Nonnull SneakyThrows.Consumer<OutputStream> consumer) throws Exception
Context
responseStream
in interface Context
contentType
- Content type.consumer
- Output stream consumer.Exception
- Is something goes wrong.@Nonnull default Context responseStream(@Nonnull SneakyThrows.Consumer<OutputStream> consumer) throws Exception
Context
responseStream
in interface Context
consumer
- Output stream consumer.Exception
- Is something goes wrong.@Nonnull default PrintWriter responseWriter()
Context
responseWriter
in interface Context
@Nonnull default PrintWriter responseWriter(@Nonnull MediaType contentType)
Context
responseWriter
in interface Context
contentType
- Content type.@Nonnull default Context responseWriter(@Nonnull SneakyThrows.Consumer<PrintWriter> consumer) throws Exception
Context
responseWriter
in interface Context
consumer
- Writer consumer.Exception
- Is something goes wrong.@Nonnull default Context responseWriter(@Nonnull MediaType contentType, @Nonnull SneakyThrows.Consumer<PrintWriter> consumer) throws Exception
Context
responseWriter
in interface Context
contentType
- Content type.consumer
- Writer consumer.Exception
- Is something goes wrong.@Nonnull default Context responseWriter(@Nonnull MediaType contentType, @Nullable Charset charset, @Nonnull SneakyThrows.Consumer<PrintWriter> consumer) throws Exception
Context
responseWriter
in interface Context
contentType
- Content type.charset
- Charset.consumer
- Writer consumer.Exception
- Is something goes wrong.@Nonnull default Context sendRedirect(@Nonnull String location)
Context
302
response.sendRedirect
in interface Context
location
- Location.@Nonnull default Context sendRedirect(@Nonnull StatusCode redirect, @Nonnull String location)
Context
sendRedirect
in interface Context
redirect
- Redirect status code.location
- Location.@Nonnull default Context send(@Nonnull byte[]... data)
Context
@Nonnull default Context send(@Nonnull String data)
Context
@Nonnull default Context send(@Nonnull AttachedFile file)
Context
@Nonnull default Context send(@Nonnull Path file)
Context
@Nonnull default Context sendError(@Nonnull Throwable cause)
Context
Router.errorCode(Throwable)
.Copyright © 2020. All rights reserved.