470803 If a webapp is not fully started do not fully stop it

This commit is contained in:
Jan Bartel 2015-06-25 18:29:51 +10:00
parent 8a64c50f24
commit 3ac6a727cf
5 changed files with 126 additions and 45 deletions

View File

@ -131,7 +131,7 @@ public class JettyWebAppContext extends WebAppContext
/* ------------------------------------------------------------ */
public JettyWebAppContext ()
throws Exception
{
@ -139,71 +139,81 @@ public class JettyWebAppContext extends WebAppContext
// Turn off copyWebInf option as it is not applicable for plugin.
super.setCopyWebInf(false);
}
/* ------------------------------------------------------------ */
public void setContainerIncludeJarPattern(String pattern)
{
_containerIncludeJarPattern = pattern;
}
/* ------------------------------------------------------------ */
public String getContainerIncludeJarPattern()
{
return _containerIncludeJarPattern;
}
/* ------------------------------------------------------------ */
public String getWebInfIncludeJarPattern()
{
return _webInfIncludeJarPattern;
}
/* ------------------------------------------------------------ */
public void setWebInfIncludeJarPattern(String pattern)
{
_webInfIncludeJarPattern = pattern;
}
/* ------------------------------------------------------------ */
public List<File> getClassPathFiles()
{
return this._classpathFiles;
}
/* ------------------------------------------------------------ */
public void setJettyEnvXml (String jettyEnvXml)
{
this._jettyEnvXml = jettyEnvXml;
}
/* ------------------------------------------------------------ */
public String getJettyEnvXml()
{
return this._jettyEnvXml;
}
/* ------------------------------------------------------------ */
public void setClasses(File dir)
{
_classes = dir;
}
/* ------------------------------------------------------------ */
public File getClasses()
{
return _classes;
}
/* ------------------------------------------------------------ */
public void setWebInfLib (List<File> jars)
{
_webInfJars.addAll(jars);
}
/* ------------------------------------------------------------ */
public void setTestClasses (File dir)
{
_testClasses = dir;
}
/* ------------------------------------------------------------ */
public File getTestClasses ()
{
return _testClasses;
}
/* ------------------------------------------------------------ */
/**
* Ordered list of wars to overlay on top of the current project. The list
* may contain an overlay that represents the current project.
@ -214,6 +224,7 @@ public class JettyWebAppContext extends WebAppContext
_overlays = overlays;
}
/* ------------------------------------------------------------ */
public List<Overlay> getOverlays()
{
return _overlays;
@ -262,16 +273,19 @@ public class JettyWebAppContext extends WebAppContext
setBaseResource(new ResourceCollection(resources.toArray(new String[resources.size()])));
}
/* ------------------------------------------------------------ */
public List<File> getWebInfLib()
{
return _webInfJars;
}
/* ------------------------------------------------------------ */
public void setGenerateQuickStart (boolean quickStart)
{
_isGenerateQuickStart = quickStart;
}
/* ------------------------------------------------------------ */
public boolean isGenerateQuickStart()
{
return _isGenerateQuickStart;
@ -279,7 +293,7 @@ public class JettyWebAppContext extends WebAppContext
/* ------------------------------------------------------------ */
@Override
protected void startWebapp() throws Exception
{
@ -295,10 +309,24 @@ public class JettyWebAppContext extends WebAppContext
}
}
else
{
if (LOG.isDebugEnabled()) { LOG.debug("Calling full start on webapp");}
super.startWebapp();
}
}
/* ------------------------------------------------------------ */
@Override
protected void stopWebapp() throws Exception
{
if (isGenerateQuickStart())
return;
if (LOG.isDebugEnabled()) { LOG.debug("Calling stop of fully started webapp");}
super.stopWebapp();
}
/* ------------------------------------------------------------ */
@Override
public void doStart () throws Exception
{
@ -315,7 +343,6 @@ public class JettyWebAppContext extends WebAppContext
}
}
//inject configurations with config from maven plugin
for (Configuration c:getConfigurations())
{
@ -370,6 +397,8 @@ public class JettyWebAppContext extends WebAppContext
super.doStart();
}
/* ------------------------------------------------------------ */
public void doStop () throws Exception
{
if (_classpathFiles != null)
@ -390,6 +419,7 @@ public class JettyWebAppContext extends WebAppContext
// CHECK setShutdown(true);
//just wait a little while to ensure no requests are still being processed
Thread.currentThread().sleep(500L);
super.doStop();
//remove all listeners, servlets and filters. This is because we will re-apply
@ -401,6 +431,8 @@ public class JettyWebAppContext extends WebAppContext
getServletHandler().setServletMappings(new ServletMapping[0]);
}
/* ------------------------------------------------------------ */
@Override
public Resource getResource(String uriInContext) throws MalformedURLException
{
@ -475,6 +507,8 @@ public class JettyWebAppContext extends WebAppContext
return resource;
}
/* ------------------------------------------------------------ */
@Override
public Set<String> getResourcePaths(String path)
{
@ -511,7 +545,7 @@ public class JettyWebAppContext extends WebAppContext
return paths;
}
/* ------------------------------------------------------------ */
public String addPattern (String s, String pattern)
{
if (s == null)
@ -529,6 +563,8 @@ public class JettyWebAppContext extends WebAppContext
return s;
}
/* ------------------------------------------------------------ */
public void initCDI()
{
Class cdiInitializer = null;

View File

@ -104,6 +104,17 @@ public class QuickStartWebApp extends WebAppContext
super.startWebapp();
}
@Override
protected void stopWebapp() throws Exception
{
if (!_startWebapp)
return;
super.stopWebapp();
}
@Override
protected void doStart() throws Exception
{

View File

@ -772,6 +772,24 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
}
}
/* ------------------------------------------------------------ */
protected void stopContext () throws Exception
{
//stop all the handler hierarchy
super.doStop();
//Call the context listeners
if (!_contextListeners.isEmpty())
{
ServletContextEvent event = new ServletContextEvent(_scontext);
for (int i = _contextListeners.size(); i-->0;)
callContextDestroyed(_contextListeners.get(i),event);
}
}
/* ------------------------------------------------------------ */
protected void callContextInitialized (ServletContextListener l, ServletContextEvent e)
{
@ -812,15 +830,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
current_thread.setContextClassLoader(_classLoader);
}
super.doStop();
// Context listeners
if (!_contextListeners.isEmpty())
{
ServletContextEvent event = new ServletContextEvent(_scontext);
for (int i = _contextListeners.size(); i-->0;)
callContextDestroyed(_contextListeners.get(i),event);
}
stopContext();
//retain only durable listeners
setEventListeners(_durableListeners.toArray(new EventListener[_durableListeners.size()]));
@ -845,6 +855,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
_scontext.clearAttributes();
}
/* ------------------------------------------------------------ */
public boolean checkVirtualHost(final Request baseRequest)
{
if (_vhosts != null && _vhosts.length > 0)
@ -885,6 +897,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
return true;
}
/* ------------------------------------------------------------ */
public boolean checkContextPath(String uri)
{
// Are we not the root context?

View File

@ -251,6 +251,7 @@ public class ServletContextHandler extends ContextHandler
}
/* ------------------------------------------------------------ */
@Override
protected void doStart() throws Exception
{
@ -345,6 +346,13 @@ public class ServletContextHandler extends ContextHandler
_servletHandler.initialize();
}
/* ------------------------------------------------------------ */
@Override
protected void stopContext() throws Exception
{
super.stopContext();
}
/* ------------------------------------------------------------ */
/**
* @return Returns the securityHandler.

View File

@ -534,25 +534,6 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
protected void doStop() throws Exception
{
super.doStop();
try
{
for (int i=_configurations.size();i-->0;)
_configurations.get(i).deconfigure(this);
if (_metadata != null)
_metadata.clear();
_metadata=new MetaData();
}
finally
{
if (_ownClassLoader)
setClassLoader(null);
setAvailable(true);
_unavailableException=null;
}
}
/* ------------------------------------------------------------ */
@ -1355,6 +1336,32 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
startWebapp();
}
/* ------------------------------------------------------------ */
@Override
protected void stopContext() throws Exception
{
stopWebapp();
try
{
for (int i=_configurations.size();i-->0;)
_configurations.get(i).deconfigure(this);
if (_metadata != null)
_metadata.clear();
_metadata=new MetaData();
}
finally
{
if (_ownClassLoader)
setClassLoader(null);
setAvailable(true);
_unavailableException=null;
}
}
/* ------------------------------------------------------------ */
protected void startWebapp()
throws Exception
@ -1362,6 +1369,11 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
super.startContext();
}
/* ------------------------------------------------------------ */
protected void stopWebapp() throws Exception
{
super.stopContext();
}
/* ------------------------------------------------------------ */
@Override
public Set<String> setServletSecurity(Dynamic registration, ServletSecurityElement servletSecurityElement)