import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
import javax.management.ObjectName;
-import javax.naming.Binding;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
/**
* Configure the repositories for our class loader, based on the
* associated Context.
+ * @throws IOException
*/
- private void setRepositories() {
+ private void setRepositories() throws IOException {
if (!(container instanceof Context))
return;
classRepository = new File(workDir, classesPath);
classRepository.mkdirs();
- copyDir(classes, classRepository);
+ if (!copyDir(classes, classRepository)) {
+ throw new IOException(
+ sm.getString("webappLoader.copyFailure"));
+ }
}
}
// Looking up directory /WEB-INF/lib in the context
+ NamingEnumeration<NameClassPair> enumeration = null;
try {
- NamingEnumeration<Binding> enumeration =
- resources.listBindings(libPath);
- while (enumeration.hasMoreElements()) {
-
- Binding binding = enumeration.nextElement();
- String filename = libPath + "/" + binding.getName();
- if (!filename.endsWith(".jar"))
- continue;
+ enumeration = libDir.list("");
+ } catch (NamingException e) {
+ IOException ioe = new IOException(sm.getString(
+ "webappLoader.namingFailure", libPath));
+ ioe.initCause(e);
+ throw ioe;
+ }
+ while (enumeration.hasMoreElements()) {
+ NameClassPair ncPair = enumeration.nextElement();
+ String filename = libPath + "/" + ncPair.getName();
+ if (!filename.endsWith(".jar"))
+ continue;
- // Copy JAR in the work directory, always (the JAR file
- // would get locked otherwise, which would make it
- // impossible to update it or remove it at runtime)
- File destFile = new File(destDir, binding.getName());
+ // Copy JAR in the work directory, always (the JAR file
+ // would get locked otherwise, which would make it
+ // impossible to update it or remove it at runtime)
+ File destFile = new File(destDir, ncPair.getName());
- if( log.isDebugEnabled())
- log.debug(sm.getString("webappLoader.jarDeploy", filename,
- destFile.getAbsolutePath()));
+ if( log.isDebugEnabled())
+ log.debug(sm.getString("webappLoader.jarDeploy", filename,
+ destFile.getAbsolutePath()));
- Object obj = binding.getObject();
-
- if (!(obj instanceof Resource))
- continue;
+ // Bug 45403 - Explicitly call lookup() on the name to check
+ // that the resource is readable. We cannot use resources
+ // returned by listBindings(), because that lists all of them,
+ // but does not perform the necessary checks on each.
+ Object obj = null;
+ try {
+ obj = libDir.lookup(ncPair.getName());
+ } catch (NamingException e) {
+ IOException ioe = new IOException(sm.getString(
+ "webappLoader.namingFailure", filename));
+ ioe.initCause(e);
+ throw ioe;
+ }
+
+ if (!(obj instanceof Resource))
+ continue;
- Resource jarResource = (Resource) obj;
+ Resource jarResource = (Resource) obj;
- if (copyJars) {
- if (!copy(jarResource.streamContent(),
- new FileOutputStream(destFile)))
- continue;
+ if (copyJars) {
+ if (!copy(jarResource.streamContent(),
+ new FileOutputStream(destFile))) {
+ throw new IOException(
+ sm.getString("webappLoader.copyFailure"));
}
+ }
- try {
- JarFile jarFile = new JarFile(destFile);
- classLoader.addJar(filename, jarFile, destFile);
- } catch (Exception ex) {
- // Catch the exception if there is an empty jar file
- // Should ignore and continute loading other jar files
- // in the dir
- }
-
- loaderRepositories.add( filename );
-
+ try {
+ JarFile jarFile = new JarFile(destFile);
+ classLoader.addJar(filename, jarFile, destFile);
+ } catch (Exception ex) {
+ // Catch the exception if there is an empty jar file
+ // Should ignore and continue loading other jar files
+ // in the dir
}
- } catch (NamingException e) {
- // Silent catch: it's valid that no /WEB-INF/lib directory
- // exists
- } catch (IOException e) {
- e.printStackTrace();
+
+ loaderRepositories.add( filename );
}
-
}
-
}