public interface Router
Modifier and Type | Interface and Description |
---|---|
static interface |
Router.Match
Find route result.
|
Modifier and Type | Field and Description |
---|---|
static String |
CONNECT
HTTP CONNECT.
|
static String |
DELETE
HTTP DELETE.
|
static String |
GET
HTTP GET.
|
static String |
HEAD
HTTP HEAD.
|
static List<String> |
METHODS
HTTP Methods.
|
static String |
OPTIONS
HTTP OPTIONS.
|
static String |
PATCH
HTTP PATCH.
|
static String |
POST
HTTP POST.
|
static String |
PUT
HTTP PUT.
|
static String |
TRACE
HTTP TRACE.
|
Modifier and Type | Method and Description |
---|---|
Router |
after(Route.After after)
Add an after route decorator to the route pipeline.
|
default Route |
assets(String pattern,
AssetHandler handler)
Add a static resource handler.
|
default Route |
assets(String pattern,
AssetSource... source)
Add a static resource handler.
|
default Route |
assets(String pattern,
Path source)
Add a static resource handler.
|
default Route |
assets(String pattern,
String source)
Add a static resource handler.
|
default <T> T |
attribute(String key)
Get an attribute by his key.
|
default Router |
attribute(String key,
Object value)
Set an application attribute.
|
Router |
before(Route.Before before)
Add a before route decorator to the route pipeline.
|
default Route |
connect(String pattern,
Route.Handler handler)
Add a HTTP CONNECT handler.
|
Router |
decorator(Route.Decorator decorator)
Add a route decorator to the route pipeline.
|
default Route |
delete(String pattern,
Route.Handler handler)
Add a HTTP DELETE handler.
|
Router |
dispatch(Executor executor,
Runnable body)
Dispatch route pipeline to the given executor.
|
Router |
dispatch(Runnable body)
Dispatch route pipeline to the
getWorker() worker thread pool. |
default Router |
error(Class<? extends Throwable> type,
ErrorHandler handler)
Add a custom error handler that matches the given exception type.
|
Router |
error(ErrorHandler handler)
Add a custom error handler.
|
default Router |
error(Predicate<StatusCode> predicate,
ErrorHandler handler)
Add a custom error handler that matches the given predicate.
|
default Router |
error(StatusCode statusCode,
ErrorHandler handler)
Add a custom error handler that matches the given status code.
|
Router |
errorCode(Class<? extends Throwable> type,
StatusCode statusCode)
Map an exception type to a status code.
|
StatusCode |
errorCode(Throwable cause)
Computes the status code for the given exception.
|
default Route |
get(String pattern,
Route.Handler handler)
Add a HTTP GET handler.
|
Map<String,Object> |
getAttributes()
Mutable map of application attributes.
|
String |
getContextPath()
Get application context path (a.k.a as base path).
|
ErrorHandler |
getErrorHandler()
Get the error handler.
|
org.slf4j.Logger |
getLog()
Application logger.
|
Map<ResourceKey,Object> |
getResources()
Application resource registry.
|
RouterOptions |
getRouterOptions()
Router options.
|
List<Route> |
getRoutes()
Returns all routes.
|
Path |
getTmpdir()
Application temporary directory.
|
Executor |
getWorker()
Returns the worker thread pool.
|
default Route |
head(String pattern,
Route.Handler handler)
Add a HTTP HEAD handler.
|
Router.Match |
match(Context ctx)
Find a matching route using the given context.
|
Router |
mvc(Class router)
Import all route method from the given controller class.
|
<T> Router |
mvc(Class<T> router,
javax.inject.Provider<T> provider)
Import all route method from the given controller class.
|
Router |
mvc(Object router)
Import all route methods from given controller instance.
|
static String |
normalizePath(String path,
boolean caseSensitive,
boolean ignoreTrailingSlash)
Normalize a path by removing consecutives
/ (slashes), make it lower case and
removing trailing slash. |
default Route |
options(String pattern,
Route.Handler handler)
Add a HTTP OPTIONS handler.
|
Router |
parser(MediaType contentType,
Parser parser)
Register a parser for the given content type.
|
default Route |
patch(String pattern,
Route.Handler handler)
Add a HTTP PATCH handler.
|
Router |
path(String pattern,
Runnable body)
Group one or more routes under a common path prefix.
|
static List<String> |
pathKeys(String pattern)
Extract path keys from given path pattern.
|
default Route |
post(String pattern,
Route.Handler handler)
Add a HTTP POST handler.
|
default Route |
put(String pattern,
Route.Handler handler)
Add a HTTP PUT handler.
|
Router |
renderer(MediaType contentType,
Renderer renderer)
Register a route response renderer.
|
Router |
renderer(Renderer renderer)
Register a route response renderer.
|
default <R> Router |
resource(ResourceKey<R> key,
R resource)
Put an application resource.
|
default <T> T |
resource(ResourceKey<T> key)
Get a resource under this key or throws a
IllegalStateException exception. |
Router |
responseHandler(ResponseHandler factory)
Add a response handler factory.
|
Router |
route(Runnable body)
Group one or more routes.
|
Route |
route(String method,
String pattern,
Route.Handler handler)
Add a route.
|
Router |
setContextPath(String contextPath)
Set application context path.
|
Router |
setDefaultWorker(Executor worker)
Set the default worker thread pool.
|
Router |
setRouterOptions(RouterOptions options)
Set router options.
|
Router |
setWorker(Executor worker)
Set a worker thread pool.
|
default Route |
trace(String pattern,
Route.Handler handler)
Add a HTTP TRACE handler.
|
Router |
use(Predicate<Context> predicate,
Router router)
Import routes from given router.
|
Router |
use(Router router)
Import all routes from the given router.
|
Router |
use(String path,
Router router)
Import all routes from the given router and prefix them with the given path.
|
static final String GET
static final String POST
static final String PUT
static final String DELETE
static final String PATCH
static final String HEAD
static final String CONNECT
static final String OPTIONS
static final String TRACE
@Nonnull Map<String,Object> getAttributes()
@Nonnull default <T> T attribute(@Nonnull String key)
getAttributes()
.T
- Attribute type.key
- Attribute key.@Nonnull default Router attribute(@Nonnull String key, Object value)
key
- Attribute key.value
- Attribute value.@Nonnull Map<ResourceKey,Object> getResources()
Jooby.onStop(AutoCloseable)
(if need it).@Nonnull default <T> T resource(@Nonnull ResourceKey<T> key) throws IllegalStateException
IllegalStateException
exception.T
- Attribute type.key
- Attribute key.IllegalStateException
- If there is no resource under this key.@Nonnull default <R> Router resource(@Nonnull ResourceKey<R> key, @Nonnull R resource)
R
- Resource type.key
- Resource key.resource
- Resource value.@Nonnull Router setContextPath(@Nonnull String contextPath)
/
.contextPath
- Context path.@Nonnull String getContextPath()
@Nonnull Router use(@Nonnull Predicate<Context> predicate, @Nonnull Router router)
{
use(ctx -> ctx.getHost().equals("foo.com"), new FooApp());
use(ctx -> ctx.getHost().equals("bar.com"), new BarApp());
}
Imported routes are matched only when predicate pass.predicate
- Context predicate.router
- Router to import.@Nonnull Router use(@Nonnull String path, @Nonnull Router router)
path
- Prefix path.router
- Router to import.@Nonnull Router use(@Nonnull Router router)
router
- Router to import.@Nonnull Router mvc(@Nonnull Class router)
Jooby.require(Class)
.router
- Controller class.@Nonnull <T> Router mvc(@Nonnull Class<T> router, @Nonnull javax.inject.Provider<T> provider)
T
- Controller type.router
- Controller class.provider
- Controller provider.@Nonnull Router mvc(@Nonnull Object router)
router
- Controller instance.@Nonnull Router renderer(@Nonnull Renderer renderer)
renderer
- Renderer instance.@Nonnull Router renderer(@Nonnull MediaType contentType, @Nonnull Renderer renderer)
contentType
- Accept header should matches the content-type.renderer
- Renderer instance.@Nonnull Path getTmpdir()
@Nonnull Router parser(@Nonnull MediaType contentType, @Nonnull Parser parser)
contentType
- Content type to match.parser
- Parser.@Nonnull Executor getWorker()
@Nonnull Router setWorker(@Nonnull Executor worker)
worker
- Worker thread pool.@Nonnull Router setDefaultWorker(@Nonnull Executor worker)
getWorker()
returns the default thread pool, unless you explicitly set one.worker
- Default worker thread pool.@Nonnull Router decorator(@Nonnull Route.Decorator decorator)
decorator
- Decorator.@Nonnull Router before(@Nonnull Route.Before before)
before
- Before decorator.@Nonnull Router after(@Nonnull Route.After after)
after
- After decorator.@Nonnull Router dispatch(@Nonnull Runnable body)
getWorker()
worker thread pool. After dispatch
application code is allowed to do blocking calls.body
- Dispatch body.@Nonnull Router dispatch(@Nonnull Executor executor, @Nonnull Runnable body)
executor
- Executor. ExecutorService
instances automatically
shutdown at application exit.body
- Dispatch body.@Nonnull Router route(@Nonnull Runnable body)
body
- Route body.@Nonnull Router path(@Nonnull String pattern, @Nonnull Runnable body)
pattern
- Path pattern.body
- Route body.@Nonnull default Route get(@Nonnull String pattern, @Nonnull Route.Handler handler)
pattern
- Path pattern.handler
- Application code.@Nonnull default Route post(@Nonnull String pattern, @Nonnull Route.Handler handler)
pattern
- Path pattern.handler
- Application code.@Nonnull default Route put(@Nonnull String pattern, @Nonnull Route.Handler handler)
pattern
- Path pattern.handler
- Application code.@Nonnull default Route delete(@Nonnull String pattern, @Nonnull Route.Handler handler)
pattern
- Path pattern.handler
- Application code.@Nonnull default Route patch(@Nonnull String pattern, @Nonnull Route.Handler handler)
pattern
- Path pattern.handler
- Application code.@Nonnull default Route head(@Nonnull String pattern, @Nonnull Route.Handler handler)
pattern
- Path pattern.handler
- Application code.@Nonnull default Route connect(@Nonnull String pattern, @Nonnull Route.Handler handler)
pattern
- Path pattern.handler
- Application code.@Nonnull default Route options(@Nonnull String pattern, @Nonnull Route.Handler handler)
pattern
- Path pattern.handler
- Application code.@Nonnull default Route trace(@Nonnull String pattern, @Nonnull Route.Handler handler)
pattern
- Path pattern.handler
- Application code.@Nonnull default Route assets(@Nonnull String pattern, @Nonnull Path source)
pattern
- Path pattern.source
- File system directory.@Nonnull default Route assets(@Nonnull String pattern, @Nonnull String source)
pattern
- Path pattern.source
- Classpath folder.@Nonnull default Route assets(@Nonnull String pattern, @Nonnull AssetSource... source)
pattern
- Path pattern.source
- Asset sources.@Nonnull default Route assets(@Nonnull String pattern, @Nonnull AssetHandler handler)
pattern
- Path pattern.handler
- Asset handler.@Nonnull Route route(@Nonnull String method, @Nonnull String pattern, @Nonnull Route.Handler handler)
method
- HTTP method.pattern
- Path pattern.handler
- Application code.@Nonnull Router.Match match(@Nonnull Context ctx)
404
handler.
See Route.NOT_FOUND
.ctx
- Web Context.@Nonnull Router errorCode(@Nonnull Class<? extends Throwable> type, @Nonnull StatusCode statusCode)
type
- Exception type.statusCode
- Status code.@Nonnull StatusCode errorCode(@Nonnull Throwable cause)
cause
- Exception.@Nonnull default Router error(@Nonnull StatusCode statusCode, @Nonnull ErrorHandler handler)
statusCode
- Status code.handler
- Error handler.@Nonnull default Router error(@Nonnull Class<? extends Throwable> type, @Nonnull ErrorHandler handler)
type
- Exception type.handler
- Error handler.@Nonnull default Router error(@Nonnull Predicate<StatusCode> predicate, @Nonnull ErrorHandler handler)
predicate
- Status code filter.handler
- Error handler.@Nonnull Router error(@Nonnull ErrorHandler handler)
handler
- Error handler.@Nonnull ErrorHandler getErrorHandler()
@Nonnull org.slf4j.Logger getLog()
@Nonnull Router responseHandler(@Nonnull ResponseHandler factory)
factory
- Response handler factory.@Nonnull RouterOptions getRouterOptions()
@Nonnull Router setRouterOptions(@Nonnull RouterOptions options)
options
- router options.@Nonnull static String normalizePath(@Nonnull String path, boolean caseSensitive, boolean ignoreTrailingSlash)
/
(slashes), make it lower case and
removing trailing slash.path
- Path to process.caseSensitive
- True to make it lower case.ignoreTrailingSlash
- True to remove trailing slash.Copyright © 2019. All rights reserved.