public static synchronized boolean validateApplication(DirContext dirContext,
StandardContext context) throws IOException {
// ----------------------------------------------------- Static Initializer
// check for container level optional packages
String systemClasspath = System.getProperty("java.class.path");
StringTokenizer strTok = new StringTokenizer(systemClasspath,
File.pathSeparator);
// build a list of jar files in the classpath
while (strTok.hasMoreTokens()) {
String classpathItem = strTok.nextToken();
if (classpathItem.toLowerCase().endsWith(".jar")) {
File item = new File(classpathItem);
if (item.exists()) {
try {
addSystemResource(item);
} catch (IOException e) {
log.error(sm.getString
("extensionValidator.failload", item), e);
}
}
}
}
// add specified folders to the list
addFolderList("java.ext.dirs");
addFolderList("catalina.ext.dirs");
String appName = context.getPath();
ArrayList appManifestResources = new ArrayList();
// If the application context is null it does not exist and
// therefore is not valid
if (dirContext == null) return false;
// Find the Manifest for the Web Applicaiton
InputStream inputStream = null;
try {
NamingEnumeration wne = dirContext.listBindings("/META-INF/");
Binding binding = (Binding) wne.nextElement();
if (binding.getName().toUpperCase().equals("MANIFEST.MF")) {
Resource resource = (Resource)dirContext.lookup
("/META-INF/" + binding.getName());
inputStream = resource.streamContent();
Manifest manifest = new Manifest(inputStream);
inputStream.close();
inputStream = null;
ManifestResource mre = new ManifestResource
(sm.getString("extensionValidator.web-application-manifest"),
manifest, ManifestResource.WAR);
appManifestResources.add(mre);
}
} catch (NamingException nex) {
// Application does not contain a MANIFEST.MF file
} catch (NoSuchElementException nse) {
// Application does not contain a MANIFEST.MF file
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (Throwable t) {
// Ignore
}
}
}
// Locate the Manifests for all bundled JARs
NamingEnumeration ne = null;
try {
if (dirContext != null) {
ne = dirContext.listBindings("WEB-INF/lib/");
}
while ((ne != null) && ne.hasMoreElements()) {
Binding binding = (Binding)ne.nextElement();
if (!binding.getName().toLowerCase().endsWith(".jar")) {
continue;
}
Resource resource = (Resource)dirContext.lookup
("/WEB-INF/lib/" + binding.getName());
Manifest jmanifest = getManifest(resource.streamContent());
if (jmanifest != null) {
ManifestResource mre = new ManifestResource(
binding.getName(),
jmanifest,
ManifestResource.APPLICATION);
appManifestResources.add(mre);
}
}
} catch (NamingException nex) {
// Jump out of the check for this application because it
// has no resources
}
return validateManifestResources(appName, appManifestResources);
}
Runtime validation of a Web Applicaiton.
This method uses JNDI to look up the resources located under a
DirContext. It locates Web Application MANIFEST.MF
file in the /META-INF/ directory of the application and all
MANIFEST.MF files in each JAR file located in the WEB-INF/lib
directory and creates an ArrayList of
ManifestResorce objects. These objects are then passed
to the validateManifestResources method for validation. |