use of org.apache.naming.resources.DirContextURLStreamHandler in project Payara by payara.
the class StandardContext method getResource.
/**
* Return the URL to the resource that is mapped to a specified path.
* The path must begin with a "/" and is interpreted as relative to the
* current context root.
*/
@Override
public java.net.URL getResource(String path) throws MalformedURLException {
if (path == null || !path.startsWith("/")) {
String msg = MessageFormat.format(rb.getString(LogFacade.INCORRECT_PATH), path);
throw new MalformedURLException(msg);
}
path = RequestUtil.normalize(path);
if (path == null)
return (null);
String libPath = "/WEB-INF/lib/";
if ((path.startsWith(libPath)) && (path.endsWith(".jar"))) {
File jarFile = null;
if (isFilesystemBased()) {
jarFile = new File(getBasePath(docBase), path);
} else {
jarFile = new File(getWorkPath(), path);
}
if (jarFile.exists()) {
return jarFile.toURL();
} else {
return null;
}
} else {
DirContext resources = null;
if (alternateDocBases == null || alternateDocBases.isEmpty()) {
resources = context.getResources();
} else {
AlternateDocBase match = AlternateDocBase.findMatch(path, alternateDocBases);
if (match != null) {
resources = ContextsAdapterUtility.unwrap(match.getResources());
} else {
// None of the url patterns for alternate doc bases matched
resources = getResources();
}
}
if (resources != null) {
String fullPath = getName() + path;
String hostName = getParent().getName();
try {
resources.lookup(path);
return new java.net.URL(// START SJAS 6318494
"jndi", "", 0, getJNDIUri(hostName, fullPath), // END SJSAS 6318494
new DirContextURLStreamHandler(resources));
} catch (Exception e) {
// do nothing
}
}
}
return (null);
}
Aggregations