483119 - CachingWebAppClassLoader breaks JSP

Cleaned up debugging and impl.  No fix for JSP problem
This commit is contained in:
Greg Wilkins 2015-11-27 10:38:43 +11:00
parent 81b2a6a4de
commit cea05f17d9
7 changed files with 41 additions and 73 deletions

View File

@ -62,6 +62,7 @@ public class OneWebAppWithJsp
+ warFile.getAbsolutePath() );
}
webapp.setWar( warFile.getAbsolutePath() );
webapp.setExtractWAR(true);
// This webapp will use jsps and jstl. We need to enable the
// AnnotationConfiguration in order to correctly
@ -100,6 +101,8 @@ public class OneWebAppWithJsp
// Start things up!
server.start();
server.dumpStdErr();
// The use of server.join() the will make the current thread join and
// wait until the server is done executing.

View File

@ -48,6 +48,12 @@
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>apache-jsp</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>

View File

@ -598,8 +598,6 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
if (_config==null)
_config=new Config();
// Handle run as
if (_identityService!=null)
{
@ -612,14 +610,11 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
initJspServlet();
detectJspContainer();
}
else if (_forcedPath != null)
detectJspContainer();
initMultiPart();
if (_forcedPath != null && _jspContainer == null)
{
detectJspContainer();
}
if (LOG.isDebugEnabled())
LOG.debug("Servlet.init {} for {}",_servlet,getName());
_servlet.init(_config);
@ -665,6 +660,8 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
/* Set the webapp's classpath for Jasper */
ch.setAttribute("org.apache.catalina.jsp_classpath", ch.getClassPath());
System.err.println("JSP ("+ch+","+getName()+") CP="+ch.getClassPath());
/* Set up other classpath attribute */
if ("?".equals(getInitParameter("classpath")))
{

View File

@ -18,15 +18,11 @@
package org.eclipse.jetty.util;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.jetty.util.resource.Resource;
/* ------------------------------------------------------------ */
/** ClassLoader Helper.
* This helper class allows classes to be loaded either from the
@ -86,7 +82,6 @@ public class Loader
return loadClass(name);
}
/* ------------------------------------------------------------ */
public static ResourceBundle getResourceBundle(String name,boolean checkParents,Locale locale)
throws MissingResourceException
@ -94,40 +89,5 @@ public class Loader
ClassLoader loader=Thread.currentThread().getContextClassLoader();
return loader==null ? ResourceBundle.getBundle(name, locale) : ResourceBundle.getBundle(name, locale, loader);
}
/* ------------------------------------------------------------ */
/**
* Generate the classpath (as a string) of all classloaders
* above the given classloader.
*
* This is primarily used for jasper.
* @param loader the classloader to use
* @return the system class path
* @throws Exception if unable to generate the classpath from the resource references
*/
public static String getClassPath(ClassLoader loader) throws Exception
{
StringBuilder classpath=new StringBuilder();
while (loader != null && (loader instanceof URLClassLoader))
{
URL[] urls = ((URLClassLoader)loader).getURLs();
if (urls != null)
{
for (int i=0;i<urls.length;i++)
{
Resource resource = Resource.newResource(urls[i]);
File file=resource.getFile();
if (file!=null && file.exists())
{
if (classpath.length()>0)
classpath.append(File.pathSeparatorChar);
classpath.append(file.getAbsolutePath());
}
}
}
loader = loader.getParent();
}
return classpath.toString();
}
}

View File

@ -25,6 +25,8 @@ import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.ManagedOperation;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
@ -36,6 +38,8 @@ import org.eclipse.jetty.util.annotation.ManagedOperation;
@ManagedObject
public class CachingWebAppClassLoader extends WebAppClassLoader
{
private static final Logger LOG = Log.getLogger(CachingWebAppClassLoader.class);
private final ConcurrentHashSet<String> _notFound = new ConcurrentHashSet<>();
private final ConcurrentHashMap<String,URL> _cache = new ConcurrentHashMap<>();
@ -53,7 +57,11 @@ public class CachingWebAppClassLoader extends WebAppClassLoader
public URL getResource(String name)
{
if (_notFound.contains(name))
{
if (LOG.isDebugEnabled())
LOG.debug("Not found cache hit resource {}",name);
return null;
}
URL url = _cache.get(name);
@ -63,6 +71,8 @@ public class CachingWebAppClassLoader extends WebAppClassLoader
if (url==null)
{
if (LOG.isDebugEnabled())
LOG.debug("Caching not found resource {}",name);
_notFound.add(name);
}
else
@ -75,33 +85,26 @@ public class CachingWebAppClassLoader extends WebAppClassLoader
}
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
public Class<?> loadClass(String name) throws ClassNotFoundException
{
if (_notFound.contains(name))
{
if (LOG.isDebugEnabled())
LOG.debug("Not found cache hit resource {}",name);
throw new ClassNotFoundException(name+": in notfound cache");
}
try
{
return super.loadClass(name,resolve);
return super.loadClass(name);
}
catch (ClassNotFoundException nfe)
{
_notFound.add(name);
throw nfe;
}
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException
{
if (_notFound.contains(name))
throw new ClassNotFoundException(name+": in notfound cache");
try
{
return super.findClass(name);
}
catch (ClassNotFoundException nfe)
{
_notFound.add(name);
if (_notFound.add(name))
if (LOG.isDebugEnabled())
{
LOG.debug("Caching not found {}",name);
LOG.debug(nfe);
}
throw nfe;
}
}

View File

@ -450,13 +450,6 @@ public class WebAppClassLoader extends URLClassLoader
return url;
}
/* ------------------------------------------------------------ */
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException
{
return loadClass(name, false);
}
/* ------------------------------------------------------------ */
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
@ -526,7 +519,11 @@ public class WebAppClassLoader extends URLClassLoader
LOG.debug("loadedClass({})=={} from={} tried_parent={}",name,c,source,tried_parent);
if (resolve)
{
resolveClass(c);
if (LOG.isDebugEnabled())
LOG.debug("resolved({})=={} from={} tried_parent={}",name,c,source,tried_parent);
}
return c;
}

View File

@ -42,11 +42,13 @@ detected.
</Set>
<!-- Set Caching Classloader that improves performance on resource searching webapps -->
<!--
<Set name="classLoader">
<New class="org.eclipse.jetty.webapp.CachingWebAppClassLoader">
<Arg><Ref refid="testWebapp"/></Arg>
</New>
</Set>
-->
<!-- Enable symlinks
<Call name="addAliasCheck">