From d9bfc8b8e067484047750eb324793ba4c8fca434 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 7 Apr 2016 17:35:03 +1000 Subject: [PATCH] Issue #490 serverClasses set from jetty-web.xml Provided a mode that ignores server classes, but still allows them to be edited. --- .../webapp/JettyWebXmlConfiguration.java | 53 +++++++++---------- .../eclipse/jetty/webapp/WebAppContext.java | 27 +++++++++- 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.java index 5a6a6a6c67c..a1ec984f5e3 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/JettyWebXmlConfiguration.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.webapp; import java.util.Map; +import java.util.concurrent.Callable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -77,39 +78,35 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration jetty=web_inf.addPath("web-jetty.xml"); if(jetty.exists()) - { - // No server classes while configuring - String[] old_server_classes = context.getServerClasses(); + { + if(LOG.isDebugEnabled()) + LOG.debug("Configure: "+jetty); + + Object xml_attr=context.getAttribute(XML_CONFIGURATION); + context.removeAttribute(XML_CONFIGURATION); + + final XmlConfiguration jetty_config = xml_attr instanceof XmlConfiguration + ?(XmlConfiguration)xml_attr + :new XmlConfiguration(jetty.getURI().toURL()); + setupXmlConfiguration(jetty_config, web_inf); + try { - context.setServerClasses(null); - if(LOG.isDebugEnabled()) - LOG.debug("Configure: "+jetty); - - XmlConfiguration jetty_config = (XmlConfiguration)context.getAttribute(XML_CONFIGURATION); - - if (jetty_config==null) + final XmlConfiguration config=jetty_config; + context.runWithoutCheckingServerClasses(new Callable() { - jetty_config=new XmlConfiguration(jetty.getURL()); - } - else - { - context.removeAttribute(XML_CONFIGURATION); - } - setupXmlConfiguration(jetty_config, web_inf); - try - { - jetty_config.configure(context); - } - catch (ClassNotFoundException e) - { - LOG.warn("Unable to process jetty-web.xml", e); - } + @Override + public Void call() throws Exception + { + config.configure(context); + return null; + } + }); } - finally + catch(Exception e) { - if (old_server_classes != null) - context.setServerClasses(old_server_classes); + LOG.warn("Error applying {}",jetty); + throw e; } } } 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 25d65adcfc5..eef7d856e7b 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 @@ -34,6 +34,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.Callable; import javax.servlet.ServletContext; import javax.servlet.ServletRegistration.Dynamic; @@ -185,6 +186,8 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL private boolean _configurationDiscovered=true; private boolean _allowDuplicateFragmentNames = false; private boolean _throwUnavailableOnStartupException = false; + private boolean _checkingServerClasses = true; + @@ -747,11 +750,33 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL _systemClasses.prependPattern(classOrPackage); } - + + /* ------------------------------------------------------------ */ + /** Call a Callable for which all calls to {@link #isServerClass(String)} + * will return false. + * @param callable The callable to call. + * @throws Exception Any exception thrown by the Callable + */ + public void runWithoutCheckingServerClasses(Callable callable) throws Exception + { + _checkingServerClasses=false; + try + { + callable.call(); + } + finally + { + _checkingServerClasses=true; + } + } + /* ------------------------------------------------------------ */ @Override public boolean isServerClass(String name) { + if (!_checkingServerClasses) + return false; + if (_serverClasses == null) loadServerClasses();