public class VaadinServlet
extends HttpServlet
This servlet is typically subclassed in all applications to provide servlet mappings and init parameters. Together with a web.xml file, it is also possible to use this class directly.
Internally sets up a VaadinService
through
createServletService(DeploymentConfiguration)
and delegates handling
of most requests to that.
Constructor and Description |
---|
VaadinServlet() |
Modifier and Type | Method and Description |
---|---|
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 StaticFileHandler |
createStaticFileHandler(VaadinServletService servletService)
Creates a new instance of
StaticFileHandler , that is responsible
to find and serve static resources. |
protected VaadinServletRequest |
createVaadinRequest(HttpServletRequest request)
Creates a Vaadin request for a http servlet request.
|
void |
destroy() |
protected URL |
getApplicationUrl(HttpServletRequest request)
Deprecated.
As of 1.0. Will be removed in 3.0.
|
static VaadinServlet |
getCurrent()
Gets the currently used Vaadin servlet.
|
protected static String |
getLastPathParameter(String uri)
Finds any path parameter added to the last part of the uri.
|
VaadinServletService |
getService()
Gets the Vaadin service for this servlet.
|
protected Optional<WebJarServer> |
getWebJarServer()
Gets the web jar server.
|
protected boolean |
handleContextOrServletRootWithoutSlash(HttpServletRequest request,
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(ServletConfig servletConfig)
Called by the servlet container to indicate to a servlet that the servlet
is being placed into service.
|
static String |
safeEscapeForHtml(String unsafe)
Deprecated.
As of 1.0. Will be removed in 3.0. Use
Entities.escape(String) instead. |
protected boolean |
serveStaticOrWebJarRequest(HttpServletRequest request,
HttpServletResponse response)
Handles a request by serving a static file from Webpack when in
npm-dev-mode, or from a WebJar when in bower-dev-mode or from the
file-system when in production.
|
protected void |
service(HttpServletRequest request,
HttpServletResponse response)
Receives standard HTTP requests from the public service method and
dispatches them.
|
protected void |
servletInitialized() |
public void init(ServletConfig servletConfig) throws ServletException
servletConfig
- the object containing the servlet's configuration and
initialization parametersServletException
- if an exception has occurred that interferes with the
servlet's normal operation.protected StaticFileHandler createStaticFileHandler(VaadinServletService servletService)
StaticFileHandler
, that is responsible
to find and serve static resources. By default it returns a
StaticFileServer
instance.servletService
- the servlet service created at createServletService()
null
protected void servletInitialized() throws ServletException
ServletException
public static VaadinServlet getCurrent()
ThreadLocal
) and in
VaadinSession.access(Command)
and UI.access(Command)
. 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()
null
protected DeploymentConfiguration createDeploymentConfiguration() throws ServletException
VaadinService
. Intended to be used by dependency injection
frameworks.ServletException
protected DeploymentConfiguration createDeploymentConfiguration(Properties initParameters)
VaadinService
. Override this if you want to override certain
properties.initParameters
- the context-param and init-param values as propertiesprotected VaadinServletService createServletService() throws ServletException, ServiceException
init(ServletConfig)
and
createServletService(DeploymentConfiguration)
so dependency
injection frameworks can call createDeploymentConfiguration()
when creating a vaadin servlet service lazily.ServletException
- if creating a deployment configuration failsServiceException
- if creating the vaadin servlet service failsprotected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException
deploymentConfiguration
- the deployment configuration to be usedServiceException
- if creating the vaadin servlet service failsprotected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
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.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.protected boolean serveStaticOrWebJarRequest(HttpServletRequest request, HttpServletResponse response) throws IOException
VaadinService
handlers because static requests
do not need a established session.request
- the HTTP servlet request object that contains the request the
client made of the servletresponse
- the HTTP servlet response object that contains the response
the servlet returns to the clienttrue
if the request was handled a response written;
otherwise false
IOException
- if an input or output error occurs while the servlet is
handling the HTTP requestprotected boolean handleContextOrServletRootWithoutSlash(HttpServletRequest request, HttpServletResponse response) throws IOException
request
- the processed requestresponse
- the processed responsetrue
if a redirect has been sent and the request
should not be processed further; false
if the
request should be processed as usualIOException
- If an input or output exception occursprotected static String getLastPathParameter(String uri)
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
uri
- a URIprotected VaadinServletRequest createVaadinRequest(HttpServletRequest request)
request
- the original http servlet requestpublic VaadinServletService getService()
@Deprecated protected URL getApplicationUrl(HttpServletRequest request) throws MalformedURLException
request
- the HTTP request.MalformedURLException
- if the application is denied access to the persistent data
store represented by the given URL.public void destroy()
@Deprecated public static String safeEscapeForHtml(String unsafe)
Entities.escape(String)
instead.unsafe
- non-escaped stringprotected Optional<WebJarServer> getWebJarServer()
Copyright © 2020. All rights reserved.