Class JSR356WebsocketInitializer
java.lang.Object
com.vaadin.flow.server.communication.JSR356WebsocketInitializer
- All Implemented Interfaces:
jakarta.servlet.ServletContextListener
,EventListener
public class JSR356WebsocketInitializer
extends Object
implements jakarta.servlet.ServletContextListener
Initializer class for JSR 356 websockets.
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 aServletRegistration
and itsServletContext
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
contextDestroyed
(jakarta.servlet.ServletContextEvent sce) void
contextInitialized
(jakarta.servlet.ServletContextEvent sce) static String
getAttributeName
(String servletName) Returns the name of the attribute in the servlet context where the pre-initialized Atmosphere object is stored.void
init
(jakarta.servlet.ServletContext servletContext) Initializes Atmosphere for use with Vaadin servlets found in the given context.static void
initAtmosphereForVaadinServlet
(jakarta.servlet.ServletRegistration servletRegistration, jakarta.servlet.ServletContext servletContext) Initializes Atmosphere for use with the given Vaadin servletstatic boolean
Checks if Atmosphere is available on the classpath.protected boolean
isVaadinServlet
(jakarta.servlet.ServletRegistration servletRegistration, jakarta.servlet.ServletContext servletContext) Tries to determine if the given servlet registration refers to a Vaadin servlet.
-
Constructor Details
-
JSR356WebsocketInitializer
public JSR356WebsocketInitializer()
-
-
Method Details
-
contextInitialized
public void contextInitialized(jakarta.servlet.ServletContextEvent sce) - Specified by:
contextInitialized
in 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.
- 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.
- 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:
- false if the servlet is definitely not a Vaadin servlet, true otherwise
-
contextDestroyed
public void contextDestroyed(jakarta.servlet.ServletContextEvent sce) - Specified by:
contextDestroyed
in interfacejakarta.servlet.ServletContextListener
-
isAtmosphereAvailable
public static boolean isAtmosphereAvailable()Checks if Atmosphere is available on the classpath.- Returns:
true
if Atmosphere is available,false
otherwise
-