Search in sources :

Example 1 with DirContextURLStreamHandler

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);
}
Also used : MalformedURLException(java.net.MalformedURLException) AlternateDocBase(org.glassfish.grizzly.http.server.util.AlternateDocBase) WARDirContext(org.apache.naming.resources.WARDirContext) BaseDirContext(org.apache.naming.resources.BaseDirContext) ProxyDirContext(org.apache.naming.resources.ProxyDirContext) DirContext(javax.naming.directory.DirContext) WebDirContext(org.apache.naming.resources.WebDirContext) FileDirContext(org.apache.naming.resources.FileDirContext) File(java.io.File) DirContextURLStreamHandler(org.apache.naming.resources.DirContextURLStreamHandler) LifecycleException(org.apache.catalina.LifecycleException) MalformedObjectNameException(javax.management.MalformedObjectNameException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) NamingException(javax.naming.NamingException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MalformedURLException(java.net.MalformedURLException)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 NamingException (javax.naming.NamingException)1 DirContext (javax.naming.directory.DirContext)1 ServletException (javax.servlet.ServletException)1 LifecycleException (org.apache.catalina.LifecycleException)1 BaseDirContext (org.apache.naming.resources.BaseDirContext)1 DirContextURLStreamHandler (org.apache.naming.resources.DirContextURLStreamHandler)1 FileDirContext (org.apache.naming.resources.FileDirContext)1 ProxyDirContext (org.apache.naming.resources.ProxyDirContext)1 WARDirContext (org.apache.naming.resources.WARDirContext)1 WebDirContext (org.apache.naming.resources.WebDirContext)1 AlternateDocBase (org.glassfish.grizzly.http.server.util.AlternateDocBase)1