use of org.apache.tomee.jasper.TomEEJasperInitializer in project tomee by apache.
the class OpenEJBContextConfig method processServletContainerInitializers.
// called before processAnnotationsFile so using it as hook to init webInfClassesAnnotationsProcessed
@Override
protected void processServletContainerInitializers() {
try {
super.processServletContainerInitializers();
final Iterator<Map.Entry<ServletContainerInitializer, Set<Class<?>>>> iterator = initializerClassMap.entrySet().iterator();
while (iterator.hasNext()) {
final Map.Entry<ServletContainerInitializer, Set<Class<?>>> entry = iterator.next();
final ServletContainerInitializer sci = entry.getKey();
final String classname = sci.getClass().getName();
if (classname.equals("org.apache.myfaces.ee6.MyFacesContainerInitializer") || classname.equals("org.springframework.web.SpringServletContainerInitializer")) {
for (final Map.Entry<Class<?>, Set<ServletContainerInitializer>> scanning : typeInitializerMap.entrySet()) {
final Set<ServletContainerInitializer> scis = scanning.getValue();
if (scis != null && scis.contains(sci)) {
scis.remove(sci);
}
}
iterator.remove();
} else if ("org.apache.jasper.servlet.JasperInitializer".equals(classname)) {
iterator.remove();
}
}
initializerClassMap.put(new TomEEJasperInitializer(), new HashSet<Class<?>>());
final ClassLoader loader = context.getLoader().getClassLoader();
// spring-web (not scanned)
try {
final Class<?> initializer = Class.forName("org.springframework.web.SpringServletContainerInitializer", true, loader);
final ServletContainerInitializer instance = (ServletContainerInitializer) initializer.newInstance();
typeInitializerMap.put(Class.forName("org.springframework.web.WebApplicationInitializer", true, loader), Collections.singleton(instance));
initializerClassMap.put(instance, new HashSet<Class<?>>());
} catch (final Exception | NoClassDefFoundError ignored) {
// no-op
}
// scanned SCIs
if (typeInitializerMap.size() > 0 && finder != null) {
for (final Map.Entry<Class<?>, Set<ServletContainerInitializer>> entry : typeInitializerMap.entrySet()) {
if (entry.getValue() == null || entry.getValue().isEmpty()) {
continue;
}
final Class<?> annotation = entry.getKey();
for (final ServletContainerInitializer sci : entry.getValue()) {
if (annotation.isAnnotation()) {
try {
final Class<? extends Annotation> reloadedAnnotation = Class.class.cast(tempLoader.loadClass(annotation.getName()));
addClassesWithRightLoader(loader, sci, finder.findAnnotatedClasses(reloadedAnnotation));
} catch (final Throwable th) {
// no-op
}
} else {
try {
final Class<?> reloadedClass = tempLoader.loadClass(annotation.getName());
final List<Class<?>> implementations;
if (annotation.isInterface()) {
implementations = List.class.cast(finder.findImplementations(reloadedClass));
} else {
implementations = List.class.cast(finder.findSubclasses(reloadedClass));
}
addClassesWithRightLoader(loader, sci, implementations);
} catch (final Throwable th) {
// no-op
}
}
}
}
}
// done
finder = null;
tempLoader = null;
} catch (final RuntimeException e) {
// if exception occurs we have to clear the threadlocal
throw e;
}
}
Aggregations