Search in sources :

Example 1 with TomEEJasperInitializer

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;
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ClassFormatException(org.apache.tomcat.util.bcel.classfile.ClassFormatException) ServletContainerInitializer(javax.servlet.ServletContainerInitializer) AnnotationEntry(org.apache.tomcat.util.bcel.classfile.AnnotationEntry) TomEEJasperInitializer(org.apache.tomee.jasper.TomEEJasperInitializer) JavaClass(org.apache.tomcat.util.bcel.classfile.JavaClass) List(java.util.List) ArrayList(java.util.ArrayList) FilterMap(org.apache.tomcat.util.descriptor.web.FilterMap) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ServletContainerInitializer (javax.servlet.ServletContainerInitializer)1 AnnotationEntry (org.apache.tomcat.util.bcel.classfile.AnnotationEntry)1 ClassFormatException (org.apache.tomcat.util.bcel.classfile.ClassFormatException)1 JavaClass (org.apache.tomcat.util.bcel.classfile.JavaClass)1 FilterMap (org.apache.tomcat.util.descriptor.web.FilterMap)1 TomEEJasperInitializer (org.apache.tomee.jasper.TomEEJasperInitializer)1