Search in sources :

Example 1 with Timer

use of com.sun.faces.util.Timer in project mojarra by eclipse-ee4j.

the class DocumentOrderingWrapper method sort.

/**
 * Sort the provided array of <code>Document</code>s per the requirements of the 2.0 specification. Note, that this
 * method only provides partial ordering and not absolute ordering.
 * @param documents the documents to sort
 */
public static void sort(DocumentOrderingWrapper[] documents) {
    Timer t = Timer.getInstance();
    if (t != null) {
        t.startTiming();
    }
    try {
        enhanceOrderingData(documents);
    } catch (CircularDependencyException re) {
        String msg = "Circular dependencies detected!\nDocument Info\n==================\n";
        for (DocumentOrderingWrapper w : documents) {
            msg += "  " + w.toString() + '\n';
        }
        throw new ConfigurationException(msg);
    }
    // Sort the documents such that specified ordering will be considered.
    // 
    // It turns out that some of the specified ordering, if it was not discovered by the sort routine
    // until later in its processing, was not being considered correctly in the ordering algorithm.
    // 
    // This preSort method puts all of the documents with specified ordering as early on in the
    // list of documents as possible for Mojarra to consider it quickly, and be
    // able to use its ordering algorithm to the best of its ability.
    preSort(documents);
    // original inner sort algorithm
    int numberOfPasses = innerSort(documents);
    // final sort
    for (int i = 0; i < documents.length; i++) {
        LinkedList<String> ids = getIds(documents);
        if (done(documents, ids)) {
            break;
        }
    }
    if (t != null) {
        t.stopTiming();
        t.logResult("\"faces-config\" document sorting complete in " + numberOfPasses + '.');
    }
}
Also used : Timer(com.sun.faces.util.Timer) ConfigurationException(com.sun.faces.config.ConfigurationException)

Example 2 with Timer

use of com.sun.faces.util.Timer in project mojarra by eclipse-ee4j.

the class FindAnnotatedConfigClasses method call.

// ----------------------------------------------- Methods from Callable
@Override
public Map<Class<? extends Annotation>, Set<Class<?>>> call() throws Exception {
    Timer t = Timer.getInstance();
    if (t != null) {
        t.startTiming();
    }
    // We are executing on a different thread.
    facesContext.addInitContextEntryForCurrentThread();
    Set<URI> scanUris = null;
    com.sun.faces.spi.AnnotationScanner annotationScanner = metadataGetter.getAnnotationScanner();
    // This is where we discover what kind of InjectionProvider we have.
    if (provider instanceof FilterClassesFromFacesInitializerAnnotationProvider && annotationScanner != null) {
        // This InjectionProvider is capable of annotation scanning *and* injection.
        // Note that DelegatingAnnotationProvider itself doesn't use the provided scanner, but just uses the classes
        // that were already scanned by the ServletContainerInitializer and stored there.
        ((FilterClassesFromFacesInitializerAnnotationProvider) provider).setAnnotationScanner(annotationScanner, metadataGetter.getJarNames(annotatedSet));
        scanUris = emptySet();
    } else {
        // This InjectionProvider is capable of annotation scanning only
        scanUris = metadataGetter.getAnnotationScanURIs(annotatedSet);
    }
    // Note that DelegatingAnnotationProvider itself ignores the scanUris and directly gets the classes from the
    // ServletContext where they were stored by the ServletContainerInitializer
    Map<Class<? extends Annotation>, Set<Class<?>>> annotatedClasses = provider.getAnnotatedClasses(scanUris);
    if (t != null) {
        t.stopTiming();
        t.logResult("Configuration annotation scan complete.");
    }
    return annotatedClasses;
}
Also used : Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) Timer(com.sun.faces.util.Timer) URI(java.net.URI) FilterClassesFromFacesInitializerAnnotationProvider(com.sun.faces.config.manager.spi.FilterClassesFromFacesInitializerAnnotationProvider) Annotation(java.lang.annotation.Annotation)

Example 3 with Timer

use of com.sun.faces.util.Timer 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)

Example 4 with Timer

use of com.sun.faces.util.Timer in project mojarra by eclipse-ee4j.

the class Phase method doPhase.

// ---------------------------------------------------------- Public Methods
/**
 * Performs PhaseListener processing and invokes the execute method of the Phase.
 *
 * @param context the FacesContext for the current request
 * @param lifecycle the lifecycle for this request
 */
public void doPhase(FacesContext context, Lifecycle lifecycle, ListIterator<PhaseListener> listeners) {
    context.setCurrentPhaseId(getId());
    PhaseEvent event = null;
    if (listeners.hasNext()) {
        event = new PhaseEvent(context, getId(), lifecycle);
    }
    // start timing - include before and after phase processing
    Timer timer = Timer.getInstance();
    if (timer != null) {
        timer.startTiming();
    }
    try {
        handleBeforePhase(context, listeners, event);
        if (!shouldSkip(context)) {
            execute(context);
        }
    } catch (Throwable e) {
        queueException(context, e);
    } finally {
        try {
            handleAfterPhase(context, listeners, event);
        } catch (Throwable e) {
            queueException(context, e);
        }
        // stop timing
        if (timer != null) {
            timer.stopTiming();
            timer.logResult("Execution time for phase (including any PhaseListeners) -> " + getId().toString());
        }
        context.getExceptionHandler().handle();
    }
}
Also used : PhaseEvent(jakarta.faces.event.PhaseEvent) Timer(com.sun.faces.util.Timer)

Example 5 with Timer

use of com.sun.faces.util.Timer in project mojarra by eclipse-ee4j.

the class ParseConfigResourceToDOMTask method call.

// ----------------------------------------------- Methods from Callable
/**
 * @return the result of the parse operation (a DOM)
 * @throws Exception if an error occurs during the parsing process
 */
@Override
public DocumentInfo call() throws Exception {
    try {
        Timer timer = Timer.getInstance();
        if (timer != null) {
            timer.startTiming();
        }
        Document document = getDocument();
        if (timer != null) {
            timer.stopTiming();
            timer.logResult("Parse " + documentURI.toURL().toExternalForm());
        }
        return new DocumentInfo(document, documentURI);
    } catch (Exception e) {
        throw new ConfigurationException(format("Unable to parse document ''{0}'': {1}", documentURI.toURL().toExternalForm(), e.getMessage()), e);
    }
}
Also used : Timer(com.sun.faces.util.Timer) ConfigurationException(com.sun.faces.config.ConfigurationException) Document(org.w3c.dom.Document) ConfigurationException(com.sun.faces.config.ConfigurationException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) DocumentInfo(com.sun.faces.config.manager.documents.DocumentInfo)

Aggregations

Timer (com.sun.faces.util.Timer)5 ConfigurationException (com.sun.faces.config.ConfigurationException)2 ApplicationAssociate (com.sun.faces.application.ApplicationAssociate)1 WebappLifecycleListener (com.sun.faces.application.WebappLifecycleListener)1 DocumentInfo (com.sun.faces.config.manager.documents.DocumentInfo)1 FilterClassesFromFacesInitializerAnnotationProvider (com.sun.faces.config.manager.spi.FilterClassesFromFacesInitializerAnnotationProvider)1 ELContextImpl (com.sun.faces.el.ELContextImpl)1 PhaseEvent (jakarta.faces.event.PhaseEvent)1 ServletContext (jakarta.servlet.ServletContext)1 ServerContainer (jakarta.websocket.server.ServerContainer)1 IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1 URI (java.net.URI)1 Collections.emptySet (java.util.Collections.emptySet)1 Set (java.util.Set)1 Document (org.w3c.dom.Document)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1