Class WebComponentProvider

java.lang.Object
com.vaadin.flow.server.communication.WebComponentProvider
All Implemented Interfaces:
SessionlessRequestHandler, Serializable

public class WebComponentProvider extends Object implements SessionlessRequestHandler
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

    • handleRequest

      public boolean handleRequest(VaadinRequest request, VaadinResponse response) throws IOException
      Serves the script of an exported web component. The script is the same for every user, so it is served without a session. A host page that loads the scripts of several web components in parallel then does not get a new session from each of them, leaving the browser with a cookie for a session other than the one its embedded UI was created in.

      Override handleWebComponentRequest(VaadinRequest, VaadinResponse) to customize how the script is served.

      Specified by:
      handleRequest in interface SessionlessRequestHandler
      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
      Since:
      25.4
    • handleWebComponentRequest

      protected boolean handleWebComponentRequest(VaadinRequest request, VaadinResponse response) throws IOException
      Handles a request for a web component script. This is called without a session, 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, so this runs 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)