Class TomcatWebSocketInitializer

java.lang.Object
io.micronaut.servlet.websocket.tomcat.TomcatWebSocketInitializer
All Implemented Interfaces:
jakarta.servlet.ServletContainerInitializer

@Internal @Singleton @Requires(classes=org.apache.tomcat.websocket.server.WsSci.class) @Requires(property="micronaut.servlet.websocket.enabled",notEquals="false",defaultValue="true") public final class TomcatWebSocketInitializer extends Object implements jakarta.servlet.ServletContainerInitializer
Ensures that a Jakarta ServerContainer is available on the Tomcat servlet context.

Tomcat.addContext attaches only a FixContextListener and never a ContextConfig, so Tomcat's own WsSci is never discovered through META-INF/services in embedded mode. Wrapping it in a bean is enough, because the Micronaut Tomcat factory already registers every ServletContainerInitializer bean with the context.

Since:
6.2.0
Author:
graemerocher
  • Constructor Details

    • TomcatWebSocketInitializer

      public TomcatWebSocketInitializer(ServletWebSocketConfiguration configuration, io.micronaut.http.server.HttpServerConfiguration serverConfiguration, WebSocketContainerHolder holder)
      Default constructor.
      Parameters:
      configuration - The WebSocket configuration
      serverConfiguration - The server configuration, used for the default idle timeout
      holder - Where the container is registered for client connections
  • Method Details

    • onStartup

      public void onStartup(Set<Class<?>> classes, jakarta.servlet.ServletContext ctx) throws jakarta.servlet.ServletException
      Specified by:
      onStartup in interface jakarta.servlet.ServletContainerInitializer
      Throws:
      jakarta.servlet.ServletException