Package com.vaadin.flow.server
Class VaadinServletService
- java.lang.Object
-
- com.vaadin.flow.server.VaadinService
-
- com.vaadin.flow.server.VaadinServletService
-
- All Implemented Interfaces:
Serializable
public class VaadinServletService extends VaadinService
A service implementation connected to aVaadinServlet
.- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.vaadin.flow.server.VaadinService
ATMOSPHERE_MISSING_ERROR, INVALID_ATMOSPHERE_VERSION_WARNING
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
VaadinServletService()
Creates a servlet service.VaadinServletService(VaadinServlet servlet, DeploymentConfiguration deploymentConfiguration)
Creates an instance connected to the given servlet and using the given configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected VaadinContext
constructVaadinContext()
ConstructsVaadinContext
for this service.protected List<RequestHandler>
createRequestHandlers()
Called during initialization to add the request handlers for the service.String
getContextRootRelativePath(VaadinRequest request)
Returns relative context path for given request.static VaadinServletResponse
getCurrentResponse()
static javax.servlet.http.HttpServletRequest
getCurrentServletRequest()
String
getMainDivId(VaadinSession session, VaadinRequest request)
Creates and returns a unique ID for the DIV where the UI is to be rendered.String
getMimeType(String resourceName)
Returns the MIME type of the specified file, or null if the MIME type is not known.protected PwaRegistry
getPwaRegistry()
URL
getResource(String path)
Returns a URL to the resource at the given Vaadin URI.InputStream
getResourceAsStream(String path)
Opens a stream to to the resource at the given Vaadin URI.URL
getResourceInServletContext(String path)
Finds the given resource in the servlet context.protected RouteRegistry
getRouteRegistry()
Find a route registry to use for this service.String
getServiceName()
Gets a unique name for this service.VaadinServlet
getServlet()
Retrieves a reference to the servlet associated with this service.URL
getStaticResource(String path)
Returns a URL to the static resource at the given URI or null if no file found.void
init()
Initializes this service.protected boolean
requestCanCreateSession(VaadinRequest request)
Checks whether it's valid to create a new service session as a result of the given request.String
resolveResource(String url)
Resolves the givenurl
resource to be useful forVaadinService.getResource(String)
andVaadinService.getResourceAsStream(String )
.protected void
setDefaultClassLoader()
Tries to acquire default class loader and sets it as a class loader for thisVaadinService
if found.-
Methods inherited from class com.vaadin.flow.server.VaadinService
accessSession, addServiceDestroyListener, addSessionDestroyListener, addSessionInitListener, addUIInitListener, closeSession, createCriticalNotificationJSON, createCriticalNotificationJSON, createInstantiator, createSessionExpiredJSON, createUINotFoundJSON, createVaadinSession, destroy, ensureAccessQueuePurged, ensurePushAvailable, findUI, findVaadinSession, fireSessionDestroy, fireUIInitListeners, getBootstrapInitialPredicate, getBootstrapUrlPredicate, getClassLoader, getContext, getCsrfTokenAttributeName, getCurrent, getCurrentRequest, getDependencyFilters, getDeploymentConfiguration, getExistingSession, getInstantiator, getRequestHandlers, getRouter, getSessionAttributeName, getSessionLock, getSystemMessages, getSystemMessagesProvider, handleRequest, handleSessionExpired, isAtmosphereAvailable, isCsrfTokenValid, isOtherSessionLocked, isResourceAvailable, isUIActive, loadInstantiators, loadSession, lockSession, modifyBootstrapPage, modifyIndexHtmlResponse, readFromHttpSession, reinitializeSession, removeFromHttpSession, removeSession, requestEnd, requestStart, runPendingAccessTasks, setBootstrapInitialPredicate, setBootstrapUrlPredicate, setClassLoader, setCurrent, setCurrentInstances, setSystemMessagesProvider, storeSession, unlockSession, verifyNoOtherSessionLocked, writeStringResponse, writeToHttpSession, writeUncachedStringResponse
-
-
-
-
Constructor Detail
-
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 requestsdeploymentConfiguration
- the configuration to use
-
VaadinServletService
protected VaadinServletService()
Creates a servlet service. This method is for use by dependency injection frameworks etc.getServlet()
andVaadinService.getContext()
should be overridden (or otherwise intercepted) to not returnnull
.
-
-
Method Detail
-
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 classVaadinService
- 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 classVaadinService
- 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 classVaadinService
- Parameters:
request
- the request- Returns:
true
if it's valid to create a new service session for the request; elsefalse
-
init
public void init() throws ServiceException
Description copied from class:VaadinService
Initializes this service. The service should be initialized before it is used.- Overrides:
init
in classVaadinService
- Throws:
ServiceException
- if a problem occurs when creating the service
-
getCurrentServletRequest
public static javax.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 classVaadinService
- 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 classVaadinService
- 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 classVaadinService
- Returns:
- the route registry to use, not
null
-
getPwaRegistry
protected PwaRegistry getPwaRegistry()
- Specified by:
getPwaRegistry
in classVaadinService
-
resolveResource
public String resolveResource(String url)
Description copied from class:VaadinService
Resolves the givenurl
resource to be useful forVaadinService.getResource(String)
andVaadinService.getResourceAsStream(String )
.- Specified by:
resolveResource
in classVaadinService
- Parameters:
url
- the resource to resolve, notnull
- 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 classVaadinService
- 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 classVaadinService
- 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 classVaadinService
- 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 classVaadinService
- Parameters:
request
- Request.- Returns:
- Relative context root path for that request.
-
constructVaadinContext
protected VaadinContext constructVaadinContext()
Description copied from class:VaadinService
ConstructsVaadinContext
for this service. This method will be called only once, upon first call toVaadinService.getContext()
.- Specified by:
constructVaadinContext
in classVaadinService
- 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 thisVaadinService
if found. If current security policy disallows acquiring class loader instance it will log a message and re-throwSecurityException
- Overrides:
setDefaultClassLoader
in classVaadinService
-
-