ACCEPT, GMT, RFC1123, RFC1123_PATTERN
Constructor and Description |
---|
ForwardingContext(Context context)
Creates a new forwarding context.
|
Modifier and Type | Method and Description |
---|---|
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.
|
boolean |
accept(MediaType contentType)
True if the given type matches the `Accept` header.
|
<T> T |
attribute(String key)
Get an attribute by his key.
|
Context |
attribute(String key,
Object value)
Set an application attribute.
|
Body |
body()
HTTP body which provides access to body content.
|
<T> T |
body(Class<T> type)
Convert the HTTP body to the given type.
|
<T> T |
body(Type type)
Convert the HTTP body to the given type.
|
<T> T |
convert(ValueNode value,
Class<T> type)
Converts a value (single or hash) into the given type.
|
Value |
cookie(String name)
Get a cookie matching the given name.
|
Map<String,String> |
cookieMap()
Request cookies.
|
<T> T |
decode(Type type,
MediaType contentType)
Convert the HTTP body to the given type.
|
MessageDecoder |
decoder(MediaType contentType)
Get a decoder for the given content type or get an
StatusCode.UNSUPPORTED_MEDIA_TYPE . |
Context |
detach(Route.Handler next)
Tells context that response will be generated form a different thread.
|
Context |
dispatch(Executor executor,
Runnable action)
Dispatch context to the given executor.
|
Context |
dispatch(Runnable action)
Dispatch context to a worker threads.
|
FileUpload |
file(String name)
A file upload that matches the given field name.
|
List<FileUpload> |
files()
All file uploads.
|
List<FileUpload> |
files(String name)
All file uploads that matches the given field name.
|
FlashMap |
flash()
Flash map.
|
Value |
flash(String name)
Get a flash attribute.
|
Formdata |
form()
Formdata as
ValueNode . |
<T> T |
form(Class<T> type)
Convert formdata to the given type.
|
ValueNode |
form(String name)
Form field that matches the given name.
|
Map<String,String> |
formMap()
Formdata as single-value map.
|
Map<String,List<String>> |
formMultimap()
Formdata as multi-value map.
|
Map<String,Object> |
getAttributes()
Context attributes (a.k.a request attributes).
|
String |
getHost()
The fully qualified name of the resource being requested, as obtained from the Host HTTP
header.
|
String |
getMethod()
HTTP method in upper-case form.
|
String |
getProtocol()
The name of the protocol the request.
|
String |
getRemoteAddress()
The IP address of the client or last proxy that sent the request.
|
long |
getRequestLength()
Request
Content-Length header or -1 when missing. |
MediaType |
getRequestType()
Request
Content-Type header or null when missing. |
MediaType |
getRequestType(MediaType defaults)
Request
Content-Type header or null when missing. |
boolean |
getResetHeadersOnError()
True if response headers are cleared on application error.
|
StatusCode |
getResponseCode()
Get response status code.
|
long |
getResponseLength()
Get response content length or
-1 when none was set. |
MediaType |
getResponseType()
Get response content type.
|
Route |
getRoute()
Matching route.
|
Router |
getRouter()
Get the HTTP router (usually this represent an instance of
Jooby . |
String |
getScheme()
HTTP scheme in lower case.
|
ValueNode |
header()
Request headers as
ValueNode . |
Value |
header(String name)
Get a header that matches the given name.
|
Map<String,String> |
headerMap()
Header as single-value map.
|
Map<String,List<String>> |
headerMultimap()
Header as multi-value map.
|
boolean |
isInIoThread()
True when request runs in IO threads.
|
boolean |
isResponseStarted()
True if response already started.
|
Multipart |
multipart()
Get multipart data.
|
<T> T |
multipart(Class<T> type)
Convert multipart data to the given type.
|
ValueNode |
multipart(String name)
Get a multipart field that matches the given name.
|
Map<String,String> |
multipartMap()
Multipart data as single-value map.
|
Map<String,List<String>> |
multipartMultimap()
Multipart data as multi-value map.
|
ValueNode |
path()
Convert
Context.pathMap() to a ValueNode object. |
<T> T |
path(Class<T> type)
Convert the
Context.pathMap() to the given type. |
Value |
path(String name)
Path variable.
|
Map<String,String> |
pathMap()
Path map represent all the path keys with their values.
|
String |
pathString()
Request path without decoding (a.k.a raw Path) without query string.
|
QueryString |
query()
Query string as
ValueNode object. |
<T> T |
query(Class<T> type)
Convert the queryString to the given type.
|
ValueNode |
query(String name)
Get a query parameter that matches the given name.
|
Map<String,String> |
queryMap()
Query string as simple map.
|
Map<String,List<String>> |
queryMultimap()
Query string as multi-value map.
|
String |
queryString()
Query string with the leading
? or empty string. |
Context |
removeResponseHeader(String name)
Remove a response header.
|
Context |
removeResponseHeaders()
Clear/reset all the headers, including cookies.
|
Context |
render(Object value)
Render a value and send the response to client.
|
<T> T |
require(Class<T> type)
Provides an instance of the given type.
|
<T> T |
require(Class<T> type,
String name)
Provides an instance of the given type where name matches it.
|
<T> T |
require(ServiceKey<T> key)
Provides an instance of the given type.
|
Sender |
responseSender()
HTTP response channel as chunker.
|
OutputStream |
responseStream()
HTTP response channel as output stream.
|
OutputStream |
responseStream(MediaType contentType)
HTTP response channel as output stream.
|
Context |
responseStream(MediaType contentType,
SneakyThrows.Consumer<OutputStream> consumer)
HTTP response channel as output stream.
|
Context |
responseStream(SneakyThrows.Consumer<OutputStream> consumer)
HTTP response channel as output stream.
|
PrintWriter |
responseWriter()
HTTP response channel as response writer.
|
PrintWriter |
responseWriter(MediaType contentType)
HTTP response channel as response writer.
|
PrintWriter |
responseWriter(MediaType contentType,
Charset charset)
HTTP response channel as response writer.
|
Context |
responseWriter(MediaType contentType,
Charset charset,
SneakyThrows.Consumer<PrintWriter> consumer)
HTTP response channel as response writer.
|
Context |
responseWriter(MediaType contentType,
SneakyThrows.Consumer<PrintWriter> consumer)
HTTP response channel as response writer.
|
Context |
responseWriter(SneakyThrows.Consumer<PrintWriter> consumer)
HTTP response channel as response writer.
|
Context |
send(AttachedFile file)
Send a file attached response.
|
Context |
send(byte[]... data)
Send response data.
|
Context |
send(byte[] data)
Send response data.
|
Context |
send(ByteBuffer data)
Send response data.
|
Context |
send(ByteBuffer[] data)
Send response data.
|
Context |
send(FileChannel file)
Send a file response.
|
Context |
send(InputStream input)
Send response data.
|
Context |
send(Path file)
Send a file response.
|
Context |
send(ReadableByteChannel channel)
Send response data.
|
Context |
send(StatusCode statusCode)
Send an empty response with the given status code.
|
Context |
send(String data)
Send response data.
|
Context |
send(String data,
Charset charset)
Send response data.
|
Context |
sendError(Throwable cause)
Send an error response.
|
Context |
sendError(Throwable cause,
StatusCode statusCode)
Send an error response.
|
Context |
sendRedirect(StatusCode redirect,
String location)
Send a redirect response.
|
Context |
sendRedirect(String location)
Send a
302 response. |
Session |
session()
Find a session or creates a new session.
|
Value |
session(String name)
Find a session attribute using the given name.
|
Session |
sessionOrNull()
Find an existing session.
|
Context |
setDefaultResponseType(MediaType contentType)
Set the default response content type header.
|
Context |
setPathMap(Map<String,String> pathMap)
Set path map.
|
Context |
setResetHeadersOnError(boolean value)
Set whenever reset/clear headers on application error.
|
Context |
setResponseCode(int statusCode)
Set response status code.
|
Context |
setResponseCode(StatusCode statusCode)
Set response status code.
|
Context |
setResponseCookie(Cookie cookie)
Set/add a cookie to response.
|
Context |
setResponseHeader(String name,
Date value)
Set response header.
|
Context |
setResponseHeader(String name,
Instant value)
Set response header.
|
Context |
setResponseHeader(String name,
Object value)
Set response header.
|
Context |
setResponseHeader(String name,
String value)
Set response header.
|
Context |
setResponseLength(long length)
Set response content length header.
|
Context |
setResponseType(MediaType contentType)
Set response content type header.
|
Context |
setResponseType(MediaType contentType,
Charset charset)
Set response content type header.
|
Context |
setResponseType(String contentType)
Set response content type header.
|
Context |
setRoute(Route route)
Set matching route.
|
String |
toString() |
Context |
upgrade(WebSocket.Initializer handler)
Perform a websocket handsake and upgrade a HTTP GET into a websocket protocol.
|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
getContextPath, readOnly, websocket
@Nonnull public Map<String,Object> getAttributes()
Context
getAttributes
in interface Context
@Nonnull public <T> T attribute(@Nonnull String key)
Context
Context.getAttributes()
.
This method look first in current context and fallback to application attributes.@Nonnull public Context attribute(@Nonnull String key, Object value)
Context
@Nonnull public Router getRouter()
Context
Jooby
.@Nonnull public Value flash(@Nonnull String name)
Context
@Nonnull public Value session(@Nonnull String name)
Context
@Nonnull public Session session()
Context
@Nullable public Session sessionOrNull()
Context
sessionOrNull
in interface Context
null
.@Nonnull public Value cookie(@Nonnull String name)
Context
@Nonnull public Map<String,String> cookieMap()
Context
@Nonnull public String getMethod()
Context
@Nonnull public Route getRoute()
Context
@Nonnull public Context setRoute(@Nonnull Route route)
Context
@Nonnull public String pathString()
Context
pathString
in interface Context
@Nonnull public Value path(@Nonnull String name)
Context
@Nonnull public <T> T path(@Nonnull Class<T> type)
Context
Context.pathMap()
to the given type.@Nonnull public ValueNode path()
Context
Context.pathMap()
to a ValueNode
object.@Nonnull public Map<String,String> pathMap()
Context
{
get("/:id", ctx -> ctx.pathMap());
}
A call to:
GET /678Produces a path map like:
id: 678
@Nonnull public Context setPathMap(@Nonnull Map<String,String> pathMap)
Context
setPathMap
in interface Context
pathMap
- Path map.@Nonnull public QueryString query()
Context
ValueNode
object.@Nonnull public ValueNode query(@Nonnull String name)
Context
{
get("/search", ctx -> {
String q = ctx.query("q").value();
...
});
}
@Nonnull public 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 public <T> T query(@Nonnull Class<T> type)
Context
@Nonnull public Map<String,String> queryMap()
Context
{q: jooby, sort: name}
@Nonnull public Map<String,List<String>> queryMultimap()
Context
{q: [jooby], sort: [name, id]}
queryMultimap
in interface Context
@Nonnull public ValueNode header()
Context
ValueNode
.@Nonnull public Value header(@Nonnull String name)
Context
@Nonnull public Map<String,String> headerMap()
Context
@Nonnull public Map<String,List<String>> headerMultimap()
Context
headerMultimap
in interface Context
public boolean accept(@Nonnull MediaType contentType)
Context
true
if there is no accept header.@Nullable public MediaType accept(@Nonnull List<MediaType> produceTypes)
Context
@Nullable public MediaType getRequestType()
Context
Content-Type
header or null
when missing.getRequestType
in interface Context
Content-Type
header or null
when missing.@Nonnull public 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.public long getRequestLength()
Context
Content-Length
header or -1
when missing.getRequestLength
in interface Context
Content-Length
header or -1
when missing.@Nonnull public String getRemoteAddress()
Context
getRemoteAddress
in interface Context
@Nonnull public String getHost()
Context
@Nonnull public String getProtocol()
Context
getProtocol
in interface Context
@Nonnull public String getScheme()
Context
@Nonnull public Formdata form()
Context
ValueNode
. This method is for application/form-url-encoded
request.@Nonnull public Map<String,List<String>> formMultimap()
Context
application/form-url-encoded
request.formMultimap
in interface Context
application/form-url-encoded
request.@Nonnull public Map<String,String> formMap()
Context
application/form-url-encoded
request.@Nonnull public ValueNode form(@Nonnull String name)
Context
application/form-url-encoded
request.@Nonnull public <T> T form(@Nonnull Class<T> type)
Context
application/form-url-encoded
request.@Nonnull public Multipart multipart()
Context
multipart/form-data
request..@Nonnull public ValueNode multipart(@Nonnull String name)
Context
Context.file(String)
.
Only for multipart/form-data
request.@Nonnull public <T> T multipart(@Nonnull Class<T> type)
Context
multipart/form-data
request.@Nonnull public Map<String,List<String>> multipartMultimap()
Context
multipart/form-data
request.multipartMultimap
in interface Context
@Nonnull public Map<String,String> multipartMap()
Context
multipart/form-data
request.multipartMap
in interface Context
@Nonnull public List<FileUpload> files()
Context
multipart/form-data
request.@Nonnull public List<FileUpload> files(@Nonnull String name)
Context
multipart/form-data
request.@Nonnull public FileUpload file(@Nonnull String name)
Context
multipart/form-data
request.@Nonnull public Body body()
Context
@Nonnull public <T> T body(@Nonnull Class<T> type)
Context
@Nonnull public <T> T body(@Nonnull Type type)
Context
@Nullable public <T> T convert(ValueNode value, Class<T> type)
Context
@Nonnull public <T> T decode(@Nonnull Type type, @Nonnull MediaType contentType)
Context
@Nonnull public MessageDecoder decoder(@Nonnull MediaType contentType)
Context
StatusCode.UNSUPPORTED_MEDIA_TYPE
.public boolean isInIoThread()
Context
isInIoThread
in interface Context
@Nonnull public Context dispatch(@Nonnull Runnable action)
Context
Jooby.setWorker(Executor)
.
Example:
get("/", ctx -> {
return ctx.dispatch(() -> {
// run blocking code
}):
});
@Nonnull public Context dispatch(@Nonnull Executor executor, @Nonnull Runnable action)
Context
Executor executor = ...;
get("/", ctx -> {
return ctx.dispatch(executor, () -> {
// run blocking code
}):
});
@Nonnull public Context detach(@Nonnull Route.Handler next) throws Exception
Context
Context.dispatch(Runnable)
except there is no thread dispatching here.
This operation integrates easily with third-party libraries like rxJava or others.@Nonnull public Context upgrade(@Nonnull WebSocket.Initializer handler)
Context
@Nonnull public Context setResponseHeader(@Nonnull String name, @Nonnull Date value)
Context
setResponseHeader
in interface Context
name
- Header name.value
- Header value.@Nonnull public Context setResponseHeader(@Nonnull String name, @Nonnull Instant value)
Context
setResponseHeader
in interface Context
name
- Header name.value
- Header value.@Nonnull public Context setResponseHeader(@Nonnull String name, @Nonnull Object value)
Context
setResponseHeader
in interface Context
name
- Header name.value
- Header value.@Nonnull public Context setResponseHeader(@Nonnull String name, @Nonnull String value)
Context
setResponseHeader
in interface Context
name
- Header name.value
- Header value.@Nonnull public Context removeResponseHeader(@Nonnull String name)
Context
removeResponseHeader
in interface Context
name
- Header's name.@Nonnull public Context removeResponseHeaders()
Context
removeResponseHeaders
in interface Context
public long getResponseLength()
Context
-1
when none was set.getResponseLength
in interface Context
-1
when none was set.@Nonnull public Context setResponseLength(long length)
Context
setResponseLength
in interface Context
length
- Response length.@Nonnull public Context setResponseCookie(@Nonnull Cookie cookie)
Context
setResponseCookie
in interface Context
cookie
- Cookie to add.@Nonnull public Context setResponseType(@Nonnull String contentType)
Context
setResponseType
in interface Context
contentType
- Content type.@Nonnull public Context setResponseType(@Nonnull MediaType contentType)
Context
setResponseType
in interface Context
contentType
- Content type.@Nonnull public Context setResponseType(@Nonnull MediaType contentType, @Nullable Charset charset)
Context
setResponseType
in interface Context
contentType
- Content type.charset
- Charset.@Nonnull public Context setDefaultResponseType(@Nonnull MediaType contentType)
Context
setDefaultResponseType
in interface Context
contentType
- Content type.@Nonnull public MediaType getResponseType()
Context
getResponseType
in interface Context
@Nonnull public Context setResponseCode(@Nonnull StatusCode statusCode)
Context
setResponseCode
in interface Context
statusCode
- Status code.@Nonnull public Context setResponseCode(int statusCode)
Context
setResponseCode
in interface Context
statusCode
- Status code.@Nonnull public StatusCode getResponseCode()
Context
getResponseCode
in interface Context
@Nonnull public Context render(@Nonnull Object value)
Context
@Nonnull public OutputStream responseStream()
Context
responseStream
in interface Context
@Nonnull public OutputStream responseStream(@Nonnull MediaType contentType)
Context
responseStream
in interface Context
contentType
- Media type.@Nonnull public 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 public Context responseStream(@Nonnull SneakyThrows.Consumer<OutputStream> consumer) throws Exception
Context
responseStream
in interface Context
consumer
- Output stream consumer.Exception
- Is something goes wrong.@Nonnull public Sender responseSender()
Context
responseSender
in interface Context
@Nonnull public PrintWriter responseWriter()
Context
responseWriter
in interface Context
@Nonnull public PrintWriter responseWriter(@Nonnull MediaType contentType)
Context
responseWriter
in interface Context
contentType
- Content type.@Nonnull public PrintWriter responseWriter(@Nonnull MediaType contentType, @Nullable Charset charset)
Context
responseWriter
in interface Context
contentType
- Content type.charset
- Charset.@Nonnull public Context responseWriter(@Nonnull SneakyThrows.Consumer<PrintWriter> consumer) throws Exception
Context
responseWriter
in interface Context
consumer
- Writer consumer.Exception
- Is something goes wrong.@Nonnull public 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 public 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 public Context sendRedirect(@Nonnull String location)
Context
302
response.sendRedirect
in interface Context
location
- Location.@Nonnull public Context sendRedirect(@Nonnull StatusCode redirect, @Nonnull String location)
Context
sendRedirect
in interface Context
redirect
- Redirect status code.location
- Location.@Nonnull public Context send(@Nonnull String data)
Context
@Nonnull public Context send(@Nonnull String data, @Nonnull Charset charset)
Context
@Nonnull public Context send(@Nonnull byte[] data)
Context
@Nonnull public Context send(@Nonnull ByteBuffer data)
Context
@Nonnull public Context send(@Nonnull byte[]... data)
Context
@Nonnull public Context send(@Nonnull ByteBuffer[] data)
Context
@Nonnull public Context send(@Nonnull ReadableByteChannel channel)
Context
@Nonnull public Context send(@Nonnull InputStream input)
Context
@Nonnull public Context send(@Nonnull AttachedFile file)
Context
@Nonnull public Context send(@Nonnull Path file)
Context
@Nonnull public Context send(@Nonnull FileChannel file)
Context
@Nonnull public Context send(@Nonnull StatusCode statusCode)
Context
@Nonnull public Context sendError(@Nonnull Throwable cause)
Context
Router.errorCode(Throwable)
.@Nonnull public Context sendError(@Nonnull Throwable cause, @Nonnull StatusCode statusCode)
Context
public boolean isResponseStarted()
Context
isResponseStarted
in interface Context
public boolean getResetHeadersOnError()
Context
RouterOptions.getResetHeadersOnError()
.getResetHeadersOnError
in interface Context
RouterOptions.getResetHeadersOnError()
.public Context setResetHeadersOnError(boolean value)
Context
setResetHeadersOnError
in interface Context
value
- True for reset/clear headers.@Nonnull public <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 public <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 public <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.Copyright © 2019. All rights reserved.