Class JSR356WebsocketInitializer
- All Implemented Interfaces:
jakarta.servlet.ServletContextListener,EventListener
Websocket specification says that initialization of websocket end points should be done in the servlet context initialization phase. Some servers implement this strictly so that end points cannot be registered after the context initialization phase.
Note that WebListener is Servlet 5.0 API so this will not be run for
older servers (unless added to web.xml), but these servers do not support JSR
356 websockets either.
For internal use only. May be renamed or removed in a future release.
- Since:
- 1.0
- Author:
- Vaadin Ltd
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class"ServletConfig" which only provides information from aServletRegistrationand itsServletContext. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name of the servlet context attribute which, when set toBoolean.TRUE, makes this listener leave Atmosphere uninitialized when the servlet context is initialized. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcontextDestroyed(jakarta.servlet.ServletContextEvent sce) voidcontextInitialized(jakarta.servlet.ServletContextEvent sce) static StringgetAttributeName(String servletName) Returns the name of the attribute in the servlet context where the pre-initialized Atmosphere object is stored.voidinit(jakarta.servlet.ServletContext servletContext) Initializes Atmosphere for use with Vaadin servlets found in the given context.static voidinitAtmosphereForVaadinServlet(jakarta.servlet.ServletRegistration servletRegistration, jakarta.servlet.ServletContext servletContext) Initializes Atmosphere for use with the given Vaadin servletstatic booleanChecks if Atmosphere is available on the classpath.protected booleanisVaadinServlet(jakarta.servlet.ServletRegistration servletRegistration, jakarta.servlet.ServletContext servletContext) Tries to determine if the given servlet registration refers to a Vaadin servlet.
-
Field Details
-
SKIP_INITIALIZATION_ATTRIBUTE
The name of the servlet context attribute which, when set toBoolean.TRUE, makes this listener leave Atmosphere uninitialized when the servlet context is initialized.An integration sets it when it registers the push WebSocket endpoints itself and initializes Atmosphere later, with
initAtmosphereForVaadinServlet(ServletRegistration, ServletContext).For internal use only. May be renamed or removed in a future release.
- See Also:
-
-
Constructor Details
-
JSR356WebsocketInitializer
public JSR356WebsocketInitializer()
-
-
Method Details
-
contextInitialized
public void contextInitialized(jakarta.servlet.ServletContextEvent sce) - Specified by:
contextInitializedin interfacejakarta.servlet.ServletContextListener
-
init
public void init(jakarta.servlet.ServletContext servletContext) Initializes Atmosphere for use with Vaadin servlets found in the given context.For JSR 356 websockets to work properly, the initialization must be done in the servlet context initialization phase, unless the
SKIP_INITIALIZATION_ATTRIBUTEattribute of the context says that an integration takes care of the push WebSocket endpoints.- Parameters:
servletContext- The servlet context
-
initAtmosphereForVaadinServlet
public static void initAtmosphereForVaadinServlet(jakarta.servlet.ServletRegistration servletRegistration, jakarta.servlet.ServletContext servletContext) Initializes Atmosphere for use with the given Vaadin servletFor JSR 356 websockets to work properly, the initialization must be done in the servlet context initialization phase, unless an integration that set the
SKIP_INITIALIZATION_ATTRIBUTEattribute registers the push WebSocket endpoints itself. Such an integration calls this method later, before the Vaadin servlet is initialized, so that the servlet uses the Atmosphere instance created here.- Parameters:
servletRegistration- The servlet registration info for the servletservletContext- The servlet context
-
getAttributeName
Returns the name of the attribute in the servlet context where the pre-initialized Atmosphere object is stored.- Parameters:
servletName- The name of the servlet- Returns:
- The attribute name which contains the initialized Atmosphere object
-
isVaadinServlet
protected boolean isVaadinServlet(jakarta.servlet.ServletRegistration servletRegistration, jakarta.servlet.ServletContext servletContext) Tries to determine if the given servlet registration refers to a Vaadin servlet.- Parameters:
servletRegistration- The servlet registration info for the servletservletContext- the context of the servlet- Returns:
- true if the servlet class is a Vaadin servlet, false otherwise (including when the servlet class cannot be loaded)
-
contextDestroyed
public void contextDestroyed(jakarta.servlet.ServletContextEvent sce) - Specified by:
contextDestroyedin interfacejakarta.servlet.ServletContextListener
-
isAtmosphereAvailable
public static boolean isAtmosphereAvailable()Checks if Atmosphere is available on the classpath.- Returns:
trueif Atmosphere is available,falseotherwise
-