Merge pull request #5860 from eclipse/jetty-9.4.x-5851-WebSocketServletCleanup

Issue #5851 - remove WebSocketServletFactory as ServletContext attribute on destroy
This commit is contained in:
Lachlan 2021-01-20 15:50:48 +11:00 committed by GitHub
commit 759805580b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -91,7 +91,10 @@ public abstract class WebSocketServlet extends HttpServlet
{ {
try try
{ {
ServletContext ctx = getServletContext();
ctx.removeAttribute(WebSocketServletFactory.class.getName());
factory.stop(); factory.stop();
factory = null;
} }
catch (Exception ignore) catch (Exception ignore)
{ {
@ -135,11 +138,8 @@ public abstract class WebSocketServlet extends HttpServlet
ServletContext ctx = getServletContext(); ServletContext ctx = getServletContext();
factory = WebSocketServletFactory.Loader.load(ctx, policy); factory = WebSocketServletFactory.Loader.load(ctx, policy);
configure(factory); configure(factory);
factory.start(); factory.start();
ctx.setAttribute(WebSocketServletFactory.class.getName(), factory); ctx.setAttribute(WebSocketServletFactory.class.getName(), factory);
} }
catch (Exception x) catch (Exception x)

View File

@ -43,6 +43,7 @@ public interface WebSocketServletFactory
{ {
try try
{ {
@SuppressWarnings("unchecked")
Class<? extends WebSocketServletFactory> wsClazz = Class<? extends WebSocketServletFactory> wsClazz =
(Class<? extends WebSocketServletFactory>)Class.forName(DEFAULT_IMPL, true, Thread.currentThread().getContextClassLoader()); (Class<? extends WebSocketServletFactory>)Class.forName(DEFAULT_IMPL, true, Thread.currentThread().getContextClassLoader());
Constructor<? extends WebSocketServletFactory> ctor = wsClazz.getDeclaredConstructor(ServletContext.class, WebSocketPolicy.class); Constructor<? extends WebSocketServletFactory> ctor = wsClazz.getDeclaredConstructor(ServletContext.class, WebSocketPolicy.class);