Class VaadinServletService

java.lang.Object
com.vaadin.flow.server.VaadinService
com.vaadin.flow.server.VaadinServletService
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
SpringVaadinServletService

public class VaadinServletService extends VaadinService
A service implementation connected to a VaadinServlet.
Since:
1.0
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • VaadinServletService

      public VaadinServletService(VaadinServlet servlet, DeploymentConfiguration deploymentConfiguration)
      Creates an instance connected to the given servlet and using the given configuration.
      Parameters:
      servlet - the servlet which receives requests
      deploymentConfiguration - the configuration to use
    • VaadinServletService

      protected VaadinServletService()
      Creates a servlet service. This method is for use by dependency injection frameworks etc. getServlet() and VaadinService.getContext() should be overridden (or otherwise intercepted) to not return null.
  • Method Details

    • createRequestHandlers

      protected List<RequestHandler> createRequestHandlers() throws ServiceException
      Description copied from class: VaadinService
      Called during initialization to add the request handlers for the service. Note that the returned list will be reversed so the last handler will be called first. This enables overriding this method and using add on the returned list to add a custom request handler which overrides any predefined handler.
      Overrides:
      createRequestHandlers in class VaadinService
      Returns:
      The list of request handlers used by this service.
      Throws:
      ServiceException - if a problem occurs when creating the request handlers
    • getServlet

      public VaadinServlet getServlet()
      Retrieves a reference to the servlet associated with this service. Should be overridden (or otherwise intercepted) if the no-arg constructor is used to prevent NPEs.
      Returns:
      A reference to the VaadinServlet this service is using
    • getMimeType

      public String getMimeType(String resourceName)
      Description copied from class: VaadinService
      Returns the MIME type of the specified file, or null if the MIME type is not known. The MIME type is determined by the configuration of the container, and may be specified in a deployment descriptor. Common MIME types are "text/html" and "image/gif".
      Specified by:
      getMimeType in class VaadinService
      Parameters:
      resourceName - a String specifying the name of a file
      Returns:
      a String specifying the file's MIME type
      See Also:
      • ServletContext.getMimeType(String)
    • requestCanCreateSession

      protected boolean requestCanCreateSession(VaadinRequest request)
      Description copied from class: VaadinService
      Checks whether it's valid to create a new service session as a result of the given request.
      Specified by:
      requestCanCreateSession in class VaadinService
      Parameters:
      request - the request
      Returns:
      true if it's valid to create a new service session for the request; else false
    • getCurrentServletRequest

      public static jakarta.servlet.http.HttpServletRequest getCurrentServletRequest()
    • getCurrentResponse

      public static VaadinServletResponse getCurrentResponse()
    • getServiceName

      public String getServiceName()
      Description copied from class: VaadinService
      Gets a unique name for this service. The name should be unique among different services of the same type but the same for corresponding instances running in different JVMs in a cluster. This is typically based on e.g. the configured servlet's name.
      Specified by:
      getServiceName in class VaadinService
      Returns:
      the unique name of this service instance.
    • getMainDivId

      public String getMainDivId(VaadinSession session, VaadinRequest request)
      Description copied from class: VaadinService
      Creates and returns a unique ID for the DIV where the UI is to be rendered.
      Specified by:
      getMainDivId in class VaadinService
      Parameters:
      session - The service session to which the bootstrapped UI will belong.
      request - The request for which a div id is needed
      Returns:
      the id to use in the DOM
    • getRouteRegistry

      protected RouteRegistry getRouteRegistry()
      Description copied from class: VaadinService
      Find a route registry to use for this service.
      Specified by:
      getRouteRegistry in class VaadinService
      Returns:
      the route registry to use, not null
    • getPwaRegistry

      protected PwaRegistry getPwaRegistry()
      Specified by:
      getPwaRegistry in class VaadinService
    • resolveResource

      public String resolveResource(String url)
      Description copied from class: VaadinService
      Resolves the given url resource to be useful for VaadinService.getResource(String) and VaadinService.getResourceAsStream(String).
      Specified by:
      resolveResource in class VaadinService
      Parameters:
      url - the resource to resolve, not null
      Returns:
      the resolved URL or the same as the input url if no translation was performed
    • getStaticResource

      public URL getStaticResource(String path)
      Description copied from class: VaadinService
      Returns a URL to the static resource at the given URI or null if no file found.
      Specified by:
      getStaticResource in class VaadinService
      Parameters:
      path - the URL for the resource
      Returns:
      the resource located at the named path, or null if there is no resource at that path
    • getResource

      public URL getResource(String path)
      Description copied from class: VaadinService
      Returns a URL to the resource at the given Vaadin URI.
      Specified by:
      getResource in class VaadinService
      Parameters:
      path - the untranslated Vaadin URL for the resource
      Returns:
      the resource located at the named path, or null if there is no resource at that path
    • getResourceAsStream

      public InputStream getResourceAsStream(String path)
      Description copied from class: VaadinService
      Opens a stream to to the resource at the given Vaadin URI.
      Specified by:
      getResourceAsStream in class VaadinService
      Parameters:
      path - the untranslated Vaadin URL for the resource
      Returns:
      a stream for the resource or null if no resource exists at the specified path
    • getResourceInServletContext

      public URL getResourceInServletContext(String path)
      Finds the given resource in the servlet context.
      Parameters:
      path - the path inside servlet context
      Returns:
      a URL for the resource or null if no resource was found
    • getContextRootRelativePath

      public String getContextRootRelativePath(VaadinRequest request)
      Description copied from class: VaadinService
      Returns relative context path for given request. Override this method in subclasses.
      Specified by:
      getContextRootRelativePath in class VaadinService
      Parameters:
      request - Request.
      Returns:
      Relative context root path for that request.
    • constructVaadinContext

      protected VaadinContext constructVaadinContext()
      Description copied from class: VaadinService
      Constructs VaadinContext for this service. This method will be called only once, upon first call to VaadinService.getContext().
      Specified by:
      constructVaadinContext in class VaadinService
      Returns:
      Context. This may never be null.
    • setDefaultClassLoader

      protected void setDefaultClassLoader()
      Description copied from class: VaadinService
      Tries to acquire default class loader and sets it as a class loader for this VaadinService if found. If current security policy disallows acquiring class loader instance it will log a message and re-throw SecurityException
      Overrides:
      setDefaultClassLoader in class VaadinService