443262 Distinguish situation where jetty looks for tlds in META-INF but finds none vs does not look

This commit is contained in:
Jan Bartel 2014-09-04 09:47:47 +10:00
parent 610bac49b9
commit a1587d807e
3 changed files with 20 additions and 4 deletions

View File

@ -23,14 +23,14 @@ import java.net.URL;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.jasper.servlet.JasperInitializer; import org.apache.jasper.servlet.JasperInitializer;
import org.apache.jasper.servlet.TldPreScanned; import org.apache.jasper.servlet.TldPreScanned;
import org.apache.jasper.servlet.TldScanner; 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; import org.xml.sax.SAXException;
/** /**
@ -39,6 +39,7 @@ import org.xml.sax.SAXException;
*/ */
public class JettyJasperInitializer extends JasperInitializer public class JettyJasperInitializer extends JasperInitializer
{ {
private static final Logger LOG = Log.getLogger(JettyJasperInitializer.class);
/** /**
* NullTldScanner * NullTldScanner
@ -99,14 +100,18 @@ public class JettyJasperInitializer extends JasperInitializer
String tmp = context.getInitParameter("org.eclipse.jetty.jsp.precompiled"); String tmp = context.getInitParameter("org.eclipse.jetty.jsp.precompiled");
if (tmp!=null && !tmp.equals("") && Boolean.valueOf(tmp)) if (tmp!=null && !tmp.equals("") && Boolean.valueOf(tmp))
{ {
if (LOG.isDebugEnabled()) LOG.debug("Jsp precompilation detected");
return new NullTldScanner(context, namespaceAware, validate, blockExternal); return new NullTldScanner(context, namespaceAware, validate, blockExternal);
} }
Collection<URL> tldUrls = (Collection<URL>)context.getAttribute("org.eclipse.jetty.tlds"); Collection<URL> tldUrls = (Collection<URL>)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); 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); return super.newTldScanner(context, namespaceAware, validate, blockExternal);
} }

View File

@ -71,6 +71,17 @@ public class MetaInfConfiguration extends AbstractConfiguration
useContainerCache = attr.booleanValue(); useContainerCache = attr.booleanValue();
if (LOG.isDebugEnabled()) LOG.debug("{} = {}", USE_CONTAINER_METAINF_CACHE, useContainerCache); 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<URL>());
if (context.getAttribute(METAINF_RESOURCES) == null)
context.setAttribute(METAINF_RESOURCES, new HashSet<Resource>());
if (context.getAttribute(METAINF_FRAGMENTS) == null)
context.setAttribute(METAINF_FRAGMENTS, new HashMap<Resource, Resource>());
scanJars(context, context.getMetaData().getContainerResources(), useContainerCache); scanJars(context, context.getMetaData().getContainerResources(), useContainerCache);
scanJars(context, context.getMetaData().getWebInfJars(), false); scanJars(context, context.getMetaData().getWebInfJars(), false);
} }

View File

@ -175,7 +175,7 @@ public class WebInfConfiguration extends AbstractConfiguration
// Look for extra resource // Look for extra resource
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Set<Resource> resources = (Set<Resource>)context.getAttribute(RESOURCE_DIRS); Set<Resource> resources = (Set<Resource>)context.getAttribute(RESOURCE_DIRS);
if (resources!=null) if (resources!=null && !resources.isEmpty())
{ {
Resource[] collection=new Resource[resources.size()+1]; Resource[] collection=new Resource[resources.size()+1];
int i=0; int i=0;