You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2021/03/25 07:37:08 UTC

[myfaces] branch 2.3-next updated: better init / destroy handling

This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch 2.3-next
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/2.3-next by this push:
     new a511d32  better init / destroy handling
a511d32 is described below

commit a511d32f2f89980bf3271d3ceb55c2352c3328fe
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Thu Mar 25 07:36:51 2021 +0100

    better init / destroy handling
---
 .../myfaces/webapp/AbstractFacesInitializer.java   | 39 ++++------------------
 .../webapp/MyFacesContainerInitializer.java        |  2 ++
 2 files changed, 9 insertions(+), 32 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java b/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
index dcd172c..7851486 100644
--- a/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
@@ -256,6 +256,8 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
             }
 
             cleanupAfterStartup(facesContext);
+            
+            servletContext.setAttribute(MyFacesContainerInitializer.INITIALIZED, Boolean.TRUE);
         }
         catch (Exception ex)
         {
@@ -310,40 +312,13 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
     @Override
     public void destroyFaces(ServletContext servletContext)
     {
-        FacesContext facesContext = FacesContext.getCurrentInstance();
-
-        if (!WebConfigParamUtils.getBooleanInitParameter(facesContext.getExternalContext(),
-                                                         MyfacesConfig.INITIALIZE_ALWAYS_STANDALONE, false))
+        if (!Boolean.TRUE.equals(servletContext.getAttribute(MyFacesContainerInitializer.INITIALIZED)))
         {
-            FacesServletMappingUtils.ServletRegistrationInfo facesServletRegistration =
-                    FacesServletMappingUtils.getFacesServletRegistration(facesContext, servletContext, false);
-            if (facesServletRegistration == null
-                    || facesServletRegistration.getMappings() == null
-                    || facesServletRegistration.getMappings().length == 0)
-            {
-                // check to see if the FacesServlet was found by MyFacesContainerInitializer
-                Boolean mappingAdded = (Boolean) servletContext.getAttribute(
-                    MyFacesContainerInitializer.FACES_SERVLET_FOUND);
-
-                if (mappingAdded == null || !mappingAdded)
-                {
-                    // check if the FacesServlet has been added dynamically
-                    // in a Servlet 3.0 environment by MyFacesContainerInitializer
-                    mappingAdded = (Boolean) servletContext.getAttribute(
-                        MyFacesContainerInitializer.FACES_SERVLET_ADDED_ATTRIBUTE);
-
-                    if (mappingAdded == null || !mappingAdded)
-                    {
-                        if (log.isLoggable(Level.WARNING))
-                        {
-                            log.warning("No mappings of FacesServlet found. Abort destroy MyFaces.");
-                        }
-                        return;
-                    }
-                }
-            }
+            return;
         }
 
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        
         _dispatchApplicationEvent(servletContext, PreDestroyApplicationEvent.class);
 
         _callPreDestroyOnInjectedJSFArtifacts(facesContext);
@@ -713,7 +688,7 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
                 //Init LRU cache
                 WebsocketFacesInit.initWebsocketSessionLRUCache(externalContext);
 
-                externalContext.getApplicationMap().put("org.apache.myfaces.push", "true");
+                externalContext.getApplicationMap().put("org.apache.myfaces.push", Boolean.TRUE);
             }
             catch (DeploymentException e)
             {
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/MyFacesContainerInitializer.java b/impl/src/main/java/org/apache/myfaces/webapp/MyFacesContainerInitializer.java
index 678a219..dc9fc0c 100644
--- a/impl/src/main/java/org/apache/myfaces/webapp/MyFacesContainerInitializer.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/MyFacesContainerInitializer.java
@@ -96,6 +96,8 @@ public class MyFacesContainerInitializer implements ServletContainerInitializer
      */
     public static final String FACES_SERVLET_ADDED_ATTRIBUTE = "org.apache.myfaces.DYNAMICALLY_ADDED_FACES_SERVLET";
 
+    public static final String INITIALIZED = "org.apache.myfaces.INITIALIZED";
+    
     /**
      * If the servlet mapping for the FacesServlet is found on the ServletContext, Boolean.TRUE 
      * is stored under this key in the ServletContext.