Package com.vaadin.browserless
Class BrowserlessApplicationContext.Builder
java.lang.Object
com.vaadin.browserless.BrowserlessApplicationContext.Builder
- Enclosing class:
BrowserlessApplicationContext
Builder for creating a customized
BrowserlessApplicationContext.
Calling withSecurityContextHandler(SecurityContextHandler)
transitions to a SecuredBrowserlessApplicationContext.Builder
whose build() returns the credential-typed
SecuredBrowserlessApplicationContext.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the application context.withCloseHook(Runnable hook) Registers a hook to be invoked when the built application context is closed.withComponentTesterPackages(Class<?>... classes) Adds the packages of the given classes to the set of packages to scan forComponentTesterimplementations annotated withTests.withComponentTesterPackages(String... packages) Adds packages to scan forComponentTesterimplementations annotated withTests.withLookupServices(Class<?>... services) Adds the given Vaadin Lookup service classes to the set configured for this builder.withSecurityContextHandler(SecurityContextHandler<C> handler) Sets the security context handler for multi-user auth isolation and transitions to a credential-typedSecuredBrowserlessApplicationContext.Builder.withServletFactory(BiFunction<com.vaadin.browserless.internal.Routes, com.vaadin.browserless.internal.UIFactory, VaadinServlet> factory) Sets a custom servlet factory.withUIFactory(com.vaadin.browserless.internal.UIFactory uiFactory) Sets the UI factory used when creating UI instances for this application's windows.withViewPackages(Class<?>... classes) Adds the packages of the given classes to the set of packages to scan for@Route-annotated views.withViewPackages(String... packages) Adds packages to scan for@Route-annotated views.
-
Constructor Details
-
Builder
public Builder()Creates a builder with no pre-seeded routes. Routes are derived from the view packages configured on this builder (or from a full classpath scan when none are configured) atbuild()time.
-
-
Method Details
-
withViewPackages
Adds packages to scan for@Route-annotated views. Successive calls accumulate. Ignored when this builder was created with an explicitRoutesinstance.- Parameters:
packages- package names to scan- Returns:
- this builder
- Throws:
NullPointerException- ifpackagesor any element isnull
-
withViewPackages
Adds the packages of the given classes to the set of packages to scan for@Route-annotated views. Successive calls accumulate. Ignored when this builder was created with an explicitRoutesinstance.- Parameters:
classes- classes whose packages should be scanned- Returns:
- this builder
- Throws:
NullPointerException- ifclassesor any element isnull
-
withComponentTesterPackages
Adds packages to scan forComponentTesterimplementations annotated withTests. Successive calls accumulate. Each package is scanned at most once per JVM (seeTesterRegistry).- Parameters:
packages- package names to scan for testers- Returns:
- this builder
- Throws:
NullPointerException- ifpackagesor any element isnull
-
withComponentTesterPackages
Adds the packages of the given classes to the set of packages to scan forComponentTesterimplementations annotated withTests. Successive calls accumulate.- Parameters:
classes- classes whose packages should be scanned for testers- Returns:
- this builder
- Throws:
NullPointerException- ifclassesor any element isnull
-
withSecurityContextHandler
public <C> SecuredBrowserlessApplicationContext.Builder<C> withSecurityContextHandler(SecurityContextHandler<C> handler) Sets the security context handler for multi-user auth isolation and transitions to a credential-typedSecuredBrowserlessApplicationContext.Builder. The base builder's accumulated state (servlet factory, UI factory, lookup services, close hooks) is carried over.- Type Parameters:
C- the credentials type accepted by the handler- Parameters:
handler- the handler; must not benull- Returns:
- a secured builder configured with the given handler
- Throws:
NullPointerException- ifhandlerisnull
-
withServletFactory
public BrowserlessApplicationContext.Builder withServletFactory(BiFunction<com.vaadin.browserless.internal.Routes, com.vaadin.browserless.internal.UIFactory, VaadinServlet> factory) Sets a custom servlet factory. The factory receives the routes and theUIFactoryconfigured viawithUIFactory(UIFactory)(or its default), and must return a fully configuredVaadinServlet. Wiring theUIFactorythrough the builder ensures the servlet uses the same factory asBrowserlessUIContextwindow creation, so paths like the legacyafterSessionClosesession-recreation hook don't end up producing UIs of a different type. When unset, a default servlet that uses the configuredUIFactoryis created bybuild().- Parameters:
factory- the servlet factory- Returns:
- this builder
- Throws:
NullPointerException- iffactoryisnull
-
withUIFactory
public BrowserlessApplicationContext.Builder withUIFactory(com.vaadin.browserless.internal.UIFactory uiFactory) Sets the UI factory used when creating UI instances for this application's windows. Defaults to a factory producingMockedUIinstances.- Parameters:
uiFactory- the UI factory- Returns:
- this builder
- Throws:
NullPointerException- ifuiFactoryisnull
-
withLookupServices
Adds the given Vaadin Lookup service classes to the set configured for this builder. Successive calls accumulate; the builder starts with an empty set. Calling with no arguments is a no-op.- Parameters:
services- the service implementation classes to add- Returns:
- this builder
- Throws:
NullPointerException- ifservicesor any of its elements isnull
-
withCloseHook
Registers a hook to be invoked when the built application context is closed.Hooks run in registration order, after users and the Vaadin service have been torn down, exactly once (subsequent
close()calls are no-ops). They are intended for releasing framework-specific state attached during context creation — for example, Spring's lookup-initializer ThreadLocal. A throwing hook does not prevent the remaining hooks from running; any thrownRuntimeExceptions are collected and surfaced fromclose()as a singleRuntimeExceptionwith the originals attached as suppressed exceptions.- Parameters:
hook- the hook to register; must not benull- Returns:
- this builder
- Throws:
NullPointerException- ifhookisnull
-
build
Builds the application context.- Returns:
- a new application context
-