diff --git a/impl/src/main/java/com/sun/faces/config/ConfigureListener.java b/impl/src/main/java/com/sun/faces/config/ConfigureListener.java index 8122611911..4bc469f89d 100644 --- a/impl/src/main/java/com/sun/faces/config/ConfigureListener.java +++ b/impl/src/main/java/com/sun/faces/config/ConfigureListener.java @@ -54,21 +54,6 @@ import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -import com.sun.faces.application.ApplicationAssociate; -import com.sun.faces.application.WebappLifecycleListener; -import com.sun.faces.el.ELContextImpl; -import com.sun.faces.push.WebsocketEndpoint; -import com.sun.faces.util.FacesLogger; -import com.sun.faces.util.MojarraThreadFactory; -import com.sun.faces.util.ReflectionUtils; -import com.sun.faces.util.Timer; -import com.sun.faces.util.Util; - import jakarta.el.ELManager; import jakarta.faces.FactoryFinder; import jakarta.faces.annotation.FacesConfig.ContextParam; @@ -79,6 +64,7 @@ import jakarta.servlet.ServletContext; import jakarta.servlet.ServletContextEvent; import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletRegistration; import jakarta.servlet.ServletRequestEvent; import jakarta.servlet.ServletRequestListener; import jakarta.servlet.http.HttpSession; @@ -87,6 +73,21 @@ import jakarta.websocket.server.ServerContainer; import jakarta.websocket.server.ServerEndpointConfig; +import org.xml.sax.Attributes; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import com.sun.faces.application.ApplicationAssociate; +import com.sun.faces.application.WebappLifecycleListener; +import com.sun.faces.el.ELContextImpl; +import com.sun.faces.push.WebsocketEndpoint; +import com.sun.faces.util.FacesLogger; +import com.sun.faces.util.MojarraThreadFactory; +import com.sun.faces.util.ReflectionUtils; +import com.sun.faces.util.Timer; +import com.sun.faces.util.Util; + /** * Parse all relevant Faces configuration resources, and configure the Mojarra runtime * environment. @@ -94,6 +95,8 @@ public class ConfigureListener implements ServletRequestListener, HttpSessionListener, ServletContextListener { private static final Logger LOGGER = FacesLogger.CONFIG.getLogger(); + private static final String[] FACES_SERVLET_MAPPINGS_WITH_XHTML = { "/faces/*", "*.jsf", "*.faces", "*.xhtml" }; + private static final String[] FACES_SERVLET_MAPPINGS_WITHOUT_XHTML = { "/faces/*", "*.jsf", "*.faces" }; private ScheduledThreadPoolExecutor webResourcePool; @@ -130,7 +133,7 @@ public void contextInitialized(ServletContextEvent servletContextEvent) { // Check to see if the FacesServlet is present in the // web.xml. If it is, perform faces configuration as normal, // otherwise, simply return. - Object facesServletRegistration = servletContext.getAttribute(FACES_SERVLET_REGISTRATION); // If found by FacesInitializer. + ServletRegistration facesServletRegistration = (ServletRegistration) servletContext.getAttribute(FACES_SERVLET_REGISTRATION); // If found by FacesInitializer. WebXmlProcessor webXmlProcessor = new WebXmlProcessor(servletContext); if (facesServletRegistration == null) { @@ -148,6 +151,15 @@ public void contextInitialized(ServletContextEvent servletContextEvent) { } else { LOGGER.log(FINE, "FacesServlet found in deployment descriptor - processing configuration."); } + } else if (servletContext.getAttribute(FACES_SERVLET_MAPPINGS) != null) { // If automatic mapping needs to be handled. + if (ContextParam.DISABLE_FACESSERVLET_TO_XHTML.isSet(initFacesContext)) { + facesServletRegistration.addMapping(FACES_SERVLET_MAPPINGS_WITHOUT_XHTML); + } + else { + facesServletRegistration.addMapping(FACES_SERVLET_MAPPINGS_WITH_XHTML); + } + + servletContext.setAttribute(FACES_SERVLET_MAPPINGS, facesServletRegistration.getMappings()); } // Do not override if already defined diff --git a/impl/src/main/java/com/sun/faces/config/FacesInitializer.java b/impl/src/main/java/com/sun/faces/config/FacesInitializer.java index 342e65e144..13e2d0e382 100644 --- a/impl/src/main/java/com/sun/faces/config/FacesInitializer.java +++ b/impl/src/main/java/com/sun/faces/config/FacesInitializer.java @@ -20,16 +20,14 @@ import static com.sun.faces.RIConstants.ANNOTATED_CLASSES; import static com.sun.faces.RIConstants.FACES_SERVLET_MAPPINGS; import static com.sun.faces.RIConstants.FACES_SERVLET_REGISTRATION; +import static com.sun.faces.util.Util.getExistingFacesServletRegistration; import static com.sun.faces.util.Util.isEmpty; import static java.util.logging.Level.WARNING; import java.util.HashSet; -import java.util.Map; import java.util.Set; import java.util.logging.Logger; -import com.sun.faces.util.FacesLogger; - import jakarta.enterprise.inject.spi.BeanManager; import jakarta.faces.annotation.FacesConfig; import jakarta.faces.annotation.FacesConfig.ContextParam; @@ -66,6 +64,8 @@ import jakarta.servlet.annotation.HandlesTypes; import jakarta.websocket.server.ServerContainer; +import com.sun.faces.util.FacesLogger; + /** * Initializes Jakarta Faces if at least one of the following conditions is met: * @@ -98,8 +98,6 @@ public class FacesInitializer implements ServletContainerInitializer { private static final String FACES_CONFIG_RESOURCE_PATH = "/WEB-INF/faces-config.xml"; private static final String FACES_SERVLET_CLASS_NAME = FacesServlet.class.getName(); - private static final String[] FACES_SERVLET_MAPPINGS_WITH_XHTML = { "/faces/*", "*.jsf", "*.faces", "*.xhtml" }; - private static final String[] FACES_SERVLET_MAPPINGS_WITHOUT_XHTML = { "/faces/*", "*.jsf", "*.faces" }; // -------------------------------- Methods from ServletContainerInitializer @@ -174,18 +172,6 @@ private static boolean isFacesServletRegistrationPresent(ServletContext context) return getExistingFacesServletRegistration(context) != null; } - private static ServletRegistration getExistingFacesServletRegistration(ServletContext servletContext) { - Map existing = servletContext.getServletRegistrations(); - - for (ServletRegistration registration : existing.values()) { - if (FACES_SERVLET_CLASS_NAME.equals(registration.getClassName())) { - return registration; - } - } - - return null; - } - private static void handleMappingConcerns(ServletContext servletContext, FacesContext facesContext) throws ServletException { ServletRegistration existingFacesServletRegistration = getExistingFacesServletRegistration(servletContext); @@ -196,14 +182,6 @@ private static void handleMappingConcerns(ServletContext servletContext, FacesCo } ServletRegistration newFacesServletRegistration = servletContext.addServlet(FacesServlet.class.getSimpleName(), FACES_SERVLET_CLASS_NAME); - - if (ContextParam.DISABLE_FACESSERVLET_TO_XHTML.isSet(facesContext)) { - newFacesServletRegistration.addMapping(FACES_SERVLET_MAPPINGS_WITHOUT_XHTML); - } - else { - newFacesServletRegistration.addMapping(FACES_SERVLET_MAPPINGS_WITH_XHTML); - } - servletContext.setAttribute(FACES_SERVLET_MAPPINGS, newFacesServletRegistration.getMappings()); servletContext.setAttribute(FACES_SERVLET_REGISTRATION, newFacesServletRegistration); } diff --git a/impl/src/main/java/com/sun/faces/lifecycle/Phase.java b/impl/src/main/java/com/sun/faces/lifecycle/Phase.java index 7f273f9552..38a322831b 100644 --- a/impl/src/main/java/com/sun/faces/lifecycle/Phase.java +++ b/impl/src/main/java/com/sun/faces/lifecycle/Phase.java @@ -60,10 +60,7 @@ public abstract class Phase { public void doPhase(FacesContext context, Lifecycle lifecycle, ListIterator listeners) { context.setCurrentPhaseId(getId()); - PhaseEvent event = null; - if (listeners.hasNext()) { - event = new PhaseEvent(context, getId(), lifecycle); - } + PhaseEvent event = new PhaseEvent(context, getId(), lifecycle); // start timing - include before and after phase processing Timer timer = Timer.getInstance(); diff --git a/impl/src/main/java/com/sun/faces/util/Util.java b/impl/src/main/java/com/sun/faces/util/Util.java index 4bc5f936d2..67c24b5539 100644 --- a/impl/src/main/java/com/sun/faces/util/Util.java +++ b/impl/src/main/java/com/sun/faces/util/Util.java @@ -77,13 +77,6 @@ import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; -import com.sun.faces.RIConstants; -import com.sun.faces.application.ApplicationAssociate; -import com.sun.faces.config.WebConfiguration; -import com.sun.faces.config.manager.FacesSchema; -import com.sun.faces.facelets.component.UIRepeat; -import com.sun.faces.io.FastStringWriter; - import jakarta.el.ValueExpression; import jakarta.enterprise.inject.spi.BeanManager; import jakarta.enterprise.inject.spi.CDI; @@ -111,6 +104,13 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.MappingMatch; +import com.sun.faces.RIConstants; +import com.sun.faces.application.ApplicationAssociate; +import com.sun.faces.config.WebConfiguration; +import com.sun.faces.config.manager.FacesSchema; +import com.sun.faces.facelets.component.UIRepeat; +import com.sun.faces.io.FastStringWriter; + /** * Util is a class ... * @@ -183,7 +183,7 @@ private static Collection getFacesServletMappings(ServletContext servlet return emptyList(); } - private static ServletRegistration getExistingFacesServletRegistration(ServletContext servletContext) { + public static ServletRegistration getExistingFacesServletRegistration(ServletContext servletContext) { Map existing = servletContext.getServletRegistrations(); for (ServletRegistration registration : existing.values()) { if (FACES_SERVLET_CLASS.equals(registration.getClassName())) {