com.vaadin.flow.server.
Class VaadinServletService
- java.lang.Object
-
- com.vaadin.flow.server.VaadinService
-
- com.vaadin.flow.server.VaadinServletService
-
All Implemented Interfaces:
public class VaadinServletService extends VaadinService
A service implementation connected to a
VaadinServlet
.Since:
1.0
Author:
Vaadin Ltd
See Also:
-
-
Field Summary
-
Fields inherited from class com.vaadin.flow.server.VaadinService
ATMOSPHERE_MISSING_ERROR, CANNOT_ACQUIRE_CLASSLOADER_SEVERE, INVALID_ATMOSPHERE_VERSION_WARNING, URL_PARAMETER_CLOSE_APPLICATION, URL_PARAMETER_RESTART_APPLICATION
-
-
Constructor Summary
Constructors Modifier Constructor and 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 Modifier and Type Method and Description protected VaadinContext
constructVaadinContext()
Constructs
VaadinContext
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 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, WebBrowser browser, AbstractTheme theme)
Returns a URL to the resource at the given Vaadin URI.
InputStream
getResourceAsStream(String path, WebBrowser browser, AbstractTheme theme)
Opens a stream to to the resource at the given Vaadin URI.
URL
getResourceInServletContextOrWebJar(String path)
Finds the given resource in the servlet context or in a webjar.
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.
Optional<String>
getThemedUrl(String url, WebBrowser browser, AbstractTheme theme)
Checks if the given URL has a themed version.
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, WebBrowser browser)
Resolves the given
url
resource to be useful forVaadinService.getResource(String, WebBrowser, AbstractTheme)
andVaadinService.getResourceAsStream(String, WebBrowser, AbstractTheme)
.-
Methods inherited from class com.vaadin.flow.server.VaadinService
accessSession, addServiceDestroyListener, addSessionDestroyListener, addSessionInitListener, addUIInitListener, closeSession, createCriticalNotificationJSON, createInstantiator, createSessionExpiredJSON, createUINotFoundJSON, createVaadinSession, destroy, ensureAccessQueuePurged, ensurePushAvailable, findUI, findVaadinSession, fireSessionDestroy, fireUIInitListeners, getClassLoader, getContext, getCurrent, getCurrentRequest, getDependencyFilters, getDeploymentConfiguration, getExistingSession, getHtmlImportDependencyCache, getInstantiator, getRequestHandlers, getRouter, getSessionAttributeName, getSessionLock, getSystemMessages, getSystemMessagesProvider, handleRequest, handleSessionExpired, isAtmosphereAvailable, isCsrfTokenValid, isOtherSessionLocked, isResourceAvailable, isUIActive, loadInstantiators, loadSession, lockSession, modifyBootstrapPage, readFromHttpSession, reinitializeSession, removeFromHttpSession, removeSession, requestEnd, requestStart, runPendingAccessTasks, setClassLoader, setCurrent, setCurrentInstances, setDefaultClassLoader, 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 fileReturns:
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 requestReturns:
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 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 neededReturns:
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, WebBrowser browser)
Description copied from class:
VaadinService
Resolves the given
url
resource to be useful forVaadinService.getResource(String, WebBrowser, AbstractTheme)
andVaadinService.getResourceAsStream(String, WebBrowser, AbstractTheme)
.Specified by:
resolveResource
in classVaadinService
Parameters:
url
- the resource to resolve, notnull
browser
- the web browser to resolve for, relevant for es5 vs es6 resolvingReturns:
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 resourceReturns:
the resource located at the named path, or
null
if there is no resource at that path
-
getResource
public URL getResource(String path, WebBrowser browser, AbstractTheme theme)
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 resourcebrowser
- the web browser to resolve for, relevant for es5 vs es6 resolvingtheme
- the theme to use for translating the URL ornull
if no theme is usedReturns:
the resource located at the named path, or
null
if there is no resource at that path
-
getResourceAsStream
public InputStream getResourceAsStream(String path, WebBrowser browser, AbstractTheme theme)
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 resourcebrowser
- the web browser to resolve for, relevant for es5 vs es6 resolvingtheme
- the theme to use for translating the URL ornull
if no theme is usedReturns:
a stream for the resource or
null
if no resource exists at the specified path
-
getThemedUrl
public Optional<String> getThemedUrl(String url, WebBrowser browser, AbstractTheme theme)
Description copied from class:
VaadinService
Checks if the given URL has a themed version. If it does, returns the untranslated URL for the themed resource.
Specified by:
getThemedUrl
in classVaadinService
Parameters:
url
- the URL to lookupbrowser
- the browser to use for lookuptheme
- the theme to checkReturns:
an optional containing the untranslated (containing vaadin protocols) URL to the themed resource if such exists, an empty optional if the given resource has no themed version
-
getResourceInServletContextOrWebJar
public URL getResourceInServletContextOrWebJar(String path)
Finds the given resource in the servlet context or in a webjar.
Parameters:
path
- the path inside servlet context, automatically translated as needed for webjarsReturns:
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
Constructs
VaadinContext
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
.
-
-