From a1587d807ed77b25b4be2a54e0b709ba180b232d Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Thu, 4 Sep 2014 09:47:47 +1000 Subject: [PATCH] 443262 Distinguish situation where jetty looks for tlds in META-INF but finds none vs does not look --- .../jetty/apache/jsp/JettyJasperInitializer.java | 11 ++++++++--- .../eclipse/jetty/webapp/MetaInfConfiguration.java | 11 +++++++++++ .../org/eclipse/jetty/webapp/WebInfConfiguration.java | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/apache-jsp/src/main/java/org/eclipse/jetty/apache/jsp/JettyJasperInitializer.java b/apache-jsp/src/main/java/org/eclipse/jetty/apache/jsp/JettyJasperInitializer.java index 4cd79932113..9c66c8d6999 100644 --- a/apache-jsp/src/main/java/org/eclipse/jetty/apache/jsp/JettyJasperInitializer.java +++ b/apache-jsp/src/main/java/org/eclipse/jetty/apache/jsp/JettyJasperInitializer.java @@ -23,14 +23,14 @@ import java.net.URL; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Set; import javax.servlet.ServletContext; -import javax.servlet.ServletException; import org.apache.jasper.servlet.JasperInitializer; import org.apache.jasper.servlet.TldPreScanned; import org.apache.jasper.servlet.TldScanner; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; import org.xml.sax.SAXException; /** @@ -39,6 +39,7 @@ import org.xml.sax.SAXException; */ public class JettyJasperInitializer extends JasperInitializer { + private static final Logger LOG = Log.getLogger(JettyJasperInitializer.class); /** * NullTldScanner @@ -99,14 +100,18 @@ public class JettyJasperInitializer extends JasperInitializer String tmp = context.getInitParameter("org.eclipse.jetty.jsp.precompiled"); if (tmp!=null && !tmp.equals("") && Boolean.valueOf(tmp)) { + if (LOG.isDebugEnabled()) LOG.debug("Jsp precompilation detected"); return new NullTldScanner(context, namespaceAware, validate, blockExternal); } Collection tldUrls = (Collection)context.getAttribute("org.eclipse.jetty.tlds"); - if (tldUrls != null && !tldUrls.isEmpty()) + if (tldUrls != null) { + if (LOG.isDebugEnabled()) LOG.debug("Tld pre-scan detected"); return new TldPreScanned(context,namespaceAware,validate,blockExternal,tldUrls); } + + if (LOG.isDebugEnabled()) LOG.debug("Defaulting to jasper tld scanning"); return super.newTldScanner(context, namespaceAware, validate, blockExternal); } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java index 4617c025503..b2291012b6e 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java @@ -71,6 +71,17 @@ public class MetaInfConfiguration extends AbstractConfiguration useContainerCache = attr.booleanValue(); if (LOG.isDebugEnabled()) LOG.debug("{} = {}", USE_CONTAINER_METAINF_CACHE, useContainerCache); + + //pre-emptively create empty lists for tlds, fragments and resources as context attributes + //this signals that this class has been called. This differentiates the case where this class + //has been called but finds no META-INF data from the case where this class was never called + if (context.getAttribute(METAINF_TLDS) == null) + context.setAttribute(METAINF_TLDS, new HashSet()); + if (context.getAttribute(METAINF_RESOURCES) == null) + context.setAttribute(METAINF_RESOURCES, new HashSet()); + if (context.getAttribute(METAINF_FRAGMENTS) == null) + context.setAttribute(METAINF_FRAGMENTS, new HashMap()); + scanJars(context, context.getMetaData().getContainerResources(), useContainerCache); scanJars(context, context.getMetaData().getWebInfJars(), false); } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java index 1e4096c19cb..1e68b1991f2 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java @@ -175,7 +175,7 @@ public class WebInfConfiguration extends AbstractConfiguration // Look for extra resource @SuppressWarnings("unchecked") Set resources = (Set)context.getAttribute(RESOURCE_DIRS); - if (resources!=null) + if (resources!=null && !resources.isEmpty()) { Resource[] collection=new Resource[resources.size()+1]; int i=0;