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.
|
String |
getFlashCookie()
Name of the flash cookie.
|
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 |
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 |
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(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() |
Router |
use(Predicate<Context> predicate,
Router subrouter)
Import routes from given router.
|
RouteSet |
use(Predicate<Context> predicate,
Runnable body)
Import routes from given action.
|
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.
|
public RouterImpl(ClassLoader loader)
@Nonnull public com.typesafe.config.Config getConfig()
Router@Nonnull public Environment getEnvironment()
RoutergetEnvironment in interface Router@Nonnull public Map<String,Object> getAttributes()
RoutergetAttributes in interface Router@Nonnull public Set<RouterOption> getRouterOptions()
RoutergetRouterOptions in interface Router@Nonnull public Router setRouterOptions(@Nonnull RouterOption... options)
RoutersetRouterOptions in interface Routeroptions - router options.@Nonnull public Router setContextPath(@Nonnull String basePath)
Router/.setContextPath in interface RouterbasePath - Context path.@Nonnull public Path getTmpdir()
RouterEnvironment when isn't
set manually.@Nonnull public String getContextPath()
RoutergetContextPath in interface Router@Nonnull public List<Route> getRoutes()
Routerpublic boolean isTrustProxy()
RouterX-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)
RouterX-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 RoutertrustProxy - True to enabled.@Nonnull public RouteSet domain(@Nonnull String domain, @Nonnull Runnable body)
Routerhost 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)
Routerhost 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).@Nonnull public RouteSet use(@Nonnull Predicate<Context> predicate, @Nonnull Runnable body)
Router
{
use(ctx -> ctx.getHost().equals("foo.com"), () -> {
get("/", ctx -> "foo");
});
use(ctx -> ctx.getHost().equals("bar.com"), () -> {
get("/", ctx -> "bar");
});
}
NOTE: if you run behind a reverse proxy you might to enabled Router.setTrustProxy(boolean).@Nonnull public Router use(@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).@Nonnull public Router use(@Nonnull String path, @Nonnull Router router)
Router@Nonnull public Router use(@Nonnull Router router)
Router@Nonnull public Router mvc(@Nonnull Object router)
Router@Nonnull public Router mvc(@Nonnull Class router)
RouterJooby.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)
RouterRouter.getWorker() returns the default thread pool, unless you explicitly set one.setDefaultWorker in interface Routerworker - 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)
RouterRouter.getWorker() worker thread pool. After dispatch
application code is allowed to do blocking calls.@Nonnull public Router dispatch(@Nonnull Executor executor, @Nonnull Runnable action)
Routerdispatch in interface Routerexecutor - 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()
RouterSessionStore.memory().getSessionStore in interface Router@Nonnull public Router setSessionStore(SessionStore sessionStore)
RoutersetSessionStore in interface RoutersessionStore - Session store.@Nonnull public Router converter(ValueConverter converter)
Router@Nonnull public Router converter(@Nonnull BeanConverter converter)
Router@Nonnull public List<ValueConverter> getConverters()
RoutergetConverters in interface Router@Nonnull public List<BeanConverter> getBeanConverters()
RoutergetBeanConverters 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)
Routerpublic Route route(@Nonnull String method, @Nonnull String pattern, @Nonnull Route.Handler handler)
Routerpublic org.slf4j.Logger getLog()
Router@Nonnull public Router executor(@Nonnull String name, @Nonnull Executor executor)
Routerpublic void destroy()
@Nonnull public ErrorHandler getErrorHandler()
RoutergetErrorHandler in interface Router@Nonnull public Router.Match match(@Nonnull Context ctx)
Router404 handler.
See Route.NOT_FOUND.public boolean match(@Nonnull String pattern, @Nonnull String path)
Router404 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)
RouterresponseHandler in interface Routerhandler - Response handler factory.@Nonnull public ServiceRegistry getServices()
RouterJooby.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
Registryrequire in interface RegistryT - 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
Registryrequire in interface RegistryT - 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
Registryrequire in interface RegistryT - Object type.key - Object key.RegistryException - If there was a runtime failure while providing an instance.@Nonnull public String getFlashCookie()
Routerjooby.flash.getFlashCookie in interface Routerjooby.flash.@Nonnull public Router setFlashCookie(@Nonnull String name)
RoutersetFlashCookie in interface Routername - Flash cookie name.@Nonnull public ServerOptions getServerOptions()
RoutergetServerOptions in interface Router@Nonnull public Router setHiddenMethod(@Nonnull String parameterName)
RouterRouter.setHiddenMethod(Function) method.setHiddenMethod in interface RouterparameterName - Form field name.@Nonnull public Router setHiddenMethod(@Nonnull Function<Context,Optional<String>> provider)
RoutersetHiddenMethod in interface Routerprovider - Lookup strategy.@Nonnull public Router setCurrentUser(@Nonnull Function<Context,Object> provider)
RouterContext. Current user can be retrieve it
using Context.getUser().setCurrentUser in interface Routerprovider - User provider/factory.Copyright © 2020. All rights reserved.