Router.Match
Constructor and Description |
---|
RouterImpl(ClassLoader loader) |
Modifier and Type | Method and Description |
---|---|
Router |
after(Route.After after)
Add an after route decorator to the route pipeline.
|
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.
|
void |
destroy() |
Router |
dispatch(Executor executor,
Runnable action)
Dispatch route pipeline to the given executor.
|
Router |
dispatch(Runnable body)
Dispatch route pipeline to the
Router.getWorker() worker thread pool. |
Router |
domain(String domain,
Router subrouter)
Enabled routes for specific domain.
|
RouteSet |
domain(String domain,
Runnable body)
Enabled routes for specific domain.
|
Router |
encoder(MediaType contentType,
MessageEncoder encoder)
Register a route response encoder.
|
Router |
encoder(MessageEncoder encoder)
Register a route response encoder.
|
Router |
error(ErrorHandler handler)
Add a custom error handler.
|
Router |
errorCode(Class<? extends Throwable> type,
StatusCode statusCode)
Map an exception type to a status code.
|
StatusCode |
errorCode(Throwable x)
Computes the status code for the given exception.
|
Router |
executor(String name,
Executor executor)
Put an executor into the application registry.
|
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.
|
Environment |
getEnvironment()
Application environment.
|
ErrorHandler |
getErrorHandler()
Get the error handler.
|
Cookie |
getFlashCookie()
Template for the flash cookie.
|
List<Locale> |
getLocales()
Returns the supported locales.
|
org.slf4j.Logger |
getLog()
Application logger.
|
Set<RouterOption> |
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.
|
boolean |
isTrustProxy()
When true handles X-Forwarded-* headers by updating the values on the current context to
match what was sent in the header(s).
|
Router.Match |
match(Context ctx)
Find a matching route using the given context.
|
boolean |
match(String pattern,
String path)
Find a matching route using the given context.
|
Router |
mount(Predicate<Context> predicate,
Router subrouter)
Import routes from given router.
|
RouteSet |
mount(Predicate<Context> predicate,
Runnable body)
Import routes from given action.
|
Router |
mount(Router router)
Import all routes from the given router.
|
Router |
mount(String path,
Router router)
Import all routes from the given router and prefix them with the given path.
|
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.
|
RouteSet |
path(String pattern,
Runnable action)
Group one or more routes under a common path prefix.
|
<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.
|
Router |
responseHandler(ResponseHandler handler)
Add a response handler factory.
|
Route |
route(String method,
String pattern,
Route.Handler handler)
Add a route.
|
RouteSet |
routes(Runnable action)
Group one or more routes.
|
Router |
setContextAsService(boolean contextAsService)
If enabled, allows to retrieve the
Context object associated with the current
request via the service registry while the request is being processed. |
Router |
setContextPath(String basePath)
Set application context path.
|
Router |
setCurrentUser(Function<Context,Object> provider)
Provides a way to set the current user from a
Context . |
Router |
setDefaultWorker(Executor worker)
Set the default worker thread pool.
|
Router |
setFlashCookie(Cookie flashCookie)
Sets a cookie used as a template to generate the flash cookie, allowing
to customize the cookie name and other cookie parameters.
|
Router |
setFlashCookie(String name)
Set flash cookie name.
|
Router |
setHiddenMethod(Function<Context,Optional<String>> provider)
Provides a way to override the current HTTP method using lookup strategy.
|
Router |
setHiddenMethod(String parameterName)
Provides a way to override the current HTTP method.
|
Router |
setRouterOptions(RouterOption... options)
Set router options.
|
Router |
setSessionStore(SessionStore sessionStore)
Set session store.
|
Router |
setTrustProxy(boolean trustProxy)
When true handles X-Forwarded-* headers by updating the values on the current context to
match what was sent in the header(s).
|
Router |
setWorker(Executor worker)
Set a worker thread pool.
|
Route |
sse(String pattern,
ServerSentEmitter.Handler handler)
Add a server-sent event handler.
|
Router |
start(Jooby app) |
String |
toString() |
Route |
ws(String pattern,
WebSocket.Initializer handler)
Add a websocket handler.
|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
assets, assets, assets, assets, attribute, attribute, delete, error, error, error, executor, expandOptionalVariables, get, head, leadingSlash, normalizePath, noTrailingSlash, options, patch, pathKeys, pathKeys, post, put, reverse, reverse, trace, use, use, use, use
public RouterImpl(ClassLoader loader)
@Nonnull public com.typesafe.config.Config getConfig()
Router
@Nonnull public Environment getEnvironment()
Router
getEnvironment
in interface Router
@Nonnull public List<Locale> getLocales()
Router
getLocales
in interface Router
@Nonnull public Map<String,Object> getAttributes()
Router
getAttributes
in interface Router
@Nonnull public Set<RouterOption> getRouterOptions()
Router
getRouterOptions
in interface Router
@Nonnull public Router setRouterOptions(@Nonnull RouterOption... options)
Router
setRouterOptions
in interface Router
options
- router options.@Nonnull public Router setContextPath(@Nonnull String basePath)
Router
/
.setContextPath
in interface Router
basePath
- Context path.@Nonnull public Path getTmpdir()
Router
Environment
when isn't
set manually.@Nonnull public String getContextPath()
Router
getContextPath
in interface Router
@Nonnull public List<Route> getRoutes()
Router
public boolean isTrustProxy()
Router
X-Forwarded-*
header, otherwise a remote user can spoof their address by
sending a header with bogus values.
The headers that are read/set are:
Context.setRemoteAddress(String)
.Context.setScheme(String)
.Context.setHost(String)
.Context.setPort(int)
.isTrustProxy
in interface Router
@Nonnull public Router setTrustProxy(boolean trustProxy)
Router
X-Forwarded-*
header, otherwise a remote user can spoof their address by
sending a header with bogus values.
The headers that are read/set are:
Context.setRemoteAddress(String)
.Context.setScheme(String)
.Context.setHost(String)
.Context.setPort(int)
.setTrustProxy
in interface Router
trustProxy
- True to enabled.@Nonnull public RouteSet domain(@Nonnull String domain, @Nonnull Runnable body)
Router
host
header.
{
domain("foo.com", () -> {
get("/", ctx -> "foo");
});
domain("bar.com", () -> {
get("/", ctx -> "bar");
});
}
NOTE: if you run behind a reverse proxy you might to enabled Router.setTrustProxy(boolean)
.@Nonnull public Router domain(@Nonnull String domain, @Nonnull Router subrouter)
Router
host
header.
{
domain("foo.com", new FooApp());
domain("bar.com", new BarApp());
}
NOTE: if you run behind a reverse proxy you might to enabled Router.setTrustProxy(boolean)
.
NOTE: ONLY routes are imported. Services, callback, etc.. are ignored.@Nonnull public RouteSet mount(@Nonnull Predicate<Context> predicate, @Nonnull Runnable body)
Router
{
mount(ctx -> ctx.getHost().equals("foo.com"), () -> {
get("/", ctx -> "foo");
});
mount(ctx -> ctx.getHost().equals("bar.com"), () -> {
get("/", ctx -> "bar");
});
}
NOTE: if you run behind a reverse proxy you might to enabled Router.setTrustProxy(boolean)
.
NOTE: ONLY routes are imported. Services, callback, etc.. are ignored.@Nonnull public Router mount(@Nonnull Predicate<Context> predicate, @Nonnull Router subrouter)
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.
NOTE: if you run behind a reverse proxy you might to enabled Router.setTrustProxy(boolean)
.
NOTE: ONLY routes are imported. Services, callback, etc.. are ignored.@Nonnull public Router mount(@Nonnull String path, @Nonnull Router router)
Router
@Nonnull public Router mount(@Nonnull Router router)
Router
@Nonnull public Router mvc(@Nonnull Object router)
Router
@Nonnull public Router mvc(@Nonnull Class router)
Router
Jooby.require(Class)
.@Nonnull public <T> Router mvc(@Nonnull Class<T> router, @Nonnull javax.inject.Provider<T> provider)
Router
@Nonnull public Router encoder(@Nonnull MessageEncoder encoder)
Router
@Nonnull public Router encoder(@Nonnull MediaType contentType, @Nonnull MessageEncoder encoder)
Router
@Nonnull public Router decoder(@Nonnull MediaType contentType, @Nonnull MessageDecoder decoder)
Router
@Nonnull public Executor getWorker()
Router
@Nonnull public Router setWorker(Executor worker)
Router
@Nonnull public Router setDefaultWorker(@Nonnull Executor worker)
Router
Router.getWorker()
returns the default thread pool, unless you explicitly set one.setDefaultWorker
in interface Router
worker
- Default worker thread pool.@Nonnull public Router decorator(@Nonnull Route.Decorator decorator)
Router
@Nonnull public Router after(@Nonnull Route.After after)
Router
@Nonnull public Router before(@Nonnull Route.Before before)
Router
@Nonnull public Router error(@Nonnull ErrorHandler handler)
Router
@Nonnull public Router dispatch(@Nonnull Runnable body)
Router
Router.getWorker()
worker thread pool. After dispatch
application code is allowed to do blocking calls.@Nonnull public Router dispatch(@Nonnull Executor executor, @Nonnull Runnable action)
Router
dispatch
in interface Router
executor
- Executor. ExecutorService
instances automatically
shutdown at application exit.action
- Dispatch body.@Nonnull public RouteSet routes(@Nonnull Runnable action)
Router
@Nonnull public RouteSet path(@Nonnull String pattern, @Nonnull Runnable action)
Router
@Nonnull public SessionStore getSessionStore()
Router
SessionStore.memory()
.getSessionStore
in interface Router
@Nonnull public Router setSessionStore(SessionStore sessionStore)
Router
setSessionStore
in interface Router
sessionStore
- Session store.@Nonnull public Router converter(ValueConverter converter)
Router
@Nonnull public Router converter(@Nonnull BeanConverter converter)
Router
@Nonnull public List<ValueConverter> getConverters()
Router
getConverters
in interface Router
@Nonnull public List<BeanConverter> getBeanConverters()
Router
getBeanConverters
in interface Router
@Nonnull public Route ws(@Nonnull String pattern, @Nonnull WebSocket.Initializer handler)
Router
@Nonnull public Route sse(@Nonnull String pattern, @Nonnull ServerSentEmitter.Handler handler)
Router
public Route route(@Nonnull String method, @Nonnull String pattern, @Nonnull Route.Handler handler)
Router
public org.slf4j.Logger getLog()
Router
@Nonnull public Router executor(@Nonnull String name, @Nonnull Executor executor)
Router
public void destroy()
@Nonnull public ErrorHandler getErrorHandler()
Router
getErrorHandler
in interface Router
@Nonnull public Router.Match match(@Nonnull Context ctx)
Router
404
handler.
See Route.NOT_FOUND
.public boolean match(@Nonnull String pattern, @Nonnull String path)
Router
404
handler.
See Route.NOT_FOUND
.@Nonnull public Router errorCode(@Nonnull Class<? extends Throwable> type, @Nonnull StatusCode statusCode)
Router
@Nonnull public StatusCode errorCode(@Nonnull Throwable x)
Router
@Nonnull public Router responseHandler(ResponseHandler handler)
Router
responseHandler
in interface Router
handler
- Response handler factory.@Nonnull public ServiceRegistry getServices()
Router
Jooby.require(Class)
calls.
This method returns a mutable registry. You are free to modify/alter the registry.getServices
in interface Router
@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 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 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.@Nonnull public Router setFlashCookie(@Nonnull String name)
Router
setFlashCookie
in interface Router
name
- Flash cookie name.@Nonnull public Cookie getFlashCookie()
Router
jooby.flash
.getFlashCookie
in interface Router
@Nonnull public Router setFlashCookie(@Nonnull Cookie flashCookie)
Router
setFlashCookie
in interface Router
flashCookie
- The cookie template.@Nonnull public ServerOptions getServerOptions()
Router
getServerOptions
in interface Router
@Nonnull public Router setHiddenMethod(@Nonnull String parameterName)
Router
Router.setHiddenMethod(Function)
method.setHiddenMethod
in interface Router
parameterName
- Form field name.@Nonnull public Router setHiddenMethod(@Nonnull Function<Context,Optional<String>> provider)
Router
setHiddenMethod
in interface Router
provider
- Lookup strategy.@Nonnull public Router setCurrentUser(@Nonnull Function<Context,Object> provider)
Router
Context
. Current user can be retrieve it
using Context.getUser()
.setCurrentUser
in interface Router
provider
- User provider/factory.@Nonnull public Router setContextAsService(boolean contextAsService)
Router
Context
object associated with the current
request via the service registry while the request is being processed.setContextAsService
in interface Router
contextAsService
- whether to enable or disable this featureCopyright © 2022. All rights reserved.