com.vaadin.flow.server.
Class BootstrapHandler
All Implemented Interfaces:
Direct Known Subclasses:
Request handler which handles bootstrapping of the application, i.e. the initial GET request.
Since:
1.0
Author:
Vaadin Ltd
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Provides context information for the bootstrap process.
protected static class
Builds bootstrap pages.
static class
The URI resolver used in the bootstrap process.
static interface
Interface for objects capable of building the bootstrap page.
Nested classes/interfaces inherited from class com.vaadin.flow.server.SynchronizedRequestHandler
SynchronizedRequestHandler.ResponseWriter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
protected static final String
static final String
Fields inherited from class com.vaadin.flow.server.SynchronizedRequestHandler
MAX_BUFFER_SIZE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates an instance of the handler with default
BootstrapHandler.PageBuilder
.protected
BootstrapHandler
(BootstrapHandler.PageBuilder pageBuilder) Creates an instance of the handler using provided page builder.
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
canHandleRequest
(VaadinRequest request) Check whether a request may be handled by this handler.
protected BootstrapHandler.BootstrapContext
createAndInitUI
(Class<? extends UI> uiClass, VaadinRequest request, VaadinResponse response, VaadinSession session) protected BootstrapHandler.BootstrapContext
createBootstrapContext
(VaadinRequest request, VaadinResponse response, UI ui, Function<VaadinRequest, String> contextPathCallback) Creates a new instance of
BootstrapHandler.BootstrapContext
for givenrequest
,response
andui
.protected static elemental.json.JsonObject
getInitialUidl
(UI ui) Generates the initial UIDL message which is included in the initial bootstrap page.
protected BootstrapHandler.PageBuilder
Returns the current page builder object.
protected static String
protected static elemental.json.JsonObject
getStatsJson
(DeploymentConfiguration config) protected static Collection<String>
getStylesheetLinks
(VaadinContext context, String fileName) Gives a links for referencing the custom theme stylesheet files (typically styles.css or document.css), which are served in express build mode by static file server directly from frontend/themes folder.
protected static Collection<org.jsoup.nodes.Element>
getStylesheetTags
(VaadinContext context, String fileName) Gives link tags for referencing the custom theme stylesheet files (typically styles.css or document.css), which are served in express build mode by static file server directly from frontend/themes folder.
getUIClass
(VaadinRequest request) Returns the UI class mapped for servlet that handles the given request.
protected void
initializeUIWithRouter
(BootstrapHandler.BootstrapContext context, UI ui) static boolean
isFrameworkInternalRequest
(VaadinRequest request) Checks whether the request is an internal request.
protected boolean
isRequestForHtml
(VaadinRequest request) Checks if the request is potentially a request for an HTML page.
static boolean
isVaadinStaticFileRequest
(VaadinRequest request) Checks whether the request is a request for /VAADIN/*.
protected static String
readResource
(String fileName) Resolves the initial page title for the given bootstrap context and cancels any pending JS execution for it.
protected static void
setupErrorDialogs
(org.jsoup.nodes.Element style) protected static void
setupHiddenElement
(org.jsoup.nodes.Element styles) protected void
setupPushConnectionFactory
(PushConfiguration pushConfiguration, BootstrapHandler.BootstrapContext context) protected static void
setupPwa
(org.jsoup.nodes.Document document, VaadinService service) boolean
synchronizedHandleRequest
(VaadinSession session, VaadinRequest request, VaadinResponse response) Identical to
SynchronizedRequestHandler.handleRequest(VaadinSession, VaadinRequest, VaadinResponse)
except theVaadinSession
is locked before this is called and unlocked after this has completed.protected boolean
writeErrorCodeIfRequestLocationIsInvalid
(VaadinRequest request, VaadinResponse response) Checks whether the request is for a valid location, and if not, writes the error code for the response.
Methods inherited from class com.vaadin.flow.server.SynchronizedRequestHandler
getRequestBody, handleRequest, isReadAndWriteOutsideSessionLock, synchronizedHandleRequest
-
Field Details
-
SERVICE_WORKER_HEADER
See Also:
-
SCRIPT_TEMPLATE_FOR_STYLESHEET_LINK_TAG
See Also:
-
SCRIPT_TAG
See Also:
-
-
Constructor Details
-
BootstrapHandler
public BootstrapHandler()Creates an instance of the handler with default
BootstrapHandler.PageBuilder
. -
BootstrapHandler
Creates an instance of the handler using provided page builder.
Parameters:
pageBuilder
- Page builder to use.
-
-
Method Details
-
getPageBuilder
Returns the current page builder object.
Returns:
Page builder in charge of constructing the resulting page.
-
canHandleRequest
Description copied from class:
SynchronizedRequestHandler
Check whether a request may be handled by this handler. This can be used as an optimization to avoid locking the session just to investigate some method property. The default implementation just returns
true
which means that all requests will be handled by callingSynchronizedRequestHandler.synchronizedHandleRequest(VaadinSession, VaadinRequest, VaadinResponse)
with the session locked.Overrides:
canHandleRequest
in classSynchronizedRequestHandler
Parameters:
request
- the request to handleReturns:
true
if the request handling should continue once the session has been locked;false
if there's no need to lock the session since the request would still not be handled. -
isFrameworkInternalRequest
Checks whether the request is an internal request.
Warning: This assumes that the VaadinRequest is targeted for a VaadinServlet and does no further checks to validate this. You want to use
HandlerHelper.isFrameworkInternalRequest(String, jakarta.servlet.http.HttpServletRequest)
instead.This is public only so that
IndexHtmlRequestHandler
can access it. If you are not IndexHtmlRequestHandler, go away.Parameters:
request
- the requestReturns:
true
if the request is Vaadin internal,false
otherwise -
isVaadinStaticFileRequest
Checks whether the request is a request for /VAADIN/*.
Warning: This assumes that the VaadinRequest is targeted for a VaadinServlet and does no further checks to validate this.
This is public only so that
IndexHtmlRequestHandler
can access it. If you are not IndexHtmlRequestHandler, go away.Parameters:
request
- the requestReturns:
true
if the request is for /VAADIN/*,false
otherwise -
isRequestForHtml
Checks if the request is potentially a request for an HTML page.
Parameters:
request
- the request to checkReturns:
true
if the request is potentially for HTML,false
if it is certain that it is a request for a script, image or something else -
synchronizedHandleRequest
public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException Description copied from class:
SynchronizedRequestHandler
Identical to
SynchronizedRequestHandler.handleRequest(VaadinSession, VaadinRequest, VaadinResponse)
except theVaadinSession
is locked before this is called and unlocked after this has completed.Specified by:
synchronizedHandleRequest
in classSynchronizedRequestHandler
Parameters:
session
- The session for the requestrequest
- The request to handleresponse
- The response object to which a response can be written.Returns:
true if a response has been written and no further request handlers should be called, otherwise false
Throws:
IOException
- If an IO error occurredSee Also:
-
writeErrorCodeIfRequestLocationIsInvalid
protected boolean writeErrorCodeIfRequestLocationIsInvalid(VaadinRequest request, VaadinResponse response) throws IOException Checks whether the request is for a valid location, and if not, writes the error code for the response.
Parameters:
request
- the request to checkresponse
- the response to writeReturns:
true
if location was invalid and error code was written,false
if not (location was valid)Throws:
IOException
- in case writing to response fails -
resolvePageTitle
Resolves the initial page title for the given bootstrap context and cancels any pending JS execution for it.
Parameters:
context
- the bootstrap contextReturns:
the optional initial page title
-
createAndInitUI
protected BootstrapHandler.BootstrapContext createAndInitUI(Class<? extends UI> uiClass, VaadinRequest request, VaadinResponse response, VaadinSession session) -
initializeUIWithRouter
-
createBootstrapContext
protected BootstrapHandler.BootstrapContext createBootstrapContext(VaadinRequest request, VaadinResponse response, UI ui, Function<VaadinRequest, String> contextPathCallback) Creates a new instance of
BootstrapHandler.BootstrapContext
for givenrequest
,response
andui
.Parameters:
request
- the request objectresponse
- the response objectui
- the UI objectReturns:
a new bootstrap context instance
-
setupPushConnectionFactory
protected void setupPushConnectionFactory(PushConfiguration pushConfiguration, BootstrapHandler.BootstrapContext context) -
getUIClass
Returns the UI class mapped for servlet that handles the given request.
This method is protected for testing purposes.
Parameters:
request
- the request for the UIReturns:
the UI class for the request
-
readResource
-
getInitialUidl
Generates the initial UIDL message which is included in the initial bootstrap page.
Parameters:
ui
- the UI for which the UIDL should be generatedReturns:
a JSON object with the initial UIDL message
-
getPushScript
-
setupErrorDialogs
protected static void setupErrorDialogs(org.jsoup.nodes.Element style) -
setupHiddenElement
protected static void setupHiddenElement(org.jsoup.nodes.Element styles) -
setupPwa
-
getStatsJson
protected static elemental.json.JsonObject getStatsJson(DeploymentConfiguration config) throws IOException Throws:
-
getStylesheetTags
protected static Collection<org.jsoup.nodes.Element> getStylesheetTags(VaadinContext context, String fileName) throws IOException Gives link tags for referencing the custom theme stylesheet files (typically styles.css or document.css), which are served in express build mode by static file server directly from frontend/themes folder.
Parameters:
context
- the vaadin contextfileName
- the stylesheet file name to add a reference toReturns:
the collection of link tags to be added to the page
Throws:
IOException
- if theme name cannot be extracted from file -
getStylesheetLinks
Gives a links for referencing the custom theme stylesheet files (typically styles.css or document.css), which are served in express build mode by static file server directly from frontend/themes folder.
Parameters:
context
- the vaadin contextfileName
- the stylesheet file name to add a reference toReturns:
the collection of links to be added to the page
-