public interface Router extends Registry
Modifier and Type | Interface and Description |
---|---|
static interface |
Router.Match
Find route result.
|
Modifier and Type | Field and Description |
---|---|
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.
|
static String |
WS
Web socket.
|
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)
Add a static resource handler.
|
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.
|
Router |
converter(BeanConverter converter)
Add a custom bean value converter.
|
Router |
converter(ValueConverter converter)
Add a custom string value converter.
|
Router |
decoder(MediaType contentType,
MessageDecoder decoder)
Register a decoder for the given content type.
|
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. |
Router |
encoder(MediaType contentType,
MessageEncoder encoder)
Register a route response encoder.
|
Router |
encoder(MessageEncoder encoder)
Register a route response encoder.
|
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 Executor |
executor(String name)
Get an executor from application registry.
|
Router |
executor(String name,
Executor executor)
Put an executor into the application registry.
|
default Route |
get(String pattern,
Route.Handler handler)
Add a HTTP GET handler.
|
Map<String,Object> |
getAttributes()
Mutable map of application attributes.
|
List<BeanConverter> |
getBeanConverters()
Get all complex/bean value converters.
|
com.typesafe.config.Config |
getConfig()
Application configuration.
|
String |
getContextPath()
Get application context path (a.k.a as base path).
|
List<ValueConverter> |
getConverters()
Get all simple/string value converters.
|
ErrorHandler |
getErrorHandler()
Get the error handler.
|
String |
getFlashCookie()
Name of the flash cookie.
|
org.slf4j.Logger |
getLog()
Application logger.
|
RouterOptions |
getRouterOptions()
Router options.
|
List<Route> |
getRoutes()
Returns all routes.
|
ServerOptions |
getServerOptions()
Available server options.
|
ServiceRegistry |
getServices()
Application service registry.
|
SessionStore |
getSessionStore()
Session store.
|
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 ignoreCase,
boolean ignoreTrailingSlash)
Normalize a path by removing consecutive
/ (slashes), make it lower case and
removing trailing slash. |
default Route |
options(String pattern,
Route.Handler handler)
Add a HTTP OPTIONS handler.
|
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 |
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 |
setFlashCookie(String name)
Set flash cookie name.
|
Router |
setRouterOptions(RouterOptions options)
Set router options.
|
Router |
setSessionStore(SessionStore store)
Set session store.
|
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.
|
Route |
ws(String pattern,
WebSocket.Initializer handler)
Add a websocket handler.
|
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 OPTIONS
static final String TRACE
static final String WS
@Nonnull com.typesafe.config.Config getConfig()
@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 ServiceRegistry getServices()
Jooby.require(Class)
calls.
This method returns a mutable registry. You are free to modify/alter the registry.@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 Route ws(@Nonnull String pattern, @Nonnull WebSocket.Initializer handler)
pattern
- WebSocket path pattern.handler
- WebSocket handler.@Nonnull Router encoder(@Nonnull MessageEncoder encoder)
encoder
- MessageEncoder instance.@Nonnull Router encoder(@Nonnull MediaType contentType, @Nonnull MessageEncoder encoder)
contentType
- Accept header should matches the content-type.encoder
- MessageEncoder instance.@Nonnull Path getTmpdir()
@Nonnull Router decoder(@Nonnull MediaType contentType, @Nonnull MessageDecoder decoder)
contentType
- Content type to match.decoder
- MessageDecoder.@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 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
- File-System folder when exists, or fallback to a classpath folder.@Nonnull default Route assets(@Nonnull String pattern)
pattern
- Path pattern.@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 SessionStore getSessionStore()
SessionStore.memory()
.@Nonnull Router setSessionStore(@Nonnull SessionStore store)
store
- Session store.@Nonnull default Executor executor(@Nonnull String name)
name
- Executor name.@Nonnull Router executor(@Nonnull String name, @Nonnull Executor executor)
name
- Executor's name.executor
- Executor.@Nonnull String getFlashCookie()
jooby.flash
.jooby.flash
.@Nonnull Router setFlashCookie(@Nonnull String name)
name
- Flash cookie name.@Nonnull Router converter(@Nonnull ValueConverter converter)
converter
- Custom value converter.@Nonnull Router converter(@Nonnull BeanConverter converter)
converter
- Custom value converter.@Nonnull List<ValueConverter> getConverters()
@Nonnull List<BeanConverter> getBeanConverters()
@Nonnull ServerOptions getServerOptions()
@Nonnull static String normalizePath(@Nonnull String path, boolean ignoreCase, boolean ignoreTrailingSlash)
/
(slashes), make it lower case and
removing trailing slash.path
- Path to process.ignoreCase
- True to make it lower case.ignoreTrailingSlash
- True to remove trailing slash.Copyright © 2019. All rights reserved.