Cleanup webapp context

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2018-11-07 12:05:55 +01:00
parent 872eafef06
commit 6bec0e8357
3 changed files with 20 additions and 27 deletions

View File

@ -55,7 +55,7 @@ public class OneWebAppWithJsp
WebAppContext webapp = new WebAppContext(); WebAppContext webapp = new WebAppContext();
webapp.setContextPath( "/" ); webapp.setContextPath( "/" );
File warFile = new File( File warFile = new File(
"../../jetty-distribution/target/distribution/demo-base/webapps/test.war" ); "jetty-distribution/target/distribution/demo-base/webapps/test.war" );
if (!warFile.exists()) if (!warFile.exists())
{ {
throw new RuntimeException( "Unable to find WAR File: " throw new RuntimeException( "Unable to find WAR File: "
@ -96,7 +96,7 @@ public class OneWebAppWithJsp
// itself. // itself.
HashLoginService loginService = new HashLoginService(); HashLoginService loginService = new HashLoginService();
loginService.setName( "Test Realm" ); loginService.setName( "Test Realm" );
loginService.setConfig( "src/test/resources/realm.properties" ); loginService.setConfig( "examples/embedded/src/test/resources/realm.properties" );
server.addBean( loginService ); server.addBean( loginService );
// Start things up! // Start things up!

View File

@ -79,9 +79,9 @@ public class AnnotationConfiguration extends AbstractConfiguration
public static final int DEFAULT_MAX_SCAN_WAIT = 60; /* time in sec */ public static final int DEFAULT_MAX_SCAN_WAIT = 60; /* time in sec */
public static final boolean DEFAULT_MULTI_THREADED = true; public static final boolean DEFAULT_MULTI_THREADED = true;
protected List<AbstractDiscoverableAnnotationHandler> _discoverableAnnotationHandlers = new ArrayList<AbstractDiscoverableAnnotationHandler>(); protected final List<AbstractDiscoverableAnnotationHandler> _discoverableAnnotationHandlers = new ArrayList<>();
protected ClassInheritanceHandler _classInheritanceHandler; protected ClassInheritanceHandler _classInheritanceHandler;
protected List<ContainerInitializerAnnotationHandler> _containerInitializerAnnotationHandlers = new ArrayList<ContainerInitializerAnnotationHandler>(); protected final List<ContainerInitializerAnnotationHandler> _containerInitializerAnnotationHandlers = new ArrayList<>();
protected List<ParserTask> _parserTasks; protected List<ParserTask> _parserTasks;
@ -319,28 +319,11 @@ public class AnnotationConfiguration extends AbstractConfiguration
_sciExcludePattern = (tmp==null?null:Pattern.compile(tmp)); _sciExcludePattern = (tmp==null?null:Pattern.compile(tmp));
} }
public void addDiscoverableAnnotationHandler(AbstractDiscoverableAnnotationHandler handler) public void addDiscoverableAnnotationHandler(AbstractDiscoverableAnnotationHandler handler)
{ {
_discoverableAnnotationHandlers.add(handler); _discoverableAnnotationHandlers.add(handler);
} }
@Override
public void deconfigure(WebAppContext context) throws Exception
{
context.removeAttribute(CLASS_INHERITANCE_MAP);
context.removeAttribute(CONTAINER_INITIALIZERS);
ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter)context.getAttribute(CONTAINER_INITIALIZER_STARTER);
if (starter != null)
{
context.removeBean(starter);
context.removeAttribute(CONTAINER_INITIALIZER_STARTER);
}
if (_loadedInitializers != null)
_loadedInitializers.reload();
}
/** /**
* @see org.eclipse.jetty.webapp.AbstractConfiguration#configure(org.eclipse.jetty.webapp.WebAppContext) * @see org.eclipse.jetty.webapp.AbstractConfiguration#configure(org.eclipse.jetty.webapp.WebAppContext)
*/ */
@ -386,15 +369,14 @@ public class AnnotationConfiguration extends AbstractConfiguration
public void postConfigure(WebAppContext context) throws Exception public void postConfigure(WebAppContext context) throws Exception
{ {
Map<String, Set<String>> classMap = (ClassInheritanceMap)context.getAttribute(CLASS_INHERITANCE_MAP); Map<String, Set<String>> classMap = (ClassInheritanceMap)context.getAttribute(CLASS_INHERITANCE_MAP);
List<ContainerInitializer> initializers = (List<ContainerInitializer>)context.getAttribute(CONTAINER_INITIALIZERS);
context.removeAttribute(CLASS_INHERITANCE_MAP);
if (classMap != null) if (classMap != null)
classMap.clear(); classMap.clear();
context.removeAttribute(CLASS_INHERITANCE_MAP);
context.removeAttribute(CONTAINER_INITIALIZERS); List<ContainerInitializer> initializers = (List<ContainerInitializer>)context.getAttribute(CONTAINER_INITIALIZERS);
if (initializers != null) if (initializers != null)
initializers.clear(); initializers.clear();
context.removeAttribute(CONTAINER_INITIALIZERS);
if (_discoverableAnnotationHandlers != null) if (_discoverableAnnotationHandlers != null)
_discoverableAnnotationHandlers.clear(); _discoverableAnnotationHandlers.clear();
@ -409,6 +391,16 @@ public class AnnotationConfiguration extends AbstractConfiguration
_parserTasks = null; _parserTasks = null;
} }
ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter)context.getAttribute(CONTAINER_INITIALIZER_STARTER);
if (starter != null)
{
context.removeBean(starter);
context.removeAttribute(CONTAINER_INITIALIZER_STARTER);
}
if (_loadedInitializers != null)
_loadedInitializers.reload();
super.postConfigure(context); super.postConfigure(context);
} }

View File

@ -287,6 +287,7 @@ public class ServletContextHandler extends ContextHandler
{ {
super.doStop(); super.doStop();
_objFactory.clear(); _objFactory.clear();
getServletContext().removeAttribute(DecoratedObjectFactory.ATTR);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */