Router.Match
Constructor and Description |
---|
Jooby()
Creates a new Jooby instance.
|
Modifier and Type | Method and Description |
---|---|
Jooby |
after(Route.After after)
Add an after route decorator to the route pipeline.
|
<T> T |
attribute(String key)
Get an attribute by his key.
|
Jooby |
attribute(String key,
Object value)
Set an application attribute.
|
Jooby |
before(Route.Before before)
Add a before route decorator to the route pipeline.
|
static Jooby |
createApp(String[] args,
ExecutionMode executionMode,
Class<? extends Jooby> applicationType)
Setup default environment, logging (logback or log4j2) and run application.
|
static Jooby |
createApp(String[] args,
ExecutionMode executionMode,
Supplier<Jooby> provider)
Setup default environment, logging (logback or log4j2) and run application.
|
Jooby |
decoder(MediaType contentType,
MessageDecoder decoder)
Register a decoder for the given content type.
|
Jooby |
decorator(Route.Decorator decorator)
Add a route decorator to the route pipeline.
|
Jooby |
dispatch(Executor executor,
Runnable action)
Dispatch route pipeline to the given executor.
|
Jooby |
dispatch(Runnable body)
Dispatch route pipeline to the
Router.getWorker() worker thread pool. |
Jooby |
encoder(MediaType contentType,
MessageEncoder encoder)
Register a route response encoder.
|
Jooby |
encoder(MessageEncoder encoder)
Register a route response encoder.
|
Jooby |
error(ErrorHandler handler)
Add a custom error handler.
|
Jooby |
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.
|
Jooby |
executor(String name,
Executor executor)
Put an executor into the application registry.
|
Map<String,Object> |
getAttributes()
Mutable map of application attributes.
|
String |
getBasePackage()
Get base application package.
|
ClassLoader |
getClassLoader()
Application class loader.
|
com.typesafe.config.Config |
getConfig()
Application configuration.
|
String |
getContextPath()
Get application context path (a.k.a as base path).
|
Environment |
getEnvironment()
Application environment.
|
ErrorHandler |
getErrorHandler()
Get the error handler.
|
ExecutionMode |
getExecutionMode()
Application execution mode.
|
String |
getFlashCookie()
Name of the flash cookie.
|
org.slf4j.Logger |
getLog()
Application logger.
|
String |
getName()
Get application's name.
|
RouterOptions |
getRouterOptions()
Router options.
|
List<Route> |
getRoutes()
Returns all routes.
|
ServerOptions |
getServerOptions()
Server options or
null . |
ServiceRegistry |
getServices()
Application service registry.
|
SessionOptions |
getSessionOptions()
Get session options.
|
Path |
getTmpdir()
Application temporary directory.
|
String |
getVersion()
Get application version (description/debugging purpose only).
|
Executor |
getWorker()
Returns the worker thread pool.
|
Jooby |
install(Extension extension)
Install extension module.
|
Router.Match |
match(Context ctx)
Find a matching route using the given context.
|
Jooby |
mvc(Class router)
Import all route method from the given controller class.
|
<T> Jooby |
mvc(Class<T> router,
javax.inject.Provider<T> provider)
Import all route method from the given controller class.
|
Jooby |
mvc(Object router)
Import all route methods from given controller instance.
|
Jooby |
onStarted(SneakyThrows.Runnable body)
Event is fire once all components has been initialized, for example router and web-server
are up and running, extension installed, etc...
|
Jooby |
onStarting(SneakyThrows.Runnable body)
Event fired before starting router and web-server.
|
Jooby |
onStop(AutoCloseable body)
Stop event is fire at application shutdown time.
|
Jooby |
path(String pattern,
Runnable action)
Group one or more routes under a common path prefix.
|
Jooby |
ready(Server server)
Callback method that indicates application was successfully started it and listening for
connections.
|
Jooby |
registry(Registry registry)
Set application registry.
|
<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.
|
Jooby |
responseHandler(ResponseHandler handler)
Add a response handler factory.
|
Jooby |
route(Runnable action)
Group one or more routes.
|
Route |
route(String method,
String pattern,
Route.Handler handler)
Add a route.
|
static void |
runApp(String[] args,
Class<? extends Jooby> applicationType)
Setup default environment, logging (logback or log4j2) and run application.
|
static void |
runApp(String[] args,
Consumer<Jooby> consumer)
Setup default environment, logging (logback or log4j2) and run application.
|
static void |
runApp(String[] args,
ExecutionMode executionMode,
Class<? extends Jooby> applicationType)
Setup default environment, logging (logback or log4j2) and run application.
|
static void |
runApp(String[] args,
ExecutionMode executionMode,
Consumer<Jooby> consumer)
Setup default environment, logging (logback or log4j2) and run application.
|
static void |
runApp(String[] args,
ExecutionMode executionMode,
Supplier<Jooby> provider)
Setup default environment, logging (logback or log4j2) and run application.
|
static void |
runApp(String[] args,
Supplier<Jooby> provider)
Setup default environment, logging (logback or log4j2) and run application.
|
Jooby |
setContextPath(String basePath)
Set application context path.
|
Jooby |
setDefaultWorker(Executor worker)
Set the default worker thread pool.
|
Jooby |
setEnvironment(Environment environment)
Set application environment.
|
Environment |
setEnvironmentOptions(EnvironmentOptions options)
Set environment options and initialize/overrides the environment.
|
Jooby |
setExecutionMode(ExecutionMode mode)
Set application execution mode.
|
Jooby |
setFlashCookie(String name)
Set flash cookie name.
|
Jooby |
setLateInit(boolean lateInit)
Force all module to be initialized lazily at application startup time (not at
creation/instantiation time).
|
Jooby |
setName(String name)
Set application name (only for description purpose).
|
Jooby |
setRouterOptions(RouterOptions options)
Set router options.
|
Jooby |
setServerOptions(ServerOptions serverOptions)
Set server options.
|
Jooby |
setSessionOptions(SessionOptions options)
Set session options.
|
Jooby |
setTmpdir(Path tmpdir)
Set application temporary directory.
|
Jooby |
setVersion(String version)
Set application version.
|
Jooby |
setWorker(Executor worker)
Set a worker thread pool.
|
Server |
start()
Start application, find a web server, deploy application, start router, extension modules,
etc..
|
Jooby |
start(Server server)
Call back method that indicates application was deploy it in the given server.
|
Jooby |
stop()
Stop application, fire the stop event to cleanup resources.
|
String |
toString() |
Jooby |
use(Predicate<Context> predicate,
Router router)
Import routes from given router.
|
Jooby |
use(Router router)
Import all routes from the given router.
|
Jooby |
use(String path,
Router router)
Import all routes from the given router and prefix them with the given path.
|
@Nullable public ServerOptions getServerOptions()
null
.null
.@Nonnull public Jooby setServerOptions(@Nonnull ServerOptions serverOptions)
serverOptions
- Server options.@Nonnull public RouterOptions getRouterOptions()
Router
getRouterOptions
in interface Router
@Nonnull public Jooby setRouterOptions(@Nonnull RouterOptions options)
Router
setRouterOptions
in interface Router
options
- router options.@Nonnull public Environment getEnvironment()
Environment.loadEnvironment(EnvironmentOptions)
.@Nonnull public ClassLoader getClassLoader()
@Nonnull public com.typesafe.config.Config getConfig()
Environment.getConfig()
.@Nonnull public Jooby setEnvironment(@Nonnull Environment environment)
environment
- Application environment.@Nonnull public Environment setEnvironmentOptions(@Nonnull EnvironmentOptions options)
options
- Environment options.@Nonnull public Jooby onStarting(@Nonnull SneakyThrows.Runnable body)
body
- Start body.@Nonnull public Jooby onStarted(@Nonnull SneakyThrows.Runnable body)
body
- Start body.@Nonnull public Jooby onStop(@Nonnull AutoCloseable body)
body
- Stop body.@Nonnull public Jooby setContextPath(@Nonnull String basePath)
Router
/
.setContextPath
in interface Router
basePath
- Context path.@Nonnull public String getContextPath()
Router
getContextPath
in interface Router
@Nonnull public Jooby use(@Nonnull Router router)
Router
@Nonnull public Jooby use(@Nonnull Predicate<Context> predicate, @Nonnull Router 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.@Nonnull public Jooby use(@Nonnull String path, @Nonnull Router router)
Router
@Nonnull public Jooby mvc(@Nonnull Object router)
Router
@Nonnull public Jooby mvc(@Nonnull Class router)
Router
require(Class)
.@Nonnull public <T> Jooby mvc(@Nonnull Class<T> router, @Nonnull javax.inject.Provider<T> provider)
Router
@Nonnull public List<Route> getRoutes()
Router
@Nonnull public Jooby error(@Nonnull ErrorHandler handler)
Router
@Nonnull public Jooby decorator(@Nonnull Route.Decorator decorator)
Router
@Nonnull public Jooby before(@Nonnull Route.Before before)
Router
@Nonnull public Jooby after(@Nonnull Route.After after)
Router
@Nonnull public Jooby encoder(@Nonnull MessageEncoder encoder)
Router
@Nonnull public Jooby decoder(@Nonnull MediaType contentType, @Nonnull MessageDecoder decoder)
Router
@Nonnull public Jooby encoder(@Nonnull MediaType contentType, @Nonnull MessageEncoder encoder)
Router
@Nonnull public Jooby install(@Nonnull Extension extension)
extension
- Extension module.@Nonnull public Jooby dispatch(@Nonnull Runnable body)
Router
Router.getWorker()
worker thread pool. After dispatch
application code is allowed to do blocking calls.@Nonnull public Jooby 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 Jooby path(@Nonnull String pattern, @Nonnull Runnable action)
Router
@Nonnull public Jooby route(@Nonnull Runnable action)
Router
@Nonnull public Route route(@Nonnull String method, @Nonnull String pattern, @Nonnull Route.Handler handler)
Router
@Nonnull public Router.Match match(@Nonnull Context ctx)
Router
404
handler.
See Route.NOT_FOUND
.@Nonnull public Jooby errorCode(@Nonnull Class<? extends Throwable> type, @Nonnull StatusCode statusCode)
Router
@Nonnull public StatusCode errorCode(@Nonnull Throwable cause)
Router
@Nonnull public Executor getWorker()
Router
@Nonnull public Jooby setWorker(@Nonnull Executor worker)
Router
@Nonnull public Jooby 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 org.slf4j.Logger getLog()
Router
@Nonnull public Jooby responseHandler(ResponseHandler handler)
Router
responseHandler
in interface Router
handler
- Response handler factory.@Nonnull public ErrorHandler getErrorHandler()
Router
getErrorHandler
in interface Router
@Nonnull public Path getTmpdir()
Router
@Nonnull public Jooby setTmpdir(@Nonnull Path tmpdir)
tmpdir
- Temp directory.@Nonnull public ExecutionMode getExecutionMode()
@Nonnull public Jooby setExecutionMode(@Nonnull ExecutionMode mode)
mode
- Application execution mode.@Nonnull public Map<String,Object> getAttributes()
Router
getAttributes
in interface Router
@Nonnull public Jooby attribute(@Nonnull String key, @Nonnull Object value)
Router
@Nonnull public <T> T attribute(@Nonnull String key)
Router
Router.getAttributes()
.@Nonnull public <T> T require(@Nonnull Class<T> type, @Nonnull String name)
Registry
@Nonnull public <T> T require(@Nonnull Class<T> type)
Registry
@Nonnull public <T> T require(@Nonnull ServiceKey<T> key)
Registry
@Nonnull public Jooby registry(@Nonnull Registry registry)
registry
- Application registry.@Nonnull public ServiceRegistry getServices()
Router
require(Class)
calls.
This method returns a mutable registry. You are free to modify/alter the registry.getServices
in interface Router
@Nullable public String getBasePackage()
@Nonnull public SessionOptions getSessionOptions()
Router
getSessionOptions
in interface Router
@Nonnull public Jooby setSessionOptions(@Nonnull SessionOptions options)
Router
setSessionOptions
in interface Router
options
- Session options.@Nonnull public Jooby executor(@Nonnull String name, @Nonnull Executor executor)
Router
@Nonnull public String getFlashCookie()
Router
jooby.flash
.getFlashCookie
in interface Router
jooby.flash
.@Nonnull public Jooby setFlashCookie(@Nonnull String name)
Router
setFlashCookie
in interface Router
name
- Flash cookie name.@Nonnull public Server start()
@Nonnull public Jooby start(@Nonnull Server server)
server
- Server.@Nonnull public Jooby ready(@Nonnull Server server)
server
- Server.@Nonnull public Jooby stop()
Server.stop()
using a shutdown hook.
The next example shows how to successfully stop the web server and application:
Jooby app = new Jooby();
Server server = app.start();
...
server.stop();
public Jooby setLateInit(boolean lateInit)
lateInit
- True for late init.@Nonnull public String getName()
Package.getImplementationTitle()
.
- Otherwise fallback to class name.@Nonnull public Jooby setName(@Nonnull String name)
name
- Application's name.@Nonnull public String getVersion()
Package.getImplementationVersion()
. This attribute is present
when application has been packaged (jar file).
- Otherwise, fallback to 0.0.0
.@Nonnull public Jooby setVersion(@Nonnull String version)
version
- Application's version.public static void runApp(@Nonnull String[] args, @Nonnull Class<? extends Jooby> applicationType)
args
- Application arguments.applicationType
- Application type.public static void runApp(@Nonnull String[] args, @Nonnull ExecutionMode executionMode, @Nonnull Class<? extends Jooby> applicationType)
args
- Application arguments.executionMode
- Application execution mode.applicationType
- Application type.public static Jooby createApp(@Nonnull String[] args, @Nonnull ExecutionMode executionMode, @Nonnull Class<? extends Jooby> applicationType)
args
- Application arguments.executionMode
- Application execution mode.applicationType
- Application type.public static void runApp(@Nonnull String[] args, @Nonnull Supplier<Jooby> provider)
args
- Application arguments.provider
- Application provider.public static void runApp(@Nonnull String[] args, @Nonnull Consumer<Jooby> consumer)
args
- Application arguments.consumer
- Application consumer.public static void runApp(@Nonnull String[] args, @Nonnull ExecutionMode executionMode, @Nonnull Consumer<Jooby> consumer)
args
- Application arguments.executionMode
- Application execution mode.consumer
- Application consumer.public static void runApp(@Nonnull String[] args, @Nonnull ExecutionMode executionMode, @Nonnull Supplier<Jooby> provider)
args
- Application arguments.executionMode
- Application execution mode.provider
- Application provider.public static Jooby createApp(@Nonnull String[] args, @Nonnull ExecutionMode executionMode, @Nonnull Supplier<Jooby> provider)
args
- Application arguments.executionMode
- Application execution mode.provider
- Application provider.Copyright © 2019. All rights reserved.