wtlucy closed pull request #16: MYFACES-3629 add context attr for case when 
faces servlet is found by SCI
URL: https://github.com/apache/myfaces/pull/16
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/impl/src/main/java/org/apache/myfaces/ee/MyFacesContainerInitializer.java 
b/impl/src/main/java/org/apache/myfaces/ee/MyFacesContainerInitializer.java
index 668c1cf41..485336146 100644
--- a/impl/src/main/java/org/apache/myfaces/ee/MyFacesContainerInitializer.java
+++ b/impl/src/main/java/org/apache/myfaces/ee/MyFacesContainerInitializer.java
@@ -115,6 +115,12 @@
      * is stored under this key in the ServletContext.
      */
     public static final String FACES_SERVLET_ADDED_ATTRIBUTE = 
"org.apache.myfaces.DYNAMICALLY_ADDED_FACES_SERVLET";
+
+    /**
+     * If the servlet mapping for the FacesServlet is found on the 
ServletContext, Boolean.TRUE 
+     * is stored under this key in the ServletContext.
+     */
+    public static final String FACES_SERVLET_FOUND = 
"org.apache.myfaces.FACES_SERVLET_FOUND";
     
     private static final String INITIALIZE_ALWAYS_STANDALONE = 
"org.apache.myfaces.INITIALIZE_ALWAYS_STANDALONE";
     
@@ -183,7 +189,8 @@ public void onStartup(Set<Class<?>> clazzes, ServletContext 
servletContext) thro
                 if (FACES_SERVLET_CLASS.getName().equals(className)
                         || isDelegatedFacesServlet(className))
                 {
-                    // we found a FacesServlet, so we have nothing to do!
+                    // we found a FacesServlet; set an attribute for use 
during initialization
+                    servletContext.setAttribute(FACES_SERVLET_FOUND, 
Boolean.TRUE);                    
                     return;
                 }
             }
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 0838fba51..4731154ab 100644
--- a/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
@@ -161,17 +161,25 @@ public void initFaces(ServletContext servletContext)
 
                 if 
(webConfigProvider.getFacesServletMappings(facesContext.getExternalContext()).isEmpty())
                 {
-                    // check if the FacesServlet has been added dynamically
-                    // in a Servlet 3.0 environment by 
MyFacesContainerInitializer
+                    // check to see if the FacesServlet was found by 
MyFacesContainerInitializer
                     Boolean mappingAdded = (Boolean) 
servletContext.getAttribute(
-                                                        
MyFacesContainerInitializer.FACES_SERVLET_ADDED_ATTRIBUTE);
+                        MyFacesContainerInitializer.FACES_SERVLET_FOUND);
+
                     if (mappingAdded == null || !mappingAdded)
                     {
-                        if (log.isLoggable(Level.WARNING))
+                        // 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)
                         {
-                            log.warning("No mappings of FacesServlet found. 
Abort initializing MyFaces.");
+                            if (log.isLoggable(Level.WARNING))
+                            {
+                                log.warning("No mappings of FacesServlet 
found. Abort initializing MyFaces.");
+                            }
+                            return;
                         }
-                        return;
                     }
                 }
             }
@@ -374,17 +382,25 @@ public void destroyFaces(ServletContext servletContext)
 
             if 
(webConfigProvider.getFacesServletMappings(facesContext.getExternalContext()).isEmpty())
             {
-                // check if the FacesServlet has been added dynamically
-                // in a Servlet 3.0 environment by MyFacesContainerInitializer
+                // check to see if the FacesServlet was found by 
MyFacesContainerInitializer
                 Boolean mappingAdded = (Boolean) servletContext.getAttribute(
-                                                    
MyFacesContainerInitializer.FACES_SERVLET_ADDED_ATTRIBUTE);
+                    MyFacesContainerInitializer.FACES_SERVLET_FOUND);
+
                 if (mappingAdded == null || !mappingAdded)
                 {
-                    if (log.isLoggable(Level.WARNING))
+                    // 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)
                     {
-                        log.warning("No mappings of FacesServlet found. Abort 
destroy MyFaces.");
+                        if (log.isLoggable(Level.WARNING))
+                        {
+                            log.warning("No mappings of FacesServlet found. 
Abort destroy MyFaces.");
+                        }
+                        return;
                     }
-                    return;
                 }
             }
         }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to