com.vaadin.server.
Class VaadinServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- com.vaadin.server.VaadinServlet
-
All Implemented Interfaces:
Constants
,Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
Direct Known Subclasses:
public class VaadinServlet extends javax.servlet.http.HttpServlet implements Constants
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
VaadinServlet.RequestType
Deprecated.
As of 7.0.
-
Field Summary
-
Fields inherited from interface com.vaadin.server.Constants
ATMOSPHERE_MISSING_ERROR, CANNOT_ACQUIRE_CLASSLOADER_SEVERE, DEFAULT_BUFFER_SIZE, DEFAULT_THEME_CACHETIME, DEFAULT_THEME_NAME, DEFAULT_WIDGETSET, ERROR_NO_UI_FOUND, INVALID_ATMOSPHERE_VERSION_WARNING, INVALID_SECURITY_KEY_MSG, MAX_BUFFER_SIZE, NOT_PRODUCTION_MODE_INFO, PARAMETER_VAADIN_RESOURCES, PARAMETER_WIDGETSET, PORTAL_PARAMETER_VAADIN_RESOURCE_PATH, PORTAL_PARAMETER_VAADIN_THEME, PORTAL_PARAMETER_VAADIN_WIDGETSET, PORTLET_CONTEXT, PUSH_NOT_SUPPORTED_ERROR, REQUIRED_ATMOSPHERE_RUNTIME_JAKARTA_VERSION, REQUIRED_ATMOSPHERE_RUNTIME_VERSION, SERVLET_PARAMETER_CLOSE_IDLE_SESSIONS, SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, SERVLET_PARAMETER_HEARTBEAT_INTERVAL, SERVLET_PARAMETER_LEGACY_DESIGN_PREFIX, SERVLET_PARAMETER_PRODUCTION_MODE, SERVLET_PARAMETER_PUSH_MODE, SERVLET_PARAMETER_PUSH_SUSPEND_TIMEOUT_LONGPOLLING, SERVLET_PARAMETER_RESOURCE_CACHE_TIME, SERVLET_PARAMETER_SENDURLSASPARAMETERS, SERVLET_PARAMETER_SYNC_ID_CHECK, SERVLET_PARAMETER_UI_PRIORITY, SERVLET_PARAMETER_UI_PROVIDER, THEME_DIR_PATH, URL_PARAMETER_THEME, WARNING_HEARTBEAT_INTERVAL_NOT_NUMERIC, WARNING_PUSH_MODE_NOT_RECOGNIZED, WARNING_RESOURCE_CACHING_TIME_NOT_NUMERIC, WARNING_XSRF_PROTECTION_DISABLED, WIDGETSET_DIR_PATH, WIDGETSET_MISMATCH_INFO
-
-
Constructor Summary
Constructors Constructor Description VaadinServlet()
-
Method Summary
All Methods Modifier and Type Method Description protected boolean
allowServePrecompressedResource(javax.servlet.http.HttpServletRequest request, String url)
Returns whether this servlet should attempt to serve a precompressed version of the given static resource.
protected DeploymentConfiguration
createDeploymentConfiguration()
Creates a deployment configuration to be used for the creation of a
VaadinService
.protected DeploymentConfiguration
createDeploymentConfiguration(Properties initParameters)
Creates a deployment configuration to be used for the creation of a
VaadinService
.protected VaadinServletService
createServletService()
Creates a vaadin servlet service.
protected VaadinServletService
createServletService(DeploymentConfiguration deploymentConfiguration)
Creates a vaadin servlet service.
protected VaadinServletRequest
createVaadinRequest(javax.servlet.http.HttpServletRequest request)
Creates a Vaadin request for a http servlet request.
protected void
criticalNotification(VaadinServletRequest request, VaadinServletResponse response, String caption, String message, String details, String url)
Deprecated.
As of 7.0.void
destroy()
URL
findResourceURL(String filename)
Finds the given resource from the web content folder or using the class loader.
protected URL
getApplicationUrl(javax.servlet.http.HttpServletRequest request)
Deprecated.
As of 7.0.protected int
getCacheTime(String filename)
Calculates the cache lifetime for the given filename in seconds.
static VaadinServlet
getCurrent()
Gets the currently used Vaadin servlet.
static String
getDefaultTheme()
Returns the default theme.
protected static String
getLastPathParameter(String uri)
Finds any path parameter added to the last part of the uri.
protected VaadinServlet.RequestType
getRequestType(VaadinServletRequest request)
Deprecated.
As of 7.0.protected static String
getResourcePath(javax.servlet.ServletContext servletContext, String path)
Deprecated.
As of 7.0.protected VaadinServletService
getService()
Gets a the vaadin service for this servlet.
protected String
getStaticFilePath(javax.servlet.http.HttpServletRequest request)
Returns the relative path at which static files are served for a request (if any).
protected boolean
handleContextRootWithoutSlash(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Invoked for every request to this servlet to potentially send a redirect to avoid problems with requests to the context root with no trailing slash.
void
init(javax.servlet.ServletConfig servletConfig)
Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
protected boolean
isAllowedVAADINResourceUrl(javax.servlet.http.HttpServletRequest request, URL resourceUrl)
Deprecated.
As of 7.0.protected boolean
isStaticResourceRequest(javax.servlet.http.HttpServletRequest request)
static String
safeEscapeForHtml(String unsafe)
Deprecated.
As of 7.0.protected boolean
serveStaticResources(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Check if this is a request for a static resource and, if it is, serve the resource to the client.
protected void
serveStaticResourcesInVAADIN(String filename, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Serve resources from VAADIN directory.
protected void
service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Receives standard HTTP requests from the public service method and dispatches them.
protected void
servletInitialized()
static String
stripSpecialChars(String themeName)
Deprecated.
As of 7.0.protected void
writeStaticResourceResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, URL resourceUrl)
Writes the contents of the given resourceUrl in the response.
-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
-
-
-
-
Method Detail
-
init
public void init(javax.servlet.ServletConfig servletConfig) throws javax.servlet.ServletException
Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
Specified by:
init
in interfacejavax.servlet.Servlet
Overrides:
init
in classjavax.servlet.GenericServlet
Parameters:
servletConfig
- the object containing the servlet's configuration and initialization parametersThrows:
javax.servlet.ServletException
- if an exception has occurred that interferes with the servlet's normal operation.
-
servletInitialized
protected void servletInitialized() throws javax.servlet.ServletException
Throws:
javax.servlet.ServletException
-
getCurrent
public static VaadinServlet getCurrent()
Gets the currently used Vaadin servlet. The current servlet is automatically defined when initializing the servlet and when processing requests to the server (see
ThreadLocal
) and inVaadinSession.access(Runnable)
andUI.access(Runnable)
. In other cases, (e.g. from background threads), the current servlet is not automatically defined.The current servlet is derived from the current service using
VaadinService.getCurrent()
Returns:
the current Vaadin servlet instance if available, otherwise
null
Since:
7.0
-
createDeploymentConfiguration
protected DeploymentConfiguration createDeploymentConfiguration() throws javax.servlet.ServletException
Creates a deployment configuration to be used for the creation of a
VaadinService
. Intended to be used by dependency injection frameworks.Returns:
the created deployment configuration
Throws:
javax.servlet.ServletException
- if construction of theProperties
forcreateDeploymentConfiguration(Properties)
failsSince:
8.2
-
createDeploymentConfiguration
protected DeploymentConfiguration createDeploymentConfiguration(Properties initParameters)
Creates a deployment configuration to be used for the creation of a
VaadinService
. Override this if you want to override certain properties.Parameters:
initParameters
- the context-param and init-param values as propertiesReturns:
the created deployment configuration
Since:
7.0.0
-
createServletService
protected VaadinServletService createServletService() throws javax.servlet.ServletException, ServiceException
Creates a vaadin servlet service. This method functions as a layer of indirection between
init(ServletConfig)
andcreateServletService(DeploymentConfiguration)
so dependency injection frameworks can callcreateDeploymentConfiguration()
when creating a vaadin servlet service lazily.Returns:
the created vaadin servlet service
Throws:
javax.servlet.ServletException
- if creating a deployment configuration failsServiceException
- if creating the vaadin servlet service failsSince:
8.2
-
createServletService
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException
Creates a vaadin servlet service.
Parameters:
deploymentConfiguration
- the deployment configuration to be usedReturns:
the created vaadin servlet service
Throws:
ServiceException
- if creating the vaadin servlet service failsSince:
7.0.0
-
service
protected void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
Receives standard HTTP requests from the public service method and dispatches them.
Overrides:
service
in classjavax.servlet.http.HttpServlet
Parameters:
request
- the object that contains the request the client made of the servlet.response
- the object that contains the response the servlet returns to the client.Throws:
javax.servlet.ServletException
- if an input or output error occurs while the servlet is handling the TRACE request.IOException
- if the request for the TRACE cannot be handled.
-
handleContextRootWithoutSlash
protected boolean handleContextRootWithoutSlash(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
Invoked for every request to this servlet to potentially send a redirect to avoid problems with requests to the context root with no trailing slash.
Parameters:
request
- the processed requestresponse
- the processed responseReturns:
true
if a redirect has been sent and the request should not be processed further;false
if the request should be processed as usualThrows:
IOException
- If an input or output exception occurs
-
getLastPathParameter
protected static String getLastPathParameter(String uri)
Finds any path parameter added to the last part of the uri. A path parameter is any string separated by ";" from the path and ends in / or at the end of the string.
For example the uri http://myhost.com/foo;a=1/bar;b=1 contains two path parameters, a=1 related to /foo and b=1 related to /bar.
For http://myhost.com/foo;a=1/bar;b=1 this method will return ;b=1
Parameters:
uri
- a URIReturns:
the last path parameter of the uri including the semicolon or an empty string. Never null.
Since:
7.2
-
createVaadinRequest
protected VaadinServletRequest createVaadinRequest(javax.servlet.http.HttpServletRequest request)
Creates a Vaadin request for a http servlet request. This method can be overridden if the Vaadin request should have special properties.
Parameters:
request
- the original http servlet requestReturns:
a Vaadin request for the original request
-
getService
protected VaadinServletService getService()
Gets a the vaadin service for this servlet.
Returns:
the vaadin service
-
criticalNotification
@Deprecated protected void criticalNotification(VaadinServletRequest request, VaadinServletResponse response, String caption, String message, String details, String url) throws IOException
Deprecated.As of 7.0. This method is retained only for backwards compatibility and for GAEVaadinServlet.Send a notification to client-side widgetset. Used to notify client of critical errors, session expiration and more. Server has no knowledge of what UI client refers to.
Parameters:
request
- the HTTP request instance.response
- the HTTP response to write to.caption
- the notification captionmessage
- to notification bodydetails
- a detail message to show in addition to the message. Currently shown directly below the message but could be hidden behind a details drop down in the future. Mainly used to give additional information not necessarily useful to the end user.url
- url to load when the message is dismissed. Null will reload the current page.Throws:
IOException
- if the writing failed due to input/output error.
-
getResourcePath
@Deprecated protected static String getResourcePath(javax.servlet.ServletContext servletContext, String path)
Deprecated.As of 7.0. Will likely change or be removed in a future versionGets resource path using different implementations. Required to supporting different servlet container implementations (application servers).
Parameters:
servletContext
- theServletContext
in which this servlet is runningpath
- the resource path.Returns:
the resource path.
-
stripSpecialChars
@Deprecated public static String stripSpecialChars(String themeName)
Deprecated.As of 7.0. Will likely change or be removed in a future versionA helper method to strip away characters that might somehow be used for XSS attacks. Leaves at least alphanumeric characters intact. Also removes e.g. '(' and ')', so values should be safe in javascript too.
Parameters:
themeName
- name of the themeReturns:
name of the theme without special characters
-
getDefaultTheme
public static String getDefaultTheme()
Returns the default theme. Must never return null.
Returns:
default theme name
-
serveStaticResources
protected boolean serveStaticResources(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
Check if this is a request for a static resource and, if it is, serve the resource to the client.
Parameters:
request
- The requestresponse
- The responseReturns:
true
if a file was served and the request has been handled;false
otherwise.Throws:
javax.servlet.ServletException
Since:
8.5
-
serveStaticResourcesInVAADIN
protected void serveStaticResourcesInVAADIN(String filename, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
Serve resources from VAADIN directory.
Parameters:
filename
- The filename to serve. Should always start with /VAADIN/.request
- The requestresponse
- The responseThrows:
IOException
- if an I/O exception occursjavax.servlet.ServletException
- if a servlet exception occursSince:
8.5
-
getCacheTime
protected int getCacheTime(String filename)
Calculates the cache lifetime for the given filename in seconds. By default filenames containing ".nocache." return 0, filenames containing ".cache." return one year, all other return the value defined in the web.xml using resourceCacheTime (defaults to 1 hour).
Parameters:
filename
- the filenameReturns:
cache lifetime for the given filename in seconds
-
writeStaticResourceResponse
protected void writeStaticResourceResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, URL resourceUrl) throws IOException
Writes the contents of the given resourceUrl in the response. Can be overridden to add/modify response headers and similar.
WARNING: note that this should not be used for a
resourceUrl
that represents a directory! For security reasons, the directory contents should not be ever written into theresponse
, and the implementation which is used for setting the content length relies onURLConnection.getContentLength()
method which returns incorrect values for directories.Parameters:
request
- The request for the resourceresponse
- The responseresourceUrl
- The url to sendThrows:
IOException
- if an I/O exception occurs
-
allowServePrecompressedResource
protected boolean allowServePrecompressedResource(javax.servlet.http.HttpServletRequest request, String url)
Returns whether this servlet should attempt to serve a precompressed version of the given static resource. If this method returns true, the suffix
.gz
is appended to the URL and the corresponding resource is served if it exists. It is assumed that the compression method used is gzip. If this method returns false or a compressed version is not found, the original URL is used. The base implementation of this method returns true if and only if the request indicates that the client accepts gzip compressed responses and the filename extension of the requested resource is .js, .css, or .html.Parameters:
request
- the request for the resourceurl
- the URL of the requested resourceReturns:
true if the servlet should attempt to serve a precompressed version of the resource, false otherwise
Since:
7.5.0
-
findResourceURL
public URL findResourceURL(String filename) throws IOException
Finds the given resource from the web content folder or using the class loader.
Parameters:
filename
- The file to find, starting with a "/"Returns:
The URL to the given file, or null if the file was not found
Throws:
IOException
- if there was a problem while locating the fileSince:
7.7
-
isAllowedVAADINResourceUrl
@Deprecated protected boolean isAllowedVAADINResourceUrl(javax.servlet.http.HttpServletRequest request, URL resourceUrl)
Deprecated.As of 7.0. Will likely change or be removed in a future versionCheck whether a URL obtained from a classloader refers to a valid static resource in the directory VAADIN. Directories do not count as valid resources. Warning: Overriding of this method is not recommended, but is possible to support non-default classloaders or servers that may produce URLs different from the normal ones. The method prototype may change in the future. Care should be taken not to expose class files or other resources outside the VAADIN directory if the method is overridden.
Parameters:
request
- current requestresourceUrl
- URL of the resource to validateReturns:
true
if the resource is a valid VAADIN resource,false
otherwiseSince:
6.6.7
-
getRequestType
@Deprecated protected VaadinServlet.RequestType getRequestType(VaadinServletRequest request)
Deprecated.As of 7.0. This is no longer used and only provided for backwards compatibility. EachRequestHandler
can individually decide whether it wants to handle a request or not.Parameters:
request
- the request that is to be evaluatedReturns:
request type
-
isStaticResourceRequest
protected boolean isStaticResourceRequest(javax.servlet.http.HttpServletRequest request)
-
getStaticFilePath
protected String getStaticFilePath(javax.servlet.http.HttpServletRequest request)
Returns the relative path at which static files are served for a request (if any).
NOTE: This method does not check whether the requested resource is a directory and as such not a valid VAADIN resource.
Parameters:
request
- HTTP requestReturns:
relative servlet path or null if the request path does not contain "/VAADIN/" or the request has no path info
Since:
8.0
-
getApplicationUrl
@Deprecated protected URL getApplicationUrl(javax.servlet.http.HttpServletRequest request) throws MalformedURLException
Deprecated.As of 7.0. Will likely change or be removed in a future versionGets the current application URL from request.
Parameters:
request
- the HTTP request.Returns:
current application URL
Throws:
MalformedURLException
- if the application is denied access to the persistent data store represented by the given URL.
-
destroy
public void destroy()
Specified by:
destroy
in interfacejavax.servlet.Servlet
Overrides:
destroy
in classjavax.servlet.GenericServlet
-
safeEscapeForHtml
@Deprecated public static final String safeEscapeForHtml(String unsafe)
Deprecated.As of 7.0. Will likely change or be removed in a future versionEscapes characters to html entities. An exception is made for some "safe characters" to keep the text somewhat readable.
Parameters:
unsafe
- the string that needs to be made safeReturns:
a safe string to be added inside an html tag
-
-