pnicolucci opened a new pull request, #292:
URL: https://github.com/apache/myfaces/pull/292

   Fix for MYFACES-4442: https://issues.apache.org/jira/browse/MYFACES-4442
   
   
   **Current behavior:**
   1) MyFacesContainerInitializer.onStartup
        a) Checks clazzes from @HandlesTypes
        b) Checks if a faces-config.xml is present.
        c) If a or b
                - Check if there are current FacesServlet mappings
                - If there is a  FacesServlet defined set: 
FACES_SERVLET_FOUND(true)
                - If there is not a FacesServlet defined, then dynamically add 
and set: FACES_SERVLET_ADDED_ATTRIBUTE(true)
   
   2) StartupServletContextListener.contextInitialized
        a) Call FacesInitializer.initFaces(ServletContext)
   
   3) FacesInitializerImpl.initFaces
        a) If !INITIALIZE_ALWAYS_STANDALONE
        b) Use FacesServletMappingUtils to getFacesServletRegistration
        c) if getFacesServletRegistration is null / 0 then perform other checks
        d) Check MyFacesContainerInitializer.FACES_SERVLET_FOUND
        c) If MyFacesContainerInitializer.FACES_SERVLET_FOUND is null/false 
then check FACES_SERVLET_ADDED_ATTRIBUTE
        d) If FACES_SERVLET_ADDED_ATTRIBUTE is null / false then put out 
message: "No mappings of FacesServlet found. Abort  
                initializing MyFaces."
   
   **Proposed Solution:**
   1) MyFacesContainerInitializer.onStartup
        a) set isFacesServletPresent if there is a current FacesServlet defined.
        b) Checks clazzes from @HandlesTypes
        c) Checks if a faces-config.xml is present.
        d) If b or c
                - If there is not a FacesServlet defined 
(!isFacesServletPresent), then dynamically add and set: 
                FACES_SERVLET_ADDED_ATTRIBUTE(true)
   
   2) StartupServletContextListener.contextInitialized
        a) Call FacesInitializer.initFaces(ServletContext)
   
   3) FacesInitializerImpl.initFaces
        a) If !INITIALIZE_ALWAYS_STANDALONE
        d) Check MyFacesContainerInitializer.FACES_SERVLET_FOUND
        c) If MyFacesContainerInitializer.FACES_SERVLET_FOUND is null/false 
then check FACES_SERVLET_ADDED_ATTRIBUTE
        d) If FACES_SERVLET_ADDED_ATTRIBUTE is null / false then put out 
message: "No mappings of FacesServlet found. Abort 
            initializing MyFaces."
   
   Notes:
   I don't see any reason why we would need to parse the web.xml for a 
FacesServlet in the FacesInitializerImpl when
   the FacesServlet was already looked up in the MyFacesContainerInitializer. 
Also if a FacesServlet is not defined
   and @HandlesTypes classes are passed into onStartup or there is a 
faces-config.xml available in the application
   then the FacesServlet is added dynamically. So for any application that is 
"Faces enabled" we would either already
   have a FacesServlet defined in the webapp or we'd try to dynamically add a 
FacesServlet in onStartup.
   
   To me this web.xml parsing seems like old legacy code that has been around 
since before ServletContainerInitializers were available (before Servlet 3.0).
   
   This will avoid the UnsupportedOperationException from initFaces for calling 
getServletRegistrations from a
   programmatically added listener: StartupServletContextListener.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to