Search in sources :

Example 1 with ELContextImpl

use of com.sun.faces.el.ELContextImpl in project mojarra by eclipse-ee4j.

the class FacesContextImpl method getELContext.

/**
 * @see jakarta.faces.context.FacesContext#getELContext()
 */
@Override
public ELContext getELContext() {
    assertNotReleased();
    if (elContext == null) {
        elContext = new ELContextImpl(FacesContext.getCurrentInstance());
        ELContextListener[] listeners = getApplication().getELContextListeners();
        if (listeners.length > 0) {
            ELContextEvent event = new ELContextEvent(elContext);
            for (ELContextListener listener : listeners) {
                listener.contextCreated(event);
            }
        }
    }
    return elContext;
}
Also used : ELContextListener(jakarta.el.ELContextListener) ELContextImpl(com.sun.faces.el.ELContextImpl) ELContextEvent(jakarta.el.ELContextEvent)

Example 2 with ELContextImpl

use of com.sun.faces.el.ELContextImpl in project mojarra by eclipse-ee4j.

the class ConfigManager method publishPostConfigEvent.

/**
 * Publishes a {@link jakarta.faces.event.PostConstructApplicationEvent} event for the current {@link Application}
 * instance.
 */
void publishPostConfigEvent() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Application application = facesContext.getApplication();
    if (((InitFacesContext) facesContext).getELContext() == null) {
        ELContext elContext = new ELContextImpl(facesContext);
        ELContextListener[] listeners = application.getELContextListeners();
        if (listeners.length > 0) {
            ELContextEvent event = new ELContextEvent(elContext);
            for (ELContextListener listener : listeners) {
                listener.contextCreated(event);
            }
        }
        ((InitFacesContext) facesContext).setELContext(elContext);
    }
    application.publishEvent(facesContext, PostConstructApplicationEvent.class, Application.class, application);
}
Also used : FacesContext(jakarta.faces.context.FacesContext) ELContext(jakarta.el.ELContext) ELContextListener(jakarta.el.ELContextListener) ELContextImpl(com.sun.faces.el.ELContextImpl) ELContextEvent(jakarta.el.ELContextEvent) Application(jakarta.faces.application.Application)

Example 3 with ELContextImpl

use of com.sun.faces.el.ELContextImpl in project mojarra by eclipse-ee4j.

the class ConfigureListener method contextDestroyed.

@Override
public void contextDestroyed(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    ConfigManager configManager = ConfigManager.getInstance(context);
    // The additional check for a WebConfiguration instance was added at the request of JBoss
    if (configManager == null && WebConfiguration.getInstanceWithoutCreating(context) != null) {
        LOGGER.log(WARNING, "Unexpected state during contextDestroyed: no ConfigManager instance in current ServletContext but one is expected to exist.");
    }
    InitFacesContext initContext = null;
    try {
        initContext = getInitFacesContext(context);
        if (initContext == null) {
            initContext = new InitFacesContext(context);
        } else {
            InitFacesContext.getThreadInitContextMap().put(Thread.currentThread(), initContext);
        }
        if (webAppListener != null) {
            webAppListener.contextDestroyed(sce);
            webAppListener = null;
        }
        if (webResourcePool != null) {
            webResourcePool.shutdownNow();
        }
        if (LOGGER.isLoggable(FINE)) {
            LOGGER.log(FINE, "ConfigureListener.contextDestroyed({0})", context.getServletContextName());
        }
        if (configManager == null || !configManager.hasBeenInitialized(context)) {
            return;
        }
        ApplicationAssociate associate = ApplicationAssociate.getInstance(context);
        if (associate != null) {
            associate.setExpressionFactory(ELManager.getExpressionFactory());
        }
        initContext.setELContext(new ELContextImpl(initContext));
        Application application = initContext.getApplication();
        application.publishEvent(initContext, PreDestroyApplicationEvent.class, Application.class, application);
    } catch (Exception e) {
        LOGGER.log(SEVERE, "Unexpected exception when attempting to tear down the Mojarra runtime", e);
    } finally {
        ApplicationAssociate.clearInstance(context);
        ApplicationAssociate.setCurrentInstance(null);
        // Release the initialization mark on this web application
        if (configManager != null) {
            configManager.destroy(context, initContext);
            ConfigManager.removeInstance(context);
        } else if (WebConfiguration.getInstanceWithoutCreating(context) != null && LOGGER.isLoggable(WARNING)) {
            LOGGER.log(WARNING, "Unexpected state during contextDestroyed: no ConfigManager instance in current ServletContext but one is expected to exist.");
        }
        FactoryFinder.releaseFactories();
        ReflectionUtils.clearCache(Thread.currentThread().getContextClassLoader());
        WebConfiguration.clear(context);
        InitFacesContext.cleanupInitMaps(context);
    }
}
Also used : ApplicationAssociate(com.sun.faces.application.ApplicationAssociate) ServletContext(jakarta.servlet.ServletContext) ELContextImpl(com.sun.faces.el.ELContextImpl) Application(jakarta.faces.application.Application) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 4 with ELContextImpl

use of com.sun.faces.el.ELContextImpl in project mojarra by eclipse-ee4j.

the class ConfigureListener method contextInitialized.

// ------------------------------------------ ServletContextListener Methods
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    ServletContext servletContext = servletContextEvent.getServletContext();
    Timer timer = Timer.getInstance();
    if (timer != null) {
        timer.startTiming();
    }
    ConfigManager configManager = ConfigManager.getInstance(servletContext);
    if (configManager == null) {
        configManager = ConfigManager.createInstance(servletContext);
    }
    if (configManager.hasBeenInitialized(servletContext)) {
        return;
    }
    InitFacesContext initFacesContext = new InitFacesContext(servletContext);
    LOGGER.log(FINE, () -> format("ConfigureListener.contextInitialized({0})", servletContext.getContextPath()));
    webConfig = WebConfiguration.getInstance(servletContext);
    // Check to see if the FacesServlet is present in the
    // web.xml. If it is, perform faces configuration as normal,
    // otherwise, simply return.
    // If found by FacesInitializer.
    Object facesServletRegistration = servletContext.getAttribute(FACES_SERVLET_REGISTRATION);
    WebXmlProcessor webXmlProcessor = new WebXmlProcessor(servletContext);
    if (facesServletRegistration == null) {
        if (!webXmlProcessor.isFacesServletPresent()) {
            if (!webConfig.isOptionEnabled(ForceLoadFacesConfigFiles)) {
                LOGGER.log(FINE, "No FacesServlet found in deployment descriptor - bypassing configuration");
                WebConfiguration.clear(servletContext);
                configManager.destroy(servletContext, initFacesContext);
                ConfigManager.removeInstance(servletContext);
                InitFacesContext.cleanupInitMaps(servletContext);
                return;
            }
        } else {
            LOGGER.log(FINE, "FacesServlet found in deployment descriptor - processing configuration.");
        }
    }
    if (webXmlProcessor.isDistributablePresent()) {
        webConfig.setOptionEnabled(WebConfiguration.BooleanWebContextInitParameter.EnableDistributable, true);
        servletContext.setAttribute(WebConfiguration.BooleanWebContextInitParameter.EnableDistributable.getQualifiedName(), TRUE);
    }
    // Bootstrap of faces required
    webAppListener = new WebappLifecycleListener(servletContext);
    webAppListener.contextInitialized(servletContextEvent);
    ReflectionUtils.initCache(Thread.currentThread().getContextClassLoader());
    Throwable caughtThrowable = null;
    try {
        if (LOGGER.isLoggable(INFO)) {
            LOGGER.log(INFO, "faces.config.listener.version", servletContext.getContextPath());
        }
        if (webConfig.isOptionEnabled(VerifyFacesConfigObjects)) {
            LOGGER.warning("JSF1059: WARNING!  The com.sun.faces.verifyObjects feature is to aid developers not using tools.  " + "It shouldn't be enabled if using an IDE, or if this application is being deployed for production as it " + "will impact application start times.");
            // If we're verifying, force bean validation to occur at startup as well
            webConfig.overrideContextInitParameter(EnableLazyBeanValidation, false);
            Verifier.setCurrentInstance(new Verifier());
        }
        configManager.initialize(servletContext, initFacesContext);
        if (shouldInitConfigMonitoring()) {
            initConfigMonitoring(servletContext);
        }
        // Step 7, verify that all the configured factories are available
        // and optionally that configured objects can be created.
        Verifier verifier = Verifier.getCurrentInstance();
        if (verifier != null && !verifier.isApplicationValid() && LOGGER.isLoggable(SEVERE)) {
            LOGGER.severe("faces.config.verifyobjects.failures_detected");
            StringBuilder sb = new StringBuilder(128);
            for (String msg : verifier.getMessages()) {
                sb.append(msg).append('\n');
            }
            LOGGER.severe(sb.toString());
        }
        ApplicationAssociate associate = ApplicationAssociate.getInstance(servletContext);
        if (associate != null) {
            associate.setExpressionFactory(ELManager.getExpressionFactory());
        }
        initFacesContext.setELContext(new ELContextImpl(initFacesContext));
        if (associate != null) {
            associate.setContextName(servletContext.getContextPath());
            boolean isErrorPagePresent = webXmlProcessor.isErrorPagePresent();
            associate.setErrorPagePresent(isErrorPagePresent);
            servletContext.setAttribute(ERROR_PAGE_PRESENT_KEY_NAME, isErrorPagePresent);
        }
        // Note: websocket channel filter is registered in FacesInitializer.
        if (webConfig.isOptionEnabled(EnableWebsocketEndpoint)) {
            ServerContainer serverContainer = (ServerContainer) servletContext.getAttribute(ServerContainer.class.getName());
            if (serverContainer == null) {
                throw new UnsupportedOperationException("Cannot enable f:websocket." + " The current websocket container implementation does not support programmatically registering a container-provided endpoint.");
            }
            serverContainer.addEndpoint(ServerEndpointConfig.Builder.create(WebsocketEndpoint.class, URI_TEMPLATE).build());
        }
        webConfig.doPostBringupActions();
        configManager.publishPostConfigEvent();
    } catch (Throwable t) {
        LOGGER.log(SEVERE, "Critical error during deployment: ", t);
        caughtThrowable = t;
    } finally {
        servletContextEvent.getServletContext().removeAttribute(ANNOTATED_CLASSES);
        servletContextEvent.getServletContext().removeAttribute(FACES_SERVLET_MAPPINGS);
        Verifier.setCurrentInstance(null);
        LOGGER.log(FINE, "faces.config.listener.version.complete");
        if (timer != null) {
            timer.stopTiming();
            timer.logResult("Initialization of context " + servletContext.getContextPath());
        }
        if (caughtThrowable != null) {
            throw new RuntimeException(caughtThrowable);
        }
        // Bug 20458755: The InitFacesContext was not being cleaned up, resulting in
        // a partially constructed FacesContext being made available
        // to other code that re-uses this Thread at init time.
        initFacesContext.releaseCurrentInstance();
    }
}
Also used : WebappLifecycleListener(com.sun.faces.application.WebappLifecycleListener) ApplicationAssociate(com.sun.faces.application.ApplicationAssociate) Timer(com.sun.faces.util.Timer) ServletContext(jakarta.servlet.ServletContext) ELContextImpl(com.sun.faces.el.ELContextImpl) ServerContainer(jakarta.websocket.server.ServerContainer)

Aggregations

ELContextImpl (com.sun.faces.el.ELContextImpl)4 ApplicationAssociate (com.sun.faces.application.ApplicationAssociate)2 ELContextEvent (jakarta.el.ELContextEvent)2 ELContextListener (jakarta.el.ELContextListener)2 Application (jakarta.faces.application.Application)2 ServletContext (jakarta.servlet.ServletContext)2 WebappLifecycleListener (com.sun.faces.application.WebappLifecycleListener)1 Timer (com.sun.faces.util.Timer)1 ELContext (jakarta.el.ELContext)1 FacesContext (jakarta.faces.context.FacesContext)1 ServerContainer (jakarta.websocket.server.ServerContainer)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXException (org.xml.sax.SAXException)1