Class SpringVaadinServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- com.vaadin.server.VaadinServlet
-
- org.dellroad.stuff.vaadin7.SpringVaadinServlet
-
- All Implemented Interfaces:
Constants,Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
public class SpringVaadinServlet extends VaadinServlet
AVaadinServletthat associates and manages a SpringConfigurableWebApplicationContextwith eachVaadinSession(aka, "Vaadin application" in the old terminology).The
configLocationservlet parameter may be used to specify the Spring XML config file location(s). For example:<servlet> <servlet-name>My Vaadin App</servlet-name> <servlet-class>org.dellroad.stuff.vaadin7.SpringVaadinServlet</servlet-class> <init-param> <param-name>UI</param-name> <param-value>com.example.MyApplicationUI</param-value> </init-param> <init-param> <param-name>configLocation</param-name> <param-value>classpath:com/example/MyApplicationContext.xml</param-value> </init-param> </servlet>The main function of this servlet is to create and register a
SpringVaadinSessionListeneras a listener on theVaadinServiceassociated with this servlet. TheSpringVaadinSessionListenerin turn detects the creation and destruction of Vaadin application instances (represented byVaadinSessioninstances) and does the work of managing the associated Spring application contexts.Use of this servlet in place of the standard Vaadin servlet is required for the
@VaadinConfigurableannotation to work.Supported servlet parameters:
Parameter Name Required? Description applicationNameNo Vaadin application name. Used for logging purposes and as the name of the XML application context file when configLocationis not specified. If this parameter is not specified, the name of the servlet is used.configLocationNo Location of Spring application context XML file(s). Multiple locations are separated by whitespace. If omitted, /WEB-INF/ServletName.xmlis used, whereServletNameis the name of the Vaadin application (seeapplicationName).listenerClassNo Specify the name of a custom class extending SpringVaadinSessionListenerand having the same constructor arguments. If omitted,SpringVaadinSessionListeneris used.sessionTrackingNo Boolean value that configures whether the SpringVaadinSessionListenershould track Vaadin sessions; defaultfalse. If set totrue, thengetSessions()can be used to access all active sessions. Session tracking should not be used unless sessions are normally kept in memory; e.g., don't use session tracking when sessions are being serialized and persisted. See alsoVaadinSessionContainer.maxSessionsNo Configures a limit on the number of simultaneous Vaadin sessions that may exist at one time. Going over this limit will result in a ServiceExceptionbeing thrown. A zero or negative number means there is no limit (this is the default). Ignored unless "sessionTracking" is set totrue.Note: if any beans are declared
scope="session"in your application context, you must register Spring'sRequestContextListeneras a listener in yourweb.xml(normally, Spring'sDispatcherServletwould handle this task).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.server.VaadinServlet
VaadinServlet.RequestType
-
-
Field Summary
Fields Modifier and Type Field Description static StringAPPLICATION_NAME_PARAMETERServlet initialization parameter ("applicationName") used to specify the name the application.static StringCONFIG_LOCATION_PARAMETERServlet initialization parameter ("configLocation") used to specify the location(s) of the Spring application context XML file(s).static StringLISTENER_CLASS_PARAMETERServlet initialization parameter ("listenerClass") used to specify the name of an custom subclass ofSpringVaadinSessionListener.static StringMAX_SESSIONS_PARAMETERServlet initialization parameter ("maxSessions") that configures the maximum number of simultaneous Vaadin sessions.static StringSESSION_TRACKING_PARAMETERServlet initialization parameter ("sessionTracking") that enables tracking of all Vaadin session.-
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 SpringVaadinServlet()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected VaadinServletServicecreateServletService(DeploymentConfiguration deploymentConfiguration)static SpringVaadinServletgetServlet(VaadinSession session)Get theSpringVaadinServletthat is associated with the givenVaadinSession.List<VaadinSession>getSessions()Get all liveVaadinSessions associated with this instance.voidinit(javax.servlet.ServletConfig config)protected voidservletInitialized()-
Methods inherited from class com.vaadin.server.VaadinServlet
allowServePrecompressedResource, createDeploymentConfiguration, createVaadinRequest, criticalNotification, destroy, findResourceURL, getApplicationUrl, getCacheTime, getCurrent, getDefaultTheme, getLastPathParameter, getRequestType, getResourcePath, getService, handleContextRootWithoutSlash, isAllowedVAADINResourceUrl, isStaticResourceRequest, safeEscapeForHtml, serveStaticResources, serveStaticResourcesInVAADIN, service, stripSpecialChars, writeStaticResourceResponse
-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
-
-
-
-
Field Detail
-
CONFIG_LOCATION_PARAMETER
public static final String CONFIG_LOCATION_PARAMETER
Servlet initialization parameter ("configLocation") used to specify the location(s) of the Spring application context XML file(s). Multiple XML files may be separated by whitespace. This parameter is optional.- See Also:
- Constant Field Values
-
LISTENER_CLASS_PARAMETER
public static final String LISTENER_CLASS_PARAMETER
Servlet initialization parameter ("listenerClass") used to specify the name of an custom subclass ofSpringVaadinSessionListener. This parameter is optional.- See Also:
- Constant Field Values
-
APPLICATION_NAME_PARAMETER
public static final String APPLICATION_NAME_PARAMETER
Servlet initialization parameter ("applicationName") used to specify the name the application. This parameter is optional.- See Also:
- Constant Field Values
-
SESSION_TRACKING_PARAMETER
public static final String SESSION_TRACKING_PARAMETER
Servlet initialization parameter ("sessionTracking") that enables tracking of all Vaadin session. This parameter is optional, and defaults tofalse.- See Also:
- Constant Field Values
-
MAX_SESSIONS_PARAMETER
public static final String MAX_SESSIONS_PARAMETER
Servlet initialization parameter ("maxSessions") that configures the maximum number of simultaneous Vaadin sessions. RequiresSESSION_TRACKING_PARAMETERto be set totrue. This parameter is optional, and defaults to zero, which means no limit.- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException- Specified by:
initin interfacejavax.servlet.Servlet- Overrides:
initin classVaadinServlet- Throws:
javax.servlet.ServletException
-
servletInitialized
protected void servletInitialized() throws javax.servlet.ServletException- Overrides:
servletInitializedin classVaadinServlet- Throws:
javax.servlet.ServletException
-
createServletService
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException
- Overrides:
createServletServicein classVaadinServlet- Throws:
ServiceException
-
getSessions
public List<VaadinSession> getSessions()
Get all liveVaadinSessions associated with this instance.- Returns:
- live tracked sessions, or an empty collection if session tracking is not enabled
- See Also:
VaadinSessionContainer
-
getServlet
public static SpringVaadinServlet getServlet(VaadinSession session)
Get theSpringVaadinServletthat is associated with the givenVaadinSession.- Parameters:
session- Vaadin session- Returns:
- the assocated
SpringVaadinServlet - Throws:
IllegalStateException- if theVaadinServletassociated withsessionis not aSpringVaadinServlet
-
-