Don't enforce the default WebSocketMapping.

If a user wants to use the WebSocketUpgradeFilter with a different WebSocketMapping,
they can add the ServerContainer manually and put their own WebSocketMapping in.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2020-11-02 15:57:58 +11:00
parent 5d9c81a511
commit b327992f75
2 changed files with 13 additions and 7 deletions

View File

@ -91,6 +91,7 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements
private final ServletContextHandler contextHandler;
private final WebSocketMapping webSocketMapping;
private final WebSocketComponents components;
private final FrameHandlerFactory frameHandlerFactory;
private final Executor executor;
private final Configuration.ConfigurationCustomizer customizer = new Configuration.ConfigurationCustomizer();
@ -102,14 +103,15 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements
* Main entry point for {@link JettyWebSocketServletContainerInitializer}.
*
* @param webSocketMapping the {@link WebSocketMapping} that this container belongs to
* @param webSocketComponents the {@link WebSocketComponents} instance to use
* @param components the {@link WebSocketComponents} instance to use
* @param executor the {@link Executor} to use
*/
JettyWebSocketServerContainer(ServletContextHandler contextHandler, WebSocketMapping webSocketMapping, WebSocketComponents webSocketComponents, Executor executor)
JettyWebSocketServerContainer(ServletContextHandler contextHandler, WebSocketMapping webSocketMapping, WebSocketComponents components, Executor executor)
{
this.contextHandler = contextHandler;
this.webSocketMapping = webSocketMapping;
this.executor = executor;
this.components = components;
// Ensure there is a FrameHandlerFactory
JettyServerFrameHandlerFactory factory = contextHandler.getBean(JettyServerFrameHandlerFactory.class);
@ -155,6 +157,11 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements
});
}
public WebSocketComponents getWebSocketComponents()
{
return components;
}
@Override
public Executor getExecutor()
{

View File

@ -88,12 +88,9 @@ public class JettyWebSocketServletContainerInitializer implements ServletContain
*/
private static JettyWebSocketServerContainer initialize(ServletContextHandler context)
{
WebSocketComponents components = WebSocketServerComponents.ensureWebSocketComponents(context.getServletContext());
WebSocketMapping mapping = WebSocketMapping.ensureMapping(context.getServletContext(), WebSocketMapping.DEFAULT_KEY);
JettyWebSocketServerContainer container = JettyWebSocketServerContainer.ensureContainer(context.getServletContext());
if (LOG.isDebugEnabled())
LOG.debug("configureContext {} {} {}", container, mapping, components);
LOG.debug("initialize {}", container);
return container;
}
@ -102,6 +99,8 @@ public class JettyWebSocketServletContainerInitializer implements ServletContain
public void onStartup(Set<Class<?>> c, ServletContext context)
{
ServletContextHandler contextHandler = ServletContextHandler.getServletContextHandler(context, "Jetty WebSocket SCI");
JettyWebSocketServletContainerInitializer.initialize(contextHandler);
JettyWebSocketServerContainer container = JettyWebSocketServletContainerInitializer.initialize(contextHandler);
if (LOG.isDebugEnabled())
LOG.debug("onStartup {}", container);
}
}