Search in sources :

Example 1 with DirContextURLConnection

use of org.apache.naming.resources.DirContextURLConnection in project tomcat70 by apache.

the class ContextConfig method processAnnotationsJndi.

protected void processAnnotationsJndi(URL url, WebXml fragment, boolean handlesTypesOnly) {
    try {
        URLConnection urlConn = url.openConnection();
        DirContextURLConnection dcUrlConn;
        if (!(urlConn instanceof DirContextURLConnection)) {
            // This should never happen
            sm.getString("contextConfig.jndiUrlNotDirContextConn", url);
            return;
        }
        dcUrlConn = (DirContextURLConnection) urlConn;
        dcUrlConn.setUseCaches(false);
        String type = dcUrlConn.getHeaderField(ResourceAttributes.TYPE);
        if (ResourceAttributes.COLLECTION_TYPE.equals(type)) {
            // Collection
            Enumeration<String> dirs = dcUrlConn.list();
            if (log.isDebugEnabled() && dirs.hasMoreElements()) {
                log.debug(sm.getString("contextConfig.processAnnotationsWebDir.debug", url));
            }
            while (dirs.hasMoreElements()) {
                String dir = dirs.nextElement();
                URL dirUrl = new URL(url.toString() + '/' + dir);
                processAnnotationsJndi(dirUrl, fragment, handlesTypesOnly);
            }
        } else {
            // Single file
            if (url.getPath().endsWith(".class")) {
                InputStream is = null;
                try {
                    is = dcUrlConn.getInputStream();
                    processAnnotationsStream(is, fragment, handlesTypesOnly);
                } catch (IOException e) {
                    log.error(sm.getString("contextConfig.inputStreamJndi", url), e);
                } catch (ClassFormatException e) {
                    log.error(sm.getString("contextConfig.inputStreamJndi", url), e);
                } finally {
                    if (is != null) {
                        try {
                            is.close();
                        } catch (Throwable t) {
                            ExceptionUtils.handleThrowable(t);
                        }
                    }
                }
            }
        }
    } catch (IOException e) {
        log.error(sm.getString("contextConfig.jndiUrl", url), e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DirContextURLConnection(org.apache.naming.resources.DirContextURLConnection) IOException(java.io.IOException) DirContextURLConnection(org.apache.naming.resources.DirContextURLConnection) JarURLConnection(java.net.JarURLConnection) URLConnection(java.net.URLConnection) URL(java.net.URL) ClassFormatException(org.apache.tomcat.util.bcel.classfile.ClassFormatException)

Aggregations

FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 JarURLConnection (java.net.JarURLConnection)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 DirContextURLConnection (org.apache.naming.resources.DirContextURLConnection)1 ClassFormatException (org.apache.tomcat.util.bcel.classfile.ClassFormatException)1