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:
  • Constructor Details

    • WebComponentProvider

      public WebComponentProvider()
  • Method Details

    • canHandleRequest

      protected boolean canHandleRequest(VaadinRequest request)
      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 calling SynchronizedRequestHandler.synchronizedHandleRequest(VaadinSession, VaadinRequest, VaadinResponse) with the session locked.
      Overrides:
      canHandleRequest in class SynchronizedRequestHandler
      Parameters:
      request - the request to handle
      Returns:
      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.
    • synchronizedHandleRequest

      public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException
      Identical to SynchronizedRequestHandler.handleRequest(VaadinSession, VaadinRequest, VaadinResponse) except the VaadinSession is 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. Override handleWebComponentRequest(VaadinRequest, VaadinResponse) to customize how the script is served in both cases.

      Specified by:
      synchronizedHandleRequest in class SynchronizedRequestHandler
      Parameters:
      session - The session for the request
      request - The request to handle
      response - 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: SessionExpiredHandler
      Called 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 return true to indicate that no more SessionExpiredHandler handlers should be invoked for the request.
      Specified by:
      handleSessionExpired in interface SessionExpiredHandler
      Parameters:
      request - The request to handle
      response - 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

      public static boolean isWebComponentScriptRequest(VaadinRequest request)
      Checks whether the request asks for the script of an exported web component. Such a request does not need a session, see handleSessionExpired(VaadinRequest, VaadinResponse).
      Parameters:
      request - the request to check
      Returns:
      true if 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 on VaadinSession.getCurrent() or on the session lock.
      Parameters:
      request - the request to handle
      response - the response to write the script to
      Returns:
      true if the request was handled, false otherwise
      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 VaadinSession available. The result is cached per tag unless caching is disabled with setCacheEnabled(boolean).

      Parameters:
      tagName - tag name of component
      request - current VaadinRequest
      response - current VaadinResponse
      Returns:
      npm response script
      Since:
      2.2
    • bootstrapNpm

      protected String bootstrapNpm(boolean productionMode)