Module io.jooby
Package io.jooby

Class Jooby

java.lang.Object
io.jooby.Jooby
All Implemented Interfaces:
Registry, Router

public class Jooby extends Object implements Router, Registry
Welcome to Jooby!

Hello World:


 public class App extends Jooby {

   {
     get("/", ctx -> "Hello World!");
   }

   public static void main(String[] args) {
     runApp(args, App::new);
   }
 }

 
More documentation at jooby.io
Since:
2.0.0
Author:
edgar
  • Constructor Details

    • Jooby

      public Jooby()
      Creates a new Jooby instance.
  • Method Details

    • getServerOptions

      @Nullable public ServerOptions getServerOptions()
      Server options or null.
      Specified by:
      getServerOptions in interface Router
      Returns:
      Server options or null.
    • setServerOptions

      @NonNull public Jooby setServerOptions(@NonNull ServerOptions serverOptions)
      Set server options.
      Parameters:
      serverOptions - Server options.
      Returns:
      This application.
    • getRouterOptions

      @NonNull public Set<RouterOption> getRouterOptions()
      Description copied from interface: Router
      Router options.
      Specified by:
      getRouterOptions in interface Router
      Returns:
      Router options.
    • setRouterOptions

      @NonNull public Jooby setRouterOptions(@NonNull RouterOption... options)
      Description copied from interface: Router
      Set router options.
      Specified by:
      setRouterOptions in interface Router
      Parameters:
      options - router options.
      Returns:
      This router.
    • getEnvironment

      @NonNull public Environment getEnvironment()
      Application environment. If none was set, environment is initialized using Environment.loadEnvironment(EnvironmentOptions).
      Specified by:
      getEnvironment in interface Router
      Returns:
      Application environment.
    • getLocales

      @Nullable public List<Locale> getLocales()
      Returns the list of supported locales, or null if none set.
      Specified by:
      getLocales in interface Router
      Returns:
      The supported locales.
    • setLocales

      public Router setLocales(@NonNull List<Locale> locales)
      Sets the supported locales.
      Parameters:
      locales - The supported locales.
      Returns:
      This router.
    • setLocales

      public Router setLocales(Locale... locales)
      Sets the supported locales.
      Parameters:
      locales - The supported locales.
      Returns:
      This router.
    • getClassLoader

      @NonNull public ClassLoader getClassLoader()
      Application class loader.
      Returns:
      Application class loader.
    • getConfig

      @NonNull public com.typesafe.config.Config getConfig()
      Application configuration. It is a shortcut for Environment.getConfig().
      Specified by:
      getConfig in interface Router
      Returns:
      Application config.
    • setEnvironment

      @NonNull public Jooby setEnvironment(@NonNull Environment environment)
      Set application environment.
      Parameters:
      environment - Application environment.
      Returns:
      This application.
    • setEnvironmentOptions

      @NonNull public Environment setEnvironmentOptions(@NonNull EnvironmentOptions options)
      Set environment options and initialize/overrides the environment.
      Parameters:
      options - Environment options.
      Returns:
      New environment.
    • onStarting

      @NonNull public Jooby onStarting(@NonNull SneakyThrows.Runnable body)
      Event fired before starting router and web-server. Non-lateinit extension are installed at this stage.
      Parameters:
      body - Start body.
      Returns:
      This application.
    • onStarted

      @NonNull public Jooby onStarted(@NonNull 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...
      Parameters:
      body - Start body.
      Returns:
      This application.
    • onStop

      @NonNull public Jooby onStop(@NonNull AutoCloseable body)
      Stop event is fire at application shutdown time. Useful to execute cleanup task, free resources, etc...
      Parameters:
      body - Stop body.
      Returns:
      This application.
    • setContextPath

      @NonNull public Jooby setContextPath(@NonNull String basePath)
      Description copied from interface: Router
      Set application context path. Context path is the base path for all routes. Default is: / .
      Specified by:
      setContextPath in interface Router
      Parameters:
      basePath - Context path.
      Returns:
      This router.
    • getContextPath

      @NonNull public String getContextPath()
      Description copied from interface: Router
      Get application context path (a.k.a as base path).
      Specified by:
      getContextPath in interface Router
      Returns:
      Application context path (a.k.a as base path).
    • install

      @NonNull public Jooby install(@NonNull SneakyThrows.Supplier<Jooby> factory)
      Installs/imports a full application into this one. Applications share services, registry, callbacks, etc.

      Applications must be instantiated/created lazily via a supplier/factory. This is required due to the way an application is usually initialized (constructor initializer).

      Working example:

      
       install(SubApp::new);
      
       
      Lazy creation configures and setup SubApp correctly, the next example won't work:
      
       SubApp app = new SubApp();
       install(app); // WONT WORK
      
       
      Note: you must take care of application services across the applications. For example make sure you don't configure the same service twice or more in the main and imported applications too.
      Parameters:
      factory - Application factory.
      Returns:
      This application.
    • install

      @NonNull public Jooby install(@NonNull String path, @NonNull SneakyThrows.Supplier<Jooby> factory)
      Installs/imports a full application into this one. Applications share services, registry, callbacks, etc.

      Application must be instantiated/created lazily via a supplier/factory. This is required due to the way an application is usually initialized (constructor initializer).

      Working example:

      
       install("/subapp", SubApp::new);
      
       
      Lazy creation allows to configure and setup SubApp correctly, the next example won't work:
      
       SubApp app = new SubApp();
       install("/subapp", app); // WONT WORK
      
       
      Note: you must take care of application services across the applications. For example make sure you don't configure the same service twice or more in the main and imported applications too.
      Parameters:
      path - Path prefix.
      factory - Application factory.
      Returns:
      This application.
    • install

      @NonNull public Jooby install(@NonNull String path, @NonNull Predicate<Context> predicate, @NonNull SneakyThrows.Supplier<Jooby> factory)
      Installs/imports a full application into this one. Applications share services, registry, callbacks, etc.

      Application must be instantiated/created lazily via a supplier/factory. This is required due to the way an application is usually initialized (constructor initializer).

      Working example:

      
       install("/subapp", ctx -> ctx.header("v").value("").equals("1.0"), SubApp::new);
      
       
      Lazy creation allows to configure and setup SubApp correctly, the next example won't work:
      
       SubApp app = new SubApp();
       install("/subapp", ctx -> ctx.header("v").value("").equals("1.0"), app); // WONT WORK
      
       
      Note: you must take care of application services across the applications. For example make sure you don't configure the same service twice or more in the main and imported applications too.
      Parameters:
      path - Sub path.
      predicate - HTTP predicate.
      factory - Application factory.
      Returns:
      This application.
    • install

      @NonNull public Jooby install(@NonNull Predicate<Context> predicate, @NonNull SneakyThrows.Supplier<Jooby> factory)
      Installs/imports a full application into this one. Applications share services, registry, callbacks, etc.

      Application must be instantiated/created lazily via a supplier/factory. This is required due to the way an application is usually initialized (constructor initializer).

      Working example:

      
       install(ctx -> ctx.header("v").value("").equals("1.0"), SubApp::new);
      
       
      Lazy creation allows to configure and setup SubApp correctly, the next example won't work:
      
       SubApp app = new SubApp();
       install(ctx -> ctx.header("v").value("").equals("1.0"), app); // WONT WORK
      
       
      Note: you must take care of application services across the applications. For example make sure you don't configure the same service twice or more in the main and imported applications too.
      Parameters:
      predicate - HTTP predicate.
      factory - Application factory.
      Returns:
      This application.
    • getRouter

      @NonNull public Router getRouter()
      The underlying router.
      Returns:
      The underlying router.
    • isTrustProxy

      public boolean isTrustProxy()
      Description copied from interface: Router
      When true handles X-Forwarded-* headers by updating the values on the current context to match what was sent in the header(s).

      This should only be installed behind a reverse proxy that has been configured to send the 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:

      Specified by:
      isTrustProxy in interface Router
      Returns:
      True when enabled. Default is false.
    • isStarted

      public boolean isStarted()
      Specified by:
      isStarted in interface Router
    • isStopped

      public boolean isStopped()
      Specified by:
      isStopped in interface Router
    • setTrustProxy

      @NonNull public Jooby setTrustProxy(boolean trustProxy)
      Description copied from interface: Router
      When true handles X-Forwarded-* headers by updating the values on the current context to match what was sent in the header(s).

      This should only be installed behind a reverse proxy that has been configured to send the 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:

      Specified by:
      setTrustProxy in interface Router
      Parameters:
      trustProxy - True to enable.
      Returns:
      This router.
    • domain

      @NonNull public Router domain(@NonNull String domain, @NonNull Router subrouter)
      Description copied from interface: Router
      Enabled routes for specific domain. Domain matching is done using the 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.

      Specified by:
      domain in interface Router
      Parameters:
      domain - Predicate
      subrouter - Subrouter.
      Returns:
      This router.
    • domain

      @NonNull public RouteSet domain(@NonNull String domain, @NonNull Runnable body)
      Description copied from interface: Router
      Enabled routes for specific domain. Domain matching is done using the 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).
      Specified by:
      domain in interface Router
      Parameters:
      domain - Predicate
      body - Route action.
      Returns:
      This router.
    • mount

      @NonNull public RouteSet mount(@NonNull Predicate<Context> predicate, @NonNull Runnable body)
      Description copied from interface: Router
      Import routes from given action. Predicate works like a filter and only when predicate pass the routes match against the current request.

      Example of domain predicate filter:

      
       {
         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.

      Specified by:
      mount in interface Router
      Parameters:
      predicate - Context predicate.
      body - Route action.
      Returns:
      This router.
    • mount

      @NonNull public Jooby mount(@NonNull Predicate<Context> predicate, @NonNull Router subrouter)
      Description copied from interface: Router
      Import routes from given router. Predicate works like a filter and only when predicate pass the routes match against the current request.

      Example of domain predicate filter:

      
       {
         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.

      Specified by:
      mount in interface Router
      Parameters:
      predicate - Context predicate.
      subrouter - Router to import.
      Returns:
      This router.
    • mount

      @NonNull public Jooby mount(@NonNull String path, @NonNull Router router)
      Description copied from interface: Router
      Import all routes from the given router and prefix them with the given path.

      NOTE: ONLY routes are imported. Services, callback, etc.. are ignored.

      Specified by:
      mount in interface Router
      Parameters:
      path - Prefix path.
      router - Router to import.
      Returns:
      This router.
    • mount

      @NonNull public Jooby mount(@NonNull Router router)
      Description copied from interface: Router
      Import all routes from the given router.

      NOTE: ONLY routes are imported. Services, callback, etc.. are ignored.

      Specified by:
      mount in interface Router
      Parameters:
      router - Router to import.
      Returns:
      This router.
    • mvc

      @NonNull public Jooby mvc(@NonNull Object router)
      Description copied from interface: Router
      Import all route methods from given controller instance.
      Specified by:
      mvc in interface Router
      Parameters:
      router - Controller instance.
      Returns:
      This routes.
    • mvc

      @NonNull public Jooby mvc(@NonNull Class router)
      Description copied from interface: Router
      Import all route method from the given controller class. At runtime the controller instance is resolved by calling require(Class).
      Specified by:
      mvc in interface Router
      Parameters:
      router - Controller class.
      Returns:
      This router.
    • mvc

      @NonNull public <T> Jooby mvc(@NonNull Class<T> router, @NonNull jakarta.inject.Provider<T> provider)
      Description copied from interface: Router
      Import all route method from the given controller class.
      Specified by:
      mvc in interface Router
      Type Parameters:
      T - Controller type.
      Parameters:
      router - Controller class.
      provider - Controller provider.
      Returns:
      This router.
    • ws

      @NonNull public Route ws(@NonNull String pattern, @NonNull WebSocket.Initializer handler)
      Description copied from interface: Router
      Add a websocket handler.
      Specified by:
      ws in interface Router
      Parameters:
      pattern - WebSocket path pattern.
      handler - WebSocket handler.
      Returns:
      A new route.
    • sse

      @NonNull public Route sse(@NonNull String pattern, @NonNull ServerSentEmitter.Handler handler)
      Description copied from interface: Router
      Add a server-sent event handler.
      Specified by:
      sse in interface Router
      Parameters:
      pattern - Path pattern.
      handler - Handler.
      Returns:
      A new route.
    • getRoutes

      @NonNull public List<Route> getRoutes()
      Description copied from interface: Router
      Returns all routes.
      Specified by:
      getRoutes in interface Router
      Returns:
      All routes.
    • error

      @NonNull public Jooby error(@NonNull ErrorHandler handler)
      Description copied from interface: Router
      Add a custom error handler.
      Specified by:
      error in interface Router
      Parameters:
      handler - Error handler.
      Returns:
      This router.
    • use

      @NonNull public Router use(@NonNull Route.Filter filter)
      Description copied from interface: Router
      Attach a filter to the route pipeline.
      Specified by:
      use in interface Router
      Parameters:
      filter - Filter.
      Returns:
      This router.
    • before

      @NonNull public Jooby before(@NonNull Route.Before before)
      Description copied from interface: Router
      Add a before route decorator to the route pipeline.
      Specified by:
      before in interface Router
      Parameters:
      before - Before decorator.
      Returns:
      This router.
    • after

      @NonNull public Jooby after(@NonNull Route.After after)
      Description copied from interface: Router
      Add an after route decorator to the route pipeline.
      Specified by:
      after in interface Router
      Parameters:
      after - After decorator.
      Returns:
      This router.
    • encoder

      @NonNull public Jooby encoder(@NonNull MessageEncoder encoder)
      Description copied from interface: Router
      Register a route response encoder.
      Specified by:
      encoder in interface Router
      Parameters:
      encoder - MessageEncoder instance.
      Returns:
      This router.
    • decoder

      @NonNull public Jooby decoder(@NonNull MediaType contentType, @NonNull MessageDecoder decoder)
      Description copied from interface: Router
      Register a decoder for the given content type.
      Specified by:
      decoder in interface Router
      Parameters:
      contentType - Content type to match.
      decoder - MessageDecoder.
      Returns:
      This router.
    • encoder

      @NonNull public Jooby encoder(@NonNull MediaType contentType, @NonNull MessageEncoder encoder)
      Description copied from interface: Router
      Register a route response encoder.
      Specified by:
      encoder in interface Router
      Parameters:
      contentType - Accept header should match the content-type.
      encoder - MessageEncoder instance.
      Returns:
      This router.
    • install

      @NonNull public Jooby install(@NonNull Extension extension)
      Install extension module.
      Parameters:
      extension - Extension module.
      Returns:
      This application.
    • install

      @NonNull public Jooby install(@NonNull Server server)
      Set server to use.
      Parameters:
      server - Web Server.
      Returns:
      This application.
    • dispatch

      @NonNull public Jooby dispatch(@NonNull Runnable body)
      Description copied from interface: Router
      Dispatch route pipeline to the Router.getWorker() worker thread pool. After dispatch application code is allowed to do blocking calls.
      Specified by:
      dispatch in interface Router
      Parameters:
      body - Dispatch body.
      Returns:
      This router.
    • dispatch

      @NonNull public Jooby dispatch(@NonNull Executor executor, @NonNull Runnable action)
      Description copied from interface: Router
      Dispatch route pipeline to the given executor. After dispatch application code is allowed to do blocking calls.
      Specified by:
      dispatch in interface Router
      Parameters:
      executor - Executor. ExecutorService instances automatically shutdown at application exit.
      action - Dispatch body.
      Returns:
      This router.
    • path

      @NonNull public RouteSet path(@NonNull String pattern, @NonNull Runnable action)
      Description copied from interface: Router
      Group one or more routes under a common path prefix. Useful for applying cross-cutting concerns to the enclosed routes.
      Specified by:
      path in interface Router
      Parameters:
      pattern - Path pattern.
      action - Route body.
      Returns:
      All routes created.
    • routes

      @NonNull public RouteSet routes(@NonNull Runnable action)
      Description copied from interface: Router
      Group one or more routes. Useful for applying cross cutting concerns to the enclosed routes.
      Specified by:
      routes in interface Router
      Parameters:
      action - Route body.
      Returns:
      All routes created.
    • route

      @NonNull public Route route(@NonNull String method, @NonNull String pattern, @NonNull Route.Handler handler)
      Description copied from interface: Router
      Add a route.
      Specified by:
      route in interface Router
      Parameters:
      method - HTTP method.
      pattern - Path pattern.
      handler - Application code.
      Returns:
      A route.
    • match

      @NonNull public Router.Match match(@NonNull Context ctx)
      Description copied from interface: Router
      Find a matching route using the given context.

      If no match exists this method returns a route with a 404 handler. See Route.NOT_FOUND.

      Specified by:
      match in interface Router
      Parameters:
      ctx - Web Context.
      Returns:
      A route match result.
    • match

      public boolean match(@NonNull String pattern, @NonNull String path)
      Description copied from interface: Router
      Find a matching route using the given context.

      If no match exists this method returns a route with a 404 handler. See Route.NOT_FOUND.

      Specified by:
      match in interface Router
      Parameters:
      pattern - Method to match.
      path - Path to match.
      Returns:
      A route match result.
    • errorCode

      @NonNull public Jooby errorCode(@NonNull Class<? extends Throwable> type, @NonNull StatusCode statusCode)
      Description copied from interface: Router
      Map an exception type to a status code.
      Specified by:
      errorCode in interface Router
      Parameters:
      type - Exception type.
      statusCode - Status code.
      Returns:
      This router.
    • errorCode

      @NonNull public StatusCode errorCode(@NonNull Throwable cause)
      Description copied from interface: Router
      Computes the status code for the given exception.
      Specified by:
      errorCode in interface Router
      Parameters:
      cause - Exception.
      Returns:
      Status code.
    • getWorker

      @NonNull public Executor getWorker()
      Description copied from interface: Router
      Returns the worker thread pool. This thread pool is used to run application blocking code.
      Specified by:
      getWorker in interface Router
      Returns:
      Worker thread pool.
    • setWorker

      @NonNull public Jooby setWorker(@NonNull Executor worker)
      Description copied from interface: Router
      Set a worker thread pool. This thread pool is used to run application blocking code.
      Specified by:
      setWorker in interface Router
      Parameters:
      worker - Worker thread pool.
      Returns:
      This router.
    • setDefaultWorker

      @NonNull public Jooby setDefaultWorker(@NonNull Executor worker)
      Description copied from interface: Router
      Set the default worker thread pool. Via this method the underlying web server set/suggests the worker thread pool that should be used it.

      A call to Router.getWorker() returns the default thread pool, unless you explicitly set one.

      Specified by:
      setDefaultWorker in interface Router
      Parameters:
      worker - Default worker thread pool.
      Returns:
      This router.
    • getBufferFactory

      @NonNull public DataBufferFactory getBufferFactory()
      Specified by:
      getBufferFactory in interface Router
    • setBufferFactory

      @NonNull public Jooby setBufferFactory(@NonNull DataBufferFactory bufferFactory)
      Specified by:
      setBufferFactory in interface Router
    • getLog

      @NonNull public org.slf4j.Logger getLog()
      Description copied from interface: Router
      Application logger.
      Specified by:
      getLog in interface Router
      Returns:
      Application logger.
    • resultHandler

      @NonNull public Jooby resultHandler(ResultHandler handler)
      Description copied from interface: Router
      Add a response handler factory.
      Specified by:
      resultHandler in interface Router
      Parameters:
      handler - Response handler factory.
      Returns:
      This router.
    • getErrorHandler

      @NonNull public ErrorHandler getErrorHandler()
      Description copied from interface: Router
      Get the error handler.
      Specified by:
      getErrorHandler in interface Router
      Returns:
      An error handler.
    • getTmpdir

      @NonNull public Path getTmpdir()
      Description copied from interface: Router
      Application temporary directory. This method initialize the Environment when isn't set manually.
      Specified by:
      getTmpdir in interface Router
      Returns:
      Application temporary directory.
    • setTmpdir

      @NonNull public Jooby setTmpdir(@NonNull Path tmpdir)
      Set application temporary directory.
      Parameters:
      tmpdir - Temp directory.
      Returns:
      This application.
    • getExecutionMode

      @NonNull public ExecutionMode getExecutionMode()
      Application execution mode.
      Returns:
      Application execution mode.
    • setExecutionMode

      @NonNull public Jooby setExecutionMode(@NonNull ExecutionMode mode)
      Set application execution mode.
      Parameters:
      mode - Application execution mode.
      Returns:
      This application.
    • getAttributes

      @NonNull public Map<String,Object> getAttributes()
      Description copied from interface: Router
      Mutable map of application attributes.
      Specified by:
      getAttributes in interface Router
      Returns:
      Mutable map of application attributes.
    • attribute

      @NonNull public Jooby attribute(@NonNull String key, @NonNull Object value)
      Description copied from interface: Router
      Set an application attribute.
      Specified by:
      attribute in interface Router
      Parameters:
      key - Attribute key.
      value - Attribute value.
      Returns:
      This router.
    • attribute

      @NonNull public <T> T attribute(@NonNull String key)
      Description copied from interface: Router
      Get an attribute by his key. This is just a utility method around Router.getAttributes().
      Specified by:
      attribute in interface Router
      Type Parameters:
      T - Attribute type.
      Parameters:
      key - Attribute key.
      Returns:
      Attribute value.
    • require

      @NonNull public <T> T require(@NonNull Class<T> type, @NonNull String name)
      Description copied from interface: Registry
      Provides an instance of the given type where name matches it.
      Specified by:
      require in interface Registry
      Type Parameters:
      T - Object type.
      Parameters:
      type - Object type.
      name - Object name.
      Returns:
      Instance of this type.
    • require

      @NonNull public <T> T require(@NonNull Class<T> type)
      Description copied from interface: Registry
      Provides an instance of the given type.
      Specified by:
      require in interface Registry
      Type Parameters:
      T - Object type.
      Parameters:
      type - Object type.
      Returns:
      Instance of this type.
    • require

      @NonNull public <T> T require(@NonNull ServiceKey<T> key)
      Description copied from interface: Registry
      Provides an instance of the given type.
      Specified by:
      require in interface Registry
      Type Parameters:
      T - Object type.
      Parameters:
      key - Object key.
      Returns:
      Instance of this type.
    • registry

      @NonNull public Jooby registry(@NonNull Registry registry)
      Set application registry.
      Parameters:
      registry - Application registry.
      Returns:
      This application.
    • getServices

      @NonNull public ServiceRegistry getServices()
      Description copied from interface: Router
      Application service registry. Services are accessible via this registry or require(Class) calls.

      This method returns a mutable registry. You are free to modify/alter the registry.

      Specified by:
      getServices in interface Router
      Returns:
      Service registry.
    • getBasePackage

      @Nullable public String getBasePackage()
      Get base application package. This is the package from where application was initialized or the package of a Jooby application sub-class.
      Returns:
      Base application package.
    • setBasePackage

      @NonNull public Jooby setBasePackage(@Nullable String basePackage)
    • getSessionStore

      @NonNull public SessionStore getSessionStore()
      Description copied from interface: Router
      Session store. Default use a cookie ID with a memory storage.

      See SessionStore.memory().

      Specified by:
      getSessionStore in interface Router
      Returns:
      Session store.
    • setSessionStore

      @NonNull public Jooby setSessionStore(@NonNull SessionStore store)
      Description copied from interface: Router
      Set session store.
      Specified by:
      setSessionStore in interface Router
      Parameters:
      store - Session store.
      Returns:
      This router.
    • executor

      @NonNull public Jooby executor(@NonNull String name, @NonNull Executor executor)
      Description copied from interface: Router
      Put an executor into the application registry.
      Specified by:
      executor in interface Router
      Parameters:
      name - Executor's name.
      executor - Executor.
      Returns:
      This router.
    • getFlashCookie

      @NonNull public Cookie getFlashCookie()
      Description copied from interface: Router
      Template for the flash cookie. Default name is: jooby.flash.
      Specified by:
      getFlashCookie in interface Router
      Returns:
      Template for the flash cookie.
    • setFlashCookie

      @NonNull public Jooby setFlashCookie(@NonNull Cookie flashCookie)
      Description copied from interface: Router
      Sets a cookie used as a template to generate the flash cookie, allowing to customize the cookie name and other cookie parameters.
      Specified by:
      setFlashCookie in interface Router
      Parameters:
      flashCookie - The cookie template.
      Returns:
      This router.
    • converter

      @NonNull public Jooby converter(@NonNull ValueConverter converter)
      Description copied from interface: Router
      Add a custom string value converter.
      Specified by:
      converter in interface Router
      Parameters:
      converter - Custom value converter.
      Returns:
      This router.
    • getConverters

      @NonNull public List<ValueConverter> getConverters()
      Description copied from interface: Router
      Get all simple/string value converters.
      Specified by:
      getConverters in interface Router
      Returns:
      All simple/string value converters.
    • getBeanConverters

      @NonNull public List<BeanConverter> getBeanConverters()
      Description copied from interface: Router
      Get all complex/bean value converters.
      Specified by:
      getBeanConverters in interface Router
      Returns:
      All complex/bean value converters.
    • setHiddenMethod

      @NonNull public Jooby setHiddenMethod(@NonNull Function<Context,Optional<String>> provider)
      Description copied from interface: Router
      Provides a way to override the current HTTP method using lookup strategy.
      Specified by:
      setHiddenMethod in interface Router
      Parameters:
      provider - Lookup strategy.
      Returns:
      This router.
    • setCurrentUser

      @NonNull public Jooby setCurrentUser(@NonNull Function<Context,Object> provider)
      Description copied from interface: Router
      Provides a way to set the current user from a Context. Current user can be retrieve it using Context.getUser().
      Specified by:
      setCurrentUser in interface Router
      Parameters:
      provider - User provider/factory.
      Returns:
      This router.
    • setContextAsService

      @NonNull public Jooby setContextAsService(boolean contextAsService)
      Description copied from interface: Router
      If enabled, allows to retrieve the Context object associated with the current request via the service registry while the request is being processed.
      Specified by:
      setContextAsService in interface Router
      Parameters:
      contextAsService - whether to enable or disable this feature
      Returns:
      This router.
    • setHiddenMethod

      @NonNull public Jooby setHiddenMethod(@NonNull String parameterName)
      Description copied from interface: Router
      Provides a way to override the current HTTP method. Request must be:

      - POST Form/multipart request

      For alternative strategy use the Router.setHiddenMethod(Function) method.

      Specified by:
      setHiddenMethod in interface Router
      Parameters:
      parameterName - Form field name.
      Returns:
      This router.
    • getStartupSummary

      public List<StartupSummary> getStartupSummary()
      Controls the level of information logged during startup.
      Returns:
      Controls the level of information logged during startup.
    • setStartupSummary

      public Jooby setStartupSummary(List<StartupSummary> startupSummary)
      Controls the level of information logged during startup.
      Parameters:
      startupSummary - Summary.
      Returns:
      This instance.
    • start

      @NonNull public Server start()
      Start application, find a web server, deploy application, start router, extension modules, etc..
      Returns:
      Server.
    • start

      @NonNull public Jooby start(@NonNull Server server)
      Call back method that indicates application was deploy it in the given server.
      Parameters:
      server - Server.
      Returns:
      This application.
    • ready

      @NonNull public Jooby ready(@NonNull Server server)
      Callback method that indicates application was successfully started it and listening for connections.
      Parameters:
      server - Server.
      Returns:
      This application.
    • stop

      @NonNull public Jooby stop()
      Stop application, fire the stop event to cleanup resources.

      This method is usually invoked by 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();
       
      Returns:
      This application.
    • setLateInit

      public Jooby setLateInit(boolean lateInit)
      Force all module to be initialized lazily at application startup time (not at creation/instantiation time).

      This option is present mostly for unit-test where you need to instantiated a Jooby instance without running extensions.

      Parameters:
      lateInit - True for late init.
      Returns:
      This application.
    • getName

      @NonNull public String getName()
      Get application's name. If none set:

      - Try to get from Package.getImplementationTitle(). - Otherwise fallback to class name.

      Returns:
      Application's name.
    • setName

      @NonNull public Jooby setName(@NonNull String name)
      Set application name.
      Parameters:
      name - Application's name.
      Returns:
      This application.
    • getVersion

      @NonNull public String getVersion()
      Get application version (description/debugging purpose only). If none set:

      - Try to get it from Package.getImplementationVersion(). This attribute is present when application has been packaged (jar file).

      - Otherwise, fallback to 0.0.0.

      Returns:
      Application version.
    • setVersion

      @NonNull public Jooby setVersion(@NonNull String version)
      Set application version.
      Parameters:
      version - Application's version.
      Returns:
      This application.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • runApp

      public static void runApp(@NonNull String[] args, @NonNull Supplier<Jooby> provider)
      Setup default environment, logging (logback or log4j2) and run application.
      Parameters:
      args - Application arguments.
      provider - Application provider.
    • runApp

      public static void runApp(@NonNull String[] args, @NonNull Consumer<Jooby> consumer)
      Setup default environment, logging (logback or log4j2) and run application.
      Parameters:
      args - Application arguments.
      consumer - Application consumer.
    • runApp

      public static void runApp(@NonNull String[] args, @NonNull ExecutionMode executionMode, @NonNull Consumer<Jooby> consumer)
      Setup default environment, logging (logback or log4j2) and run application.
      Parameters:
      args - Application arguments.
      executionMode - Application execution mode.
      consumer - Application consumer.
    • runApp

      public static void runApp(@NonNull String[] args, @NonNull ExecutionMode executionMode, @NonNull Supplier<Jooby> provider)
      Setup default environment, logging (logback or log4j2) and run application.
      Parameters:
      args - Application arguments.
      executionMode - Application execution mode.
      provider - Application provider.
    • createApp

      public static Jooby createApp(@NonNull String[] args, @NonNull ExecutionMode executionMode, @NonNull Supplier<Jooby> provider)
      Setup default environment, logging (logback or log4j2) and run application.
      Parameters:
      args - Application arguments.
      executionMode - Application execution mode.
      provider - Application provider.
      Returns:
      Application.