485063 After stopping JettyWebAppContext, it still contains reference to old WebAppClassLoader via ServerContainer bean
This commit is contained in:
parent
d760926554
commit
a934db118d
|
@ -23,6 +23,8 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.ServletContainerInitializer;
|
import javax.servlet.ServletContainerInitializer;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.ServletContextEvent;
|
||||||
|
import javax.servlet.ServletContextListener;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.annotation.HandlesTypes;
|
import javax.servlet.annotation.HandlesTypes;
|
||||||
import javax.websocket.DeploymentException;
|
import javax.websocket.DeploymentException;
|
||||||
|
@ -47,6 +49,39 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
|
||||||
public static final String ENABLE_KEY = "org.eclipse.jetty.websocket.jsr356";
|
public static final String ENABLE_KEY = "org.eclipse.jetty.websocket.jsr356";
|
||||||
private static final Logger LOG = Log.getLogger(WebSocketServerContainerInitializer.class);
|
private static final Logger LOG = Log.getLogger(WebSocketServerContainerInitializer.class);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DestroyListener
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static class ContextDestroyListener implements ServletContextListener
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void contextInitialized(ServletContextEvent sce)
|
||||||
|
{
|
||||||
|
//noop
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextDestroyed(ServletContextEvent sce)
|
||||||
|
{
|
||||||
|
//remove any ServerContainer beans
|
||||||
|
if (sce.getServletContext() instanceof ContextHandler.Context)
|
||||||
|
{
|
||||||
|
ContextHandler handler = ((ContextHandler.Context)sce.getServletContext()).getContextHandler();
|
||||||
|
ServerContainer bean = handler.getBean(ServerContainer.class);
|
||||||
|
if (bean != null)
|
||||||
|
handler.removeBean(bean);
|
||||||
|
}
|
||||||
|
|
||||||
|
//remove reference in attributes
|
||||||
|
sce.getServletContext().removeAttribute(javax.websocket.server.ServerContainer.class.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Jetty Native approach.
|
* Jetty Native approach.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -63,7 +98,7 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
|
||||||
|
|
||||||
// Create the Jetty ServerContainer implementation
|
// Create the Jetty ServerContainer implementation
|
||||||
ServerContainer jettyContainer = new ServerContainer(filter,filter.getFactory(),context.getServer().getThreadPool());
|
ServerContainer jettyContainer = new ServerContainer(filter,filter.getFactory(),context.getServer().getThreadPool());
|
||||||
context.addBean(jettyContainer);
|
context.addBean(jettyContainer, true);
|
||||||
|
|
||||||
// Store a reference to the ServerContainer per javax.websocket spec 1.0 final section 6.4 Programmatic Server Deployment
|
// Store a reference to the ServerContainer per javax.websocket spec 1.0 final section 6.4 Programmatic Server Deployment
|
||||||
context.setAttribute(javax.websocket.server.ServerContainer.class.getName(),jettyContainer);
|
context.setAttribute(javax.websocket.server.ServerContainer.class.getName(),jettyContainer);
|
||||||
|
@ -88,7 +123,7 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
|
||||||
|
|
||||||
// Create the Jetty ServerContainer implementation
|
// Create the Jetty ServerContainer implementation
|
||||||
ServerContainer jettyContainer = new ServerContainer(filter,filter.getFactory(),jettyContext.getServer().getThreadPool());
|
ServerContainer jettyContainer = new ServerContainer(filter,filter.getFactory(),jettyContext.getServer().getThreadPool());
|
||||||
jettyContext.addBean(jettyContainer);
|
jettyContext.addBean(jettyContainer, true);
|
||||||
|
|
||||||
// Store a reference to the ServerContainer per javax.websocket spec 1.0 final section 6.4 Programmatic Server Deployment
|
// Store a reference to the ServerContainer per javax.websocket spec 1.0 final section 6.4 Programmatic Server Deployment
|
||||||
context.setAttribute(javax.websocket.server.ServerContainer.class.getName(),jettyContainer);
|
context.setAttribute(javax.websocket.server.ServerContainer.class.getName(),jettyContainer);
|
||||||
|
@ -172,8 +207,7 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
|
||||||
// Create the Jetty ServerContainer implementation
|
// Create the Jetty ServerContainer implementation
|
||||||
ServerContainer jettyContainer = configureContext(context,jettyContext);
|
ServerContainer jettyContainer = configureContext(context,jettyContext);
|
||||||
|
|
||||||
// Store a reference to the ServerContainer per javax.websocket spec 1.0 final section 6.4 Programmatic Server Deployment
|
context.addListener(new ContextDestroyListener()); //make sure context is cleaned up when the context stops
|
||||||
context.setAttribute(javax.websocket.server.ServerContainer.class.getName(),jettyContainer);
|
|
||||||
|
|
||||||
// Establish the DecoratedObjectFactory thread local
|
// Establish the DecoratedObjectFactory thread local
|
||||||
// for various ServiceLoader initiated components to use.
|
// for various ServiceLoader initiated components to use.
|
||||||
|
@ -278,7 +312,9 @@ public class WebSocketServerContainerInitializer implements ServletContainerInit
|
||||||
throw new ServletException(e);
|
throw new ServletException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
Thread.currentThread().setContextClassLoader(old);
|
Thread.currentThread().setContextClassLoader(old);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue