public class VaadinServlet
extends javax.servlet.http.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(javax.servlet.http.HttpServletRequest request)
Creates a Vaadin request for a http servlet request.
|
void |
destroy() |
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.
|
javax.servlet.ServletConfig |
getServletConfig() |
protected boolean |
handleContextOrServletRootWithoutSlash(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 |
serveStaticOrWebJarRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.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(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() |
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
public void init(javax.servlet.ServletConfig servletConfig) throws javax.servlet.ServletException
init
in interface javax.servlet.Servlet
init
in class javax.servlet.GenericServlet
servletConfig
- the object containing the servlet's configuration and
initialization parametersjavax.servlet.ServletException
- if an exception has occurred that interferes with the
servlet's normal operation.public javax.servlet.ServletConfig getServletConfig()
getServletConfig
in interface javax.servlet.Servlet
getServletConfig
in class javax.servlet.GenericServlet
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 javax.servlet.ServletException
javax.servlet.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 javax.servlet.ServletException
VaadinService
. Intended to be used by dependency injection
frameworks.javax.servlet.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 javax.servlet.ServletException, ServiceException
init(ServletConfig)
and
createServletService(DeploymentConfiguration)
so dependency
injection frameworks can call createDeploymentConfiguration()
when creating a vaadin servlet service lazily.javax.servlet.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(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
service
in class javax.servlet.http.HttpServlet
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.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.protected boolean serveStaticOrWebJarRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.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(javax.servlet.http.HttpServletRequest request, javax.servlet.http.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(javax.servlet.http.HttpServletRequest request)
request
- the original http servlet requestpublic VaadinServletService getService()
public void destroy()
destroy
in interface javax.servlet.Servlet
destroy
in class javax.servlet.GenericServlet
Copyright © 2021. All rights reserved.