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);
}
}
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);
}
}
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
}
}
}
}
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();
}
}
}
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);
}
}
}
Aggregations