Package com.vaadin.flow.server
Class BootstrapHandler
- java.lang.Object
-
- com.vaadin.flow.server.SynchronizedRequestHandler
-
- com.vaadin.flow.server.BootstrapHandler
-
- All Implemented Interfaces:
RequestHandler,Serializable
- Direct Known Subclasses:
JavaScriptBootstrapHandler,WebComponentBootstrapHandler
public class BootstrapHandler extends SynchronizedRequestHandler
Request handler which handles bootstrapping of the application, i.e. the initial GET request.- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classBootstrapHandler.BootstrapContextProvides context information for the bootstrap process.protected static classBootstrapHandler.BootstrapPageBuilderBuilds bootstrap pages.static classBootstrapHandler.BootstrapUriResolverThe URI resolver used in the bootstrap process.static interfaceBootstrapHandler.PageBuilderInterface for objects capable of building the bootstrap page.-
Nested classes/interfaces inherited from class com.vaadin.flow.server.SynchronizedRequestHandler
SynchronizedRequestHandler.ResponseWriter
-
-
Field Summary
Fields Modifier and Type Field Description static StringSERVICE_WORKER_HEADER-
Fields inherited from class com.vaadin.flow.server.SynchronizedRequestHandler
MAX_BUFFER_SIZE
-
-
Constructor Summary
Constructors Modifier Constructor Description BootstrapHandler()Creates an instance of the handler with defaultBootstrapHandler.PageBuilder.protectedBootstrapHandler(BootstrapHandler.PageBuilder pageBuilder)Creates an instance of the handler using provided page builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancanHandleRequest(VaadinRequest request)Check whether a request may be handled by this handler.protected BootstrapHandler.BootstrapContextcreateAndInitUI(Class<? extends UI> uiClass, VaadinRequest request, VaadinResponse response, VaadinSession session)protected BootstrapHandler.BootstrapContextcreateBootstrapContext(VaadinRequest request, VaadinResponse response, UI ui, Function<VaadinRequest,String> contextPathCallback)protected static elemental.json.JsonObjectgetInitialUidl(UI ui)Generates the initial UIDL message which is included in the initial bootstrap page.protected BootstrapHandler.PageBuildergetPageBuilder()Returns the current page builder object.protected static StringgetPushScript(BootstrapHandler.BootstrapContext context)protected static Class<? extends UI>getUIClass(VaadinRequest request)Returns the UI class mapped for servlet that handles the given request.protected voidinitializeUIWithRouter(BootstrapHandler.BootstrapContext context, UI ui)static booleanisFrameworkInternalRequest(VaadinRequest request)Checks whether the request is an internal request.protected booleanisRequestForHtml(VaadinRequest request)Checks if the request is potentially a request for an HTML page.static booleanisVaadinStaticFileRequest(VaadinRequest request)Checks whether the request is a request for /VAADIN/*.protected static StringreadResource(String fileName)protected static Optional<String>resolvePageTitle(BootstrapHandler.BootstrapContext context)Resolves the initial page title for the given bootstrap context and cancels any pending JS execution for it.protected static voidsetupErrorDialogs(org.jsoup.nodes.Element style)protected static voidsetupHiddenElement(org.jsoup.nodes.Element styles)protected voidsetupPushConnectionFactory(PushConfiguration pushConfiguration, BootstrapHandler.BootstrapContext context)protected static voidsetupPwa(org.jsoup.nodes.Document document, VaadinService service)protected static voidshowDevServerErrors(VaadinService service, org.jsoup.nodes.Document document)booleansynchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)Identical toSynchronizedRequestHandler.handleRequest(VaadinSession, VaadinRequest, VaadinResponse)except theVaadinSessionis locked before this is called and unlocked after this has completed.protected booleanwriteErrorCodeIfRequestLocationIsInvalid(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 Detail
-
SERVICE_WORKER_HEADER
public static final String SERVICE_WORKER_HEADER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BootstrapHandler
public BootstrapHandler()
Creates an instance of the handler with defaultBootstrapHandler.PageBuilder.
-
BootstrapHandler
protected BootstrapHandler(BootstrapHandler.PageBuilder pageBuilder)
Creates an instance of the handler using provided page builder.- Parameters:
pageBuilder- Page builder to use.
-
-
Method Detail
-
getPageBuilder
protected BootstrapHandler.PageBuilder getPageBuilder()
Returns the current page builder object.- Returns:
- Page builder in charge of constructing the resulting page.
-
canHandleRequest
protected boolean canHandleRequest(VaadinRequest request)
Description copied from class:SynchronizedRequestHandlerCheck 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 returnstruewhich means that all requests will be handled by callingSynchronizedRequestHandler.synchronizedHandleRequest(VaadinSession, VaadinRequest, VaadinResponse)with the session locked.- Overrides:
canHandleRequestin classSynchronizedRequestHandler- Parameters:
request- the request to handle- Returns:
trueif the request handling should continue once the session has been locked;falseif there's no need to lock the session since the request would still not be handled.
-
isFrameworkInternalRequest
public static boolean isFrameworkInternalRequest(VaadinRequest request)
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, javax.servlet.http.HttpServletRequest)instead.This is public only so that
IndexHtmlRequestHandlercan access it. If you are not IndexHtmlRequestHandler, go away.- Parameters:
request- the request- Returns:
trueif the request is Vaadin internal,falseotherwise
-
isVaadinStaticFileRequest
public static boolean isVaadinStaticFileRequest(VaadinRequest request)
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
IndexHtmlRequestHandlercan access it. If you are not IndexHtmlRequestHandler, go away.- Parameters:
request- the request- Returns:
trueif the request is for /VAADIN/*,falseotherwise
-
isRequestForHtml
protected boolean isRequestForHtml(VaadinRequest request)
Checks if the request is potentially a request for an HTML page.- Parameters:
request- the request to check- Returns:
trueif the request is potentially for HTML,falseif 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:SynchronizedRequestHandlerIdentical toSynchronizedRequestHandler.handleRequest(VaadinSession, VaadinRequest, VaadinResponse)except theVaadinSessionis locked before this is called and unlocked after this has completed.- Specified by:
synchronizedHandleRequestin 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 occurred- See Also:
SynchronizedRequestHandler.handleRequest(VaadinSession, VaadinRequest, VaadinResponse)
-
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 write- Returns:
trueif location was invalid and error code was written,falseif not (location was valid)- Throws:
IOException- in case writing to response fails
-
resolvePageTitle
protected static Optional<String> resolvePageTitle(BootstrapHandler.BootstrapContext context)
Resolves the initial page title for the given bootstrap context and cancels any pending JS execution for it.- Parameters:
context- the bootstrap context- Returns:
- the optional initial page title
-
createAndInitUI
protected BootstrapHandler.BootstrapContext createAndInitUI(Class<? extends UI> uiClass, VaadinRequest request, VaadinResponse response, VaadinSession session)
-
initializeUIWithRouter
protected void initializeUIWithRouter(BootstrapHandler.BootstrapContext context, UI ui)
-
createBootstrapContext
protected BootstrapHandler.BootstrapContext createBootstrapContext(VaadinRequest request, VaadinResponse response, UI ui, Function<VaadinRequest,String> contextPathCallback)
- Parameters:
request- the request objectresponse- the response objectui- the UI object- Returns:
- a new bootstrap context instance
-
setupPushConnectionFactory
protected void setupPushConnectionFactory(PushConfiguration pushConfiguration, BootstrapHandler.BootstrapContext context)
-
getUIClass
protected static Class<? extends UI> getUIClass(VaadinRequest request)
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 UI- Returns:
- the UI class for the request
-
getInitialUidl
protected static elemental.json.JsonObject getInitialUidl(UI ui)
Generates the initial UIDL message which is included in the initial bootstrap page.- Parameters:
ui- the UI for which the UIDL should be generated- Returns:
- a JSON object with the initial UIDL message
-
getPushScript
protected static String getPushScript(BootstrapHandler.BootstrapContext context)
-
showDevServerErrors
protected static void showDevServerErrors(VaadinService service, org.jsoup.nodes.Document document)
-
setupErrorDialogs
protected static void setupErrorDialogs(org.jsoup.nodes.Element style)
-
setupHiddenElement
protected static void setupHiddenElement(org.jsoup.nodes.Element styles)
-
setupPwa
protected static void setupPwa(org.jsoup.nodes.Document document, VaadinService service)
-
-