Class WebComponentProvider
java.lang.Object
com.vaadin.flow.server.SynchronizedRequestHandler
com.vaadin.flow.server.communication.WebComponentProvider
- All Implemented Interfaces:
RequestHandler,SessionExpiredHandler,Serializable
public class WebComponentProvider
extends SynchronizedRequestHandler
implements SessionExpiredHandler
Request handler that supplies the script/html of the web component matching
the given tag.
For internal use only. May be renamed or removed in a future release.
- Since:
- 2.0
- Author:
- Vaadin Ltd.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.server.SynchronizedRequestHandler
SynchronizedRequestHandler.ResponseWriter -
Field Summary
Fields inherited from class com.vaadin.flow.server.SynchronizedRequestHandler
MAX_BUFFER_SIZE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringbootstrapNpm(boolean productionMode) protected booleancanHandleRequest(VaadinRequest request) Check whether a request may be handled by this handler.protected StringgenerateNPMResponse(String tagName, VaadinRequest request, VaadinResponse response) Generate the npm response for the web component.booleanhandleSessionExpired(VaadinRequest request, VaadinResponse response) Called when the a session expiration has occurred and a notification needs to be sent to the user.protected booleanhandleWebComponentRequest(VaadinRequest request, VaadinResponse response) Handles a request for a web component script.booleanWhether bootstrap HTML fragment are cached based on component tag.static booleanisWebComponentScriptRequest(VaadinRequest request) Checks whether the request asks for the script of an exported web component.voidsetCacheEnabled(boolean cacheEnabled) Enable / disable bootstrap HTML fragment caching based on component tag.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.Methods inherited from class com.vaadin.flow.server.SynchronizedRequestHandler
getMaxRequestBodySize, getRequestBody, getRequestBody, handleRequest, isReadAndWriteOutsideSessionLock, synchronizedHandleRequestMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.server.RequestHandler
handleRequest
-
Constructor Details
-
WebComponentProvider
public WebComponentProvider()
-
-
Method Details
-
canHandleRequest
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.
-
synchronizedHandleRequest
public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException Identical toSynchronizedRequestHandler.handleRequest(VaadinSession, VaadinRequest, VaadinResponse)except theVaadinSessionis locked before this is called and unlocked after this has completed.This is only called when the request has a session. A web component script request without a session is served through
handleSessionExpired(VaadinRequest, VaadinResponse)instead. OverridehandleWebComponentRequest(VaadinRequest, VaadinResponse)to customize how the script is served in both cases.- 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:
-
handleSessionExpired
public boolean handleSessionExpired(VaadinRequest request, VaadinResponse response) throws IOException Description copied from interface:SessionExpiredHandlerCalled when the a session expiration has occurred and a notification needs to be sent to the user. If a response is written, this method should returntrueto indicate that no moreSessionExpiredHandlerhandlers should be invoked for the request.- Specified by:
handleSessionExpiredin interfaceSessionExpiredHandler- Parameters:
request- 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
-
isWebComponentScriptRequest
Checks whether the request asks for the script of an exported web component. Such a request does not need a session, seehandleSessionExpired(VaadinRequest, VaadinResponse).- Parameters:
request- the request to check- Returns:
trueif the request is for a web component script- Since:
- 25.4
-
handleWebComponentRequest
protected boolean handleWebComponentRequest(VaadinRequest request, VaadinResponse response) throws IOException Handles a request for a web component script. This is called both for requests that have a session and for requests that do not, so it must not depend onVaadinSession.getCurrent()or on the session lock.- Parameters:
request- the request to handleresponse- the response to write the script to- Returns:
trueif the request was handled,falseotherwise- Throws:
IOException- if writing the response fails- Since:
- 25.4
-
isCacheEnabled
public boolean isCacheEnabled()Whether bootstrap HTML fragment are cached based on component tag. Enabled by default.- Returns:
- true iff bootstrap fragment caching is enabled
- Since:
- 2.2
-
setCacheEnabled
public void setCacheEnabled(boolean cacheEnabled) Enable / disable bootstrap HTML fragment caching based on component tag. Calling this method has the side effect of always clearing the cache.- Parameters:
cacheEnabled- whether bootstrap fragments should be cached per tag- Since:
- 2.2
-
generateNPMResponse
protected String generateNPMResponse(String tagName, VaadinRequest request, VaadinResponse response) Generate the npm response for the web component.The script is served without a session when the request has none, so this may run with no
VaadinSessionavailable. The result is cached per tag unless caching is disabled withsetCacheEnabled(boolean).- Parameters:
tagName- tag name of componentrequest- current VaadinRequestresponse- current VaadinResponse- Returns:
- npm response script
- Since:
- 2.2
-
bootstrapNpm
-