Package 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:
GAEVaadinServlet
,LegacyVaadinServlet
public class VaadinServlet extends javax.servlet.http.HttpServlet implements Constants
- See Also:
- Serialized Form
-
-
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_VERSION, SERVLET_PARAMETER_CLOSE_IDLE_SESSIONS, SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, SERVLET_PARAMETER_HEARTBEAT_INTERVAL, SERVLET_PARAMETER_LEGACY_DESIGN_PREFIX, SERVLET_PARAMETER_LEGACY_PROPERTY_TOSTRING, 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_PROVIDER, THEME_DIR_PATH, URL_PARAMETER_THEME, WARNING_HEARTBEAT_INTERVAL_NOT_NUMERIC, WARNING_LEGACY_PROPERTY_TOSTRING, WARNING_PUSH_MODE_NOT_RECOGNIZED, WARNING_RESOURCE_CACHING_TIME_NOT_NUMERIC, WARNING_UNKNOWN_LEGACY_PROPERTY_TOSTRING_VALUE, WARNING_XSRF_PROTECTION_DISABLED, WIDGETSET_DIR_PATH, WIDGETSET_MISMATCH_INFO
-
-
Constructor Summary
Constructors Constructor Description VaadinServlet()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated 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(Properties initParameters)
protected VaadinServletService
createServletService(DeploymentConfiguration deploymentConfiguration)
protected VaadinServletRequest
createVaadinRequest(javax.servlet.http.HttpServletRequest request)
Create 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()
protected 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 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 parameters- Throws:
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 and in threads started at a point when the current servlet is defined (seeInheritableThreadLocal
). In other cases, (e.g. from background threads started in some other way), 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(Properties initParameters)
-
createServletService
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException
- Throws:
ServiceException
-
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 response- Returns:
true
if a redirect has been sent and the request should not be processed further;false
if the request should be processed as usual- Throws:
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 URI- Returns:
- 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)
Create 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 request- Returns:
- 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 forGAEVaadinServlet
.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
-path
- 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
-- Returns:
-
getDefaultTheme
public static String getDefaultTheme()
Returns the default theme. Must never return null.- Returns:
-
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
-response
-- Returns:
- true if a file was served and the request has been handled, false otherwise.
- Throws:
IOException
javax.servlet.ServletException
- Since:
- 7.7.14
-
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
-response
-- Throws:
IOException
javax.servlet.ServletException
- Since:
- 7.7.14
-
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
-- Returns:
- 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.- Parameters:
request
- The request for the resourceresponse
- The responseresourceUrl
- The url to send- Throws:
IOException
-
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 resource- Returns:
- true if the servlet should attempt to serve a precompressed version of the resource, false otherwise
- Since:
- 7.5.0
-
findResourceURL
protected 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 file- Since:
- 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
-resourceUrl
-- Returns:
- Since:
- 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
-- Returns:
-
isStaticResourceRequest
protected boolean isStaticResourceRequest(javax.servlet.http.HttpServletRequest request)
-
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.- 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
-- Returns:
- a safe string to be added inside an html tag
-
-