Search in sources :

Example 1 with ClassFormatException

use of org.apache.tomcat.util.bcel.classfile.ClassFormatException 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)

Example 2 with ClassFormatException

use of org.apache.tomcat.util.bcel.classfile.ClassFormatException in project tomcat by apache.

the class ContextConfig method processAnnotationsJar.

protected void processAnnotationsJar(URL url, WebXml fragment, boolean handlesTypesOnly, Map<String, JavaClassCacheEntry> javaClassCache) {
    try (Jar jar = JarFactory.newInstance(url)) {
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("contextConfig.processAnnotationsJar.debug", url));
        }
        jar.nextEntry();
        String entryName = jar.getEntryName();
        while (entryName != null) {
            if (entryName.endsWith(".class")) {
                try (InputStream is = jar.getEntryInputStream()) {
                    processAnnotationsStream(is, fragment, handlesTypesOnly, javaClassCache);
                } catch (IOException | ClassFormatException e) {
                    log.error(sm.getString("contextConfig.inputStreamJar", entryName, url), e);
                }
            }
            jar.nextEntry();
            entryName = jar.getEntryName();
        }
    } catch (IOException e) {
        log.error(sm.getString("contextConfig.jarFile", url), e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Jar(org.apache.tomcat.Jar) IOException(java.io.IOException) ClassFormatException(org.apache.tomcat.util.bcel.classfile.ClassFormatException)

Example 3 with ClassFormatException

use of org.apache.tomcat.util.bcel.classfile.ClassFormatException in project tomcat70 by apache.

the class ContextConfig method populateJavaClassCache.

private void populateJavaClassCache(String className) {
    if (!javaClassCache.containsKey(className)) {
        String name = className.replace('.', '/') + ".class";
        InputStream is = context.getLoader().getClassLoader().getResourceAsStream(name);
        if (is == null) {
            return;
        }
        ClassParser parser = new ClassParser(is);
        try {
            JavaClass clazz = parser.parse();
            populateJavaClassCache(clazz.getClassName(), clazz);
        } catch (ClassFormatException e) {
            log.debug(sm.getString("contextConfig.invalidSciHandlesTypes", className), e);
        } catch (IOException e) {
            log.debug(sm.getString("contextConfig.invalidSciHandlesTypes", className), e);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
}
Also used : JavaClass(org.apache.tomcat.util.bcel.classfile.JavaClass) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ClassParser(org.apache.tomcat.util.bcel.classfile.ClassParser) ClassFormatException(org.apache.tomcat.util.bcel.classfile.ClassFormatException)

Example 4 with ClassFormatException

use of org.apache.tomcat.util.bcel.classfile.ClassFormatException in project tomcat70 by apache.

the class ContextConfig method processAnnotationsJar.

protected void processAnnotationsJar(URL url, WebXml fragment, boolean handlesTypesOnly) {
    Jar jar = null;
    InputStream is;
    try {
        jar = JarFactory.newInstance(url);
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("contextConfig.processAnnotationsJar.debug", url));
        }
        jar.nextEntry();
        String entryName = jar.getEntryName();
        while (entryName != null) {
            if (entryName.endsWith(".class")) {
                is = null;
                try {
                    is = jar.getEntryInputStream();
                    processAnnotationsStream(is, fragment, handlesTypesOnly);
                } catch (IOException e) {
                    log.error(sm.getString("contextConfig.inputStreamJar", entryName, url), e);
                } catch (ClassFormatException e) {
                    log.error(sm.getString("contextConfig.inputStreamJar", entryName, url), e);
                } finally {
                    if (is != null) {
                        try {
                            is.close();
                        } catch (IOException ioe) {
                        // Ignore
                        }
                    }
                }
            }
            jar.nextEntry();
            entryName = jar.getEntryName();
        }
    } catch (IOException e) {
        log.error(sm.getString("contextConfig.jarFile", url), e);
    } finally {
        if (jar != null) {
            jar.close();
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Jar(org.apache.tomcat.util.scan.Jar) IOException(java.io.IOException) ClassFormatException(org.apache.tomcat.util.bcel.classfile.ClassFormatException)

Example 5 with ClassFormatException

use of org.apache.tomcat.util.bcel.classfile.ClassFormatException in project tomcat by apache.

the class ContextConfig method populateJavaClassCache.

private void populateJavaClassCache(String className, Map<String, JavaClassCacheEntry> javaClassCache) {
    if (!javaClassCache.containsKey(className)) {
        String name = className.replace('.', '/') + ".class";
        try (InputStream is = context.getLoader().getClassLoader().getResourceAsStream(name)) {
            if (is == null) {
                return;
            }
            ClassParser parser = new ClassParser(is);
            JavaClass clazz = parser.parse();
            populateJavaClassCache(clazz.getClassName(), clazz, javaClassCache);
        } catch (ClassFormatException | IOException e) {
            log.debug(sm.getString("contextConfig.invalidSciHandlesTypes", className), e);
        }
    }
}
Also used : JavaClass(org.apache.tomcat.util.bcel.classfile.JavaClass) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ClassParser(org.apache.tomcat.util.bcel.classfile.ClassParser) ClassFormatException(org.apache.tomcat.util.bcel.classfile.ClassFormatException)

Aggregations

FileInputStream (java.io.FileInputStream)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 ClassFormatException (org.apache.tomcat.util.bcel.classfile.ClassFormatException)5 ClassParser (org.apache.tomcat.util.bcel.classfile.ClassParser)2 JavaClass (org.apache.tomcat.util.bcel.classfile.JavaClass)2 JarURLConnection (java.net.JarURLConnection)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 DirContextURLConnection (org.apache.naming.resources.DirContextURLConnection)1 Jar (org.apache.tomcat.Jar)1 Jar (org.apache.tomcat.util.scan.Jar)1