From 3ac6a727cff2742f4b2020e9ee0a16a1552e2ab6 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Thu, 25 Jun 2015 18:29:51 +1000 Subject: [PATCH] 470803 If a webapp is not fully started do not fully stop it --- .../maven/plugin/JettyWebAppContext.java | 66 ++++++++++++++----- .../jetty/quickstart/QuickStartWebApp.java | 11 ++++ .../jetty/server/handler/ContextHandler.java | 36 ++++++---- .../jetty/servlet/ServletContextHandler.java | 8 +++ .../eclipse/jetty/webapp/WebAppContext.java | 50 ++++++++------ 5 files changed, 126 insertions(+), 45 deletions(-) diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java index bcb574899a6..b4b52441dfa 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java @@ -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 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 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 getOverlays() { return _overlays; @@ -261,17 +272,20 @@ public class JettyWebAppContext extends WebAppContext setBaseResource(new ResourceCollection(resources.toArray(new String[resources.size()]))); } - + + /* ------------------------------------------------------------ */ public List 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()) { @@ -369,7 +396,9 @@ public class JettyWebAppContext extends WebAppContext // CHECK setShutdown(false); super.doStart(); } - + + + /* ------------------------------------------------------------ */ public void doStop () throws Exception { if (_classpathFiles != null) @@ -390,8 +419,9 @@ 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 //any context xml file, which means they would potentially be added multiple times. setEventListeners(new EventListener[0]); @@ -400,7 +430,9 @@ public class JettyWebAppContext extends WebAppContext getServletHandler().setServlets(new ServletHolder[0]); getServletHandler().setServletMappings(new ServletMapping[0]); } - + + + /* ------------------------------------------------------------ */ @Override public Resource getResource(String uriInContext) throws MalformedURLException { @@ -474,7 +506,9 @@ public class JettyWebAppContext extends WebAppContext } return resource; } - + + + /* ------------------------------------------------------------ */ @Override public Set 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; diff --git a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartWebApp.java b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartWebApp.java index 5f6084336e1..f69f73f5e51 100644 --- a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartWebApp.java +++ b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartWebApp.java @@ -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 { diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index 21a8cfb22a0..8fd95cf7597 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -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()])); @@ -844,7 +854,9 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu _scontext.clearAttributes(); } - + + + /* ------------------------------------------------------------ */ public boolean checkVirtualHost(final Request baseRequest) { if (_vhosts != null && _vhosts.length > 0) @@ -884,7 +896,9 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu } return true; } - + + + /* ------------------------------------------------------------ */ public boolean checkContextPath(String uri) { // Are we not the root context? diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java index d3504c28fa1..f79803c8035 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java @@ -251,6 +251,7 @@ public class ServletContextHandler extends ContextHandler } + /* ------------------------------------------------------------ */ @Override protected void doStart() throws Exception { @@ -344,6 +345,13 @@ public class ServletContextHandler extends ContextHandler if (_servletHandler != null) _servletHandler.initialize(); } + + /* ------------------------------------------------------------ */ + @Override + protected void stopContext() throws Exception + { + super.stopContext(); + } /* ------------------------------------------------------------ */ /** diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java index d987198e5cd..0f5e97aca70 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java @@ -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; - } } /* ------------------------------------------------------------ */ @@ -1354,6 +1335,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() @@ -1362,6 +1369,11 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL super.startContext(); } + /* ------------------------------------------------------------ */ + protected void stopWebapp() throws Exception + { + super.stopContext(); + } /* ------------------------------------------------------------ */ @Override public Set setServletSecurity(Dynamic registration, ServletSecurityElement servletSecurityElement)