log.trace("No loader, reset filePath = " + filePath);
loader = Thread.currentThread().getContextClassLoader();
}
log.trace("loader = " + loader);
byte[] bytes = {};
SwitchContext tclSwitchContext = null;
try
{
tclSwitchContext = this.tclSwitcher.getSwitchContext(this.getClass().getClassLoader());
if (loader != null && filePath.endsWith(".class"))
{
// A request for a class file
String className = filePath.substring(0, filePath.length() - 6).replace('/', '.');
log.trace("loading className = " + className);
Class<?> clazz = loader.loadClass(className);
URL clazzUrl = clazz.getProtectionDomain().getCodeSource().getLocation();
log.trace("clazzUrl = " + clazzUrl);
if (clazzUrl == null)
{
// Does the WebClassLoader of clazz
// have the ability to obtain the bytecodes of clazz?
bytes = ((WebClassLoader) clazz.getClassLoader()).getBytes(clazz);
if (bytes == null)
throw new Exception("Class not found: " + className);
}
else
{
if (clazzUrl.getFile().endsWith("/") == false)
{
clazzUrl = new URL("jar:" + clazzUrl + "!/" + filePath);
}
// this is a hack for the AOP ClassProxyFactory
else if (clazzUrl.getFile().indexOf("/org_jboss_aop_proxy$") < 0)
{
clazzUrl = new URL(clazzUrl, filePath);
}
// Retrieve bytecodes
log.trace("new clazzUrl: " + clazzUrl);
bytes = getBytes(clazzUrl);
}
}
else if (loader != null && filePath.length() > 0 && downloadServerClasses && downloadResources)
{
// Try getting resource
log.trace("loading resource = " + filePath);
URL resourceURL = loader.getResource(filePath);
if (resourceURL == null)
httpCode = "404 Resource not found:" + filePath;
else
{
// Retrieve bytes
log.trace("resourceURL = " + resourceURL);
bytes = getBytes(resourceURL);
}
}
else
{
httpCode = "404 Not Found";
}
}
finally
{
if (tclSwitchContext != null)
{
tclSwitchContext.reset();
}
}
// Send bytecodes/resource data in response (assumes HTTP/1.0 or later)