Search in sources :

Example 11 with ServletContainerInitializer

use of javax.servlet.ServletContainerInitializer in project wildfly by wildfly.

the class ServletContainerInitializerDeploymentProcessor method loadSci.

private List<ServletContainerInitializer> loadSci(ClassLoader classLoader, VirtualFile sci, String jar, boolean error, Set<Class<? extends ServletContainerInitializer>> sciClasses) throws DeploymentUnitProcessingException {
    final List<ServletContainerInitializer> scis = new ArrayList<ServletContainerInitializer>();
    InputStream is = null;
    try {
        // Get the ServletContainerInitializer class name
        is = sci.openStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
        String servletContainerInitializerClassName = reader.readLine();
        while (servletContainerInitializerClassName != null) {
            try {
                int pos = servletContainerInitializerClassName.indexOf('#');
                if (pos >= 0) {
                    servletContainerInitializerClassName = servletContainerInitializerClassName.substring(0, pos);
                }
                servletContainerInitializerClassName = servletContainerInitializerClassName.trim();
                if (!servletContainerInitializerClassName.isEmpty()) {
                    // Instantiate the ServletContainerInitializer
                    ServletContainerInitializer service = (ServletContainerInitializer) classLoader.loadClass(servletContainerInitializerClassName).newInstance();
                    if (service != null && sciClasses.add(service.getClass())) {
                        scis.add(service);
                    }
                }
                servletContainerInitializerClassName = reader.readLine();
            } catch (Exception e) {
                if (error) {
                    throw UndertowLogger.ROOT_LOGGER.errorProcessingSCI(jar, e);
                } else {
                    UndertowLogger.ROOT_LOGGER.skippedSCI(jar, e);
                }
            }
        }
    } catch (Exception e) {
        if (error) {
            throw UndertowLogger.ROOT_LOGGER.errorProcessingSCI(jar, e);
        } else {
            UndertowLogger.ROOT_LOGGER.skippedSCI(jar, e);
        }
    } finally {
        try {
            if (is != null)
                is.close();
        } catch (IOException e) {
        // Ignore
        }
    }
    return scis;
}
Also used : ServletContainerInitializer(javax.servlet.ServletContainerInitializer) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ModuleLoadException(org.jboss.modules.ModuleLoadException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) IOException(java.io.IOException)

Example 12 with ServletContainerInitializer

use of javax.servlet.ServletContainerInitializer in project tomee by apache.

the class OpenEJBContextConfig method webConfig.

@Override
protected void webConfig() {
    TomcatHelper.configureJarScanner(context);
    // read the real config
    super.webConfig();
    if (IgnoredStandardContext.class.isInstance(context)) {
        // no need of jsf
        return;
    }
    if (AppFinder.findAppContextOrWeb(context.getLoader().getClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE) != null) {
        final FilterDef asyncOwbFilter = new FilterDef();
        asyncOwbFilter.setAsyncSupported("true");
        asyncOwbFilter.setDescription("OpenEJB CDI Filter - to propagate @RequestScoped in async tasks");
        asyncOwbFilter.setDisplayName("OpenEJB CDI");
        asyncOwbFilter.setFilterClass(EEFilter.class.getName());
        asyncOwbFilter.setFilterName(EEFilter.class.getName());
        context.addFilterDef(asyncOwbFilter);
        final FilterMap asyncOwbMapping = new FilterMap();
        asyncOwbMapping.setFilterName(asyncOwbFilter.getFilterName());
        asyncOwbMapping.addURLPattern("/*");
        context.addFilterMap(asyncOwbMapping);
    }
    if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("tomee.jsp-development", "false"))) {
        for (final Container c : context.findChildren()) {
            if (Wrapper.class.isInstance(c)) {
                final Wrapper servlet = Wrapper.class.cast(c);
                if ("org.apache.jasper.servlet.JspServlet".equals(servlet.getServletClass())) {
                    servlet.addInitParameter("development", "true");
                }
            }
        }
    }
    final ClassLoader classLoader = context.getLoader().getClassLoader();
    // add myfaces auto-initializer if mojarra is not present
    try {
        classLoader.loadClass("com.sun.faces.context.SessionMap");
        return;
    } catch (final Throwable ignored) {
    // no-op
    }
    try {
        final Class<?> myfacesInitializer = Class.forName(MYFACES_TOMEEM_CONTAINER_INITIALIZER, true, classLoader);
        final ServletContainerInitializer instance = (ServletContainerInitializer) myfacesInitializer.newInstance();
        context.addServletContainerInitializer(instance, getJsfClasses(context));
        // cleanup listener
        context.addApplicationListener(TOMEE_MYFACES_CONTEXT_LISTENER);
    } catch (final Exception | NoClassDefFoundError ignored) {
    // no-op
    }
}
Also used : ServletContainerInitializer(javax.servlet.ServletContainerInitializer) Wrapper(org.apache.catalina.Wrapper) StandardWrapper(org.apache.catalina.core.StandardWrapper) Container(org.apache.catalina.Container) FilterDef(org.apache.tomcat.util.descriptor.web.FilterDef) EEFilter(org.apache.openejb.server.httpd.EEFilter) FilterMap(org.apache.tomcat.util.descriptor.web.FilterMap) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ClassFormatException(org.apache.tomcat.util.bcel.classfile.ClassFormatException)

Example 13 with ServletContainerInitializer

use of javax.servlet.ServletContainerInitializer in project Payara by payara.

the class StandardContext method callServletContainerInitializers.

protected void callServletContainerInitializers() throws LifecycleException {
    // Get the list of ServletContainerInitializers and the classes
    // they are interested in
    Map<Class<?>, List<Class<? extends ServletContainerInitializer>>> interestList = ServletContainerInitializerUtil.getInterestList(servletContainerInitializers);
    Map<Class<? extends ServletContainerInitializer>, Set<Class<?>>> initializerList = ServletContainerInitializerUtil.getInitializerList(servletContainerInitializers, interestList, getTypes(), getClassLoader(), isStandalone());
    if (initializerList == null) {
        return;
    }
    // Allow programmatic registration of ServletContextListeners, but
    // only within the scope of ServletContainerInitializer#onStartup
    isProgrammaticServletContextListenerRegistrationAllowed = true;
    // We have the list of initializers and the classes that satisfy the condition.
    // Time to call the initializers
    ServletContext ctxt = this.getServletContext();
    try {
        for (Map.Entry<Class<? extends ServletContainerInitializer>, Set<Class<?>>> e : initializerList.entrySet()) {
            Class<? extends ServletContainerInitializer> initializer = e.getKey();
            try {
                if (log.isLoggable(FINE)) {
                    log.log(FINE, "Calling ServletContainerInitializer [{0}] onStartup with classes {1}", new Object[] { initializer, e.getValue() });
                }
                ServletContainerInitializer iniInstance = initializer.newInstance();
                fireContainerEvent(BEFORE_CONTEXT_INITIALIZER_ON_STARTUP, iniInstance);
                iniInstance.onStartup(initializerList.get(initializer), ctxt);
                fireContainerEvent(AFTER_CONTEXT_INITIALIZER_ON_STARTUP, iniInstance);
            } catch (Throwable t) {
                log.log(SEVERE, format(rb.getString(INVOKING_SERVLET_CONTAINER_INIT_EXCEPTION), initializer.getCanonicalName()), t);
                throw new LifecycleException(t);
            }
        }
    } finally {
        isProgrammaticServletContextListenerRegistrationAllowed = false;
    }
}
Also used : ServletContainerInitializer(javax.servlet.ServletContainerInitializer) LifecycleException(org.apache.catalina.LifecycleException) EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) ServletContext(javax.servlet.ServletContext) ArrayList(java.util.ArrayList) List(java.util.List) FilterMap(org.apache.catalina.deploy.FilterMap) ServletMap(org.apache.catalina.deploy.ServletMap) Map(java.util.Map) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 14 with ServletContainerInitializer

use of javax.servlet.ServletContainerInitializer in project Payara by payara.

the class DynamicWebServletRegistrationImpl method start.

/**
 * Starts this web module.
 */
@Override
public synchronized void start() throws LifecycleException {
    // Get interestList of ServletContainerInitializers present, if any.
    List<Object> orderingList = null;
    boolean hasOthers = false;
    Map<String, String> webFragmentMap = Collections.emptyMap();
    if (webBundleDescriptor != null) {
        AbsoluteOrderingDescriptor aod = ((WebBundleDescriptorImpl) webBundleDescriptor).getAbsoluteOrderingDescriptor();
        if (aod != null) {
            orderingList = aod.getOrdering();
            hasOthers = aod.hasOthers();
        }
        webFragmentMap = webBundleDescriptor.getJarNameToWebFragmentNameMap();
    }
    boolean servletInitializersEnabled = true;
    if (webBundleDescriptor != null) {
        servletInitializersEnabled = webBundleDescriptor.getServletInitializersEnabled();
    }
    Iterable<ServletContainerInitializer> allInitializers = ServletContainerInitializerUtil.getServletContainerInitializers(webFragmentMap, orderingList, hasOthers, wmInfo.getAppClassLoader(), servletInitializersEnabled);
    setServletContainerInitializerInterestList(allInitializers);
    DeploymentContext dc = getWebModuleConfig().getDeploymentContext();
    if (dc != null) {
        directoryDeployed = Boolean.valueOf(dc.getAppProps().getProperty(ServerTags.DIRECTORY_DEPLOYED));
    }
    if (webBundleDescriptor != null) {
        showArchivedRealPathEnabled = webBundleDescriptor.isShowArchivedRealPathEnabled();
        servletReloadCheckSecs = webBundleDescriptor.getServletReloadCheckSecs();
        String reqEncoding = webBundleDescriptor.getRequestCharacterEncoding();
        if (reqEncoding != null) {
            setRequestCharacterEncoding(reqEncoding);
        }
        String resEncoding = webBundleDescriptor.getResponseCharacterEncoding();
        if (resEncoding != null) {
            setResponseCharacterEncoding(resEncoding);
        }
    }
    // Start and register Tomcat mbeans
    super.start();
    // Configure catalina listeners and valves. This can only happen
    // after this web module has been started, in order to be able to
    // load the specified listener and valve classes.
    configureValves();
    configureCatalinaProperties();
    webModuleStartedEvent();
    if (directoryListing) {
        setDirectoryListing(directoryListing);
    }
    hasStarted = true;
}
Also used : ServletContainerInitializer(javax.servlet.ServletContainerInitializer) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) WebBundleDescriptorImpl(org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl) AbsoluteOrderingDescriptor(org.glassfish.web.deployment.descriptor.AbsoluteOrderingDescriptor)

Example 15 with ServletContainerInitializer

use of javax.servlet.ServletContainerInitializer in project meecrowave by apache.

the class MeecrowaveContextConfig method processServletContainerInitializers.

@Override
protected void processServletContainerInitializers() {
    // use our finder
    if (!configuration.isTomcatScanning()) {
        return;
    }
    try {
        new WebappServiceLoader<ServletContainerInitializer>(context).load(ServletContainerInitializer.class).forEach(sci -> {
            final Set<Class<?>> classes = new HashSet<>();
            initializerClassMap.put(sci, classes);
            final HandlesTypes ht;
            try {
                ht = sci.getClass().getAnnotation(HandlesTypes.class);
            } catch (final Exception | NoClassDefFoundError e) {
                return;
            }
            if (ht == null) {
                return;
            }
            Stream.of(ht.value()).forEach(t -> {
                if (t.isAnnotation()) {
                    final Class<? extends Annotation> annotation = Class.class.cast(t);
                    classes.addAll(finder.findAnnotatedClasses(annotation));
                } else if (t.isInterface()) {
                    classes.addAll(finder.findImplementations(t));
                } else {
                    classes.addAll(finder.findSubclasses(t));
                }
            });
        });
    } catch (final IOException e) {
        ok = false;
    }
}
Also used : ServletContainerInitializer(javax.servlet.ServletContainerInitializer) WebappServiceLoader(org.apache.catalina.startup.WebappServiceLoader) IOException(java.io.IOException) HandlesTypes(javax.servlet.annotation.HandlesTypes) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

ServletContainerInitializer (javax.servlet.ServletContainerInitializer)25 IOException (java.io.IOException)10 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 Set (java.util.Set)8 File (java.io.File)7 MalformedURLException (java.net.MalformedURLException)6 HandlesTypes (javax.servlet.annotation.HandlesTypes)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 ServletContext (javax.servlet.ServletContext)5 LinkedHashMap (java.util.LinkedHashMap)4 LinkedHashSet (java.util.LinkedHashSet)4 List (java.util.List)4 Context (org.apache.catalina.Context)4 FilterMap (org.apache.catalina.deploy.FilterMap)4 Tomcat (org.apache.catalina.startup.Tomcat)4 InputStream (java.io.InputStream)3 TreeMap (java.util.TreeMap)3