3 Replies Latest reply on Feb 11, 2014 8:06 AM by sebcramer

    CDI Injection on OpenWebBeans (e.g. WebSphere 8.0, TomEE) with ResourceOptimization

    sebcramer

      Hello.

       

      Refering to [#RF-12801] org.richfaces.resourceOptimization.enabled parameter with true value disables WebBeansELResolver to register… I did some further testing and debugging.

       

      bleathem recommended to try to reproduce the problem on Tomcat with Openwebbeans installed. My problem right now is rather embarrasing : I dont get Openwebbeans working on a Tomcat7 install. No matter what I do, the best I can get is openbeanbeans complaining about the fact that comp/BeanManager is not writable in the JNDI context. That's obvious since that part of the context is indeed not available on tomcat (needs to be comp/env/...). So if anyone ever got a 1.1.x version of OWB working on tomcat (there are loads of tutorials available online - but none cover OWB & RF4.x. There is some added obstacles with org.richfaces.cdi.push.PushCDIDependencyRegistrationExtension in regard to Classloading) I could use a hand...

       

      Anyways - I at least got a "simple as possible" application to demonstrate the problem using WAS8. The application uses nothing but CDI & JSF2 (and richfaces obviously). The thing I noticed (and this might help debugging the situation) is the following: As soon as I so much as "mention" the context param org.richtfaces.resourceOptimization.enabled (even if I explicitly set it to false) the injection stops working (as in the ELResolver obviously fails to bind).

       

      Does that ring a bell with anyone? I will continue to try to get the problem reproduced with tomcat. I attached the maven project to reproduce the problem on WAS8 (even 8.0.0.7 which is - right now - the latest fixpack.

       

      Cheers

       

      Sebastian

        • 1. Re: CDI Injection on WebSphere 8.0 with ResourceOptimization
          bleathem

          I took the time to get a sample application running on TomEE:

          https://github.com/bleathem/tomee-richfaces-app/tree/master

           

          It was fairly trivial starting from the org.apache.openejb.maven:tomee-webapp-archetype:1.5.2 archetype, and adding RichFaces dependencies to the pom.  The app deploys and runs fine.

           

          In a branch I set the org.richfaces.resourceOptimization.enabled to true, and indeed the CDI injection started failing.

          https://github.com/bleathem/tomee-richfaces-app/tree/RF-12801-owb-resource-optimisation

           

          See the Readme for instructions on building the above application, and running it in an embedded TomEE container:

          https://github.com/bleathem/tomee-richfaces-app/blob/master/README.md

          • 2. Re: CDI Injection on WebSphere 8.0 with ResourceOptimization
            sebcramer

            Duh!

             

            TomEE - could have thought of that myself. Your project "works" (as in: doesnt' function) for me too... The interesting thing is: setting the context-param to "false" makes the thing work again (as opposed to my findings in Websphere). But that is only a side-note.

             

            Since org.richfaces.resource.ResourceLoadingOptimization (which you recommended) was a dead end for me the last time around in WebSphere, I will now try to debug into OWB. I assume RF triggers some behaviour in OWB that makes CDI got the way of the dodo...

             

            Will get back to you as soon as I found something. If you got any more ideas - let me know...

             

            Cheers

             

            S

            • 3. Re: Re: CDI Injection on WebSphere 8.0 with ResourceOptimization
              sebcramer

              Hello bleathem

               

              I finally got back to this problem (took some time - I know).

               

              This is actually not one but two bugs. One in Richfaces (regarding the multiple loading of resources) and one (probably) in OpenWebBeans.

               

              Regarding the missing ELResolver the cause seems as follows:

               

              1. When richfaces is started the javax.faces.event.PostConstructApplicationEvent is fired and the org.richfaces.application.InitializationListener is called.
              2. During the execution of this eventlistener the org.richfaces.resource.ResourceLoadingOptimization#isEnabled() method is called. This method will try to evaluate the org.richfaces.resourceMapping.enabled context parameter. To do this it will use the FacesContext.
              3. Since this happens very early during the application initialization sequence the OWB ELResolver has not yet been initialized. The myfaces-ELContext will initialize itself (bypassing OWB) and "remember" the partially initialized state (org.apache.myfaces.application.ApplicationImpl#getELResolver() for those playing along at home).
              4. When any other part of the CDI stack afterwards tries to access "EL-entities" registered under OWBs context it will always get a null-reference since the org.apache.webbeans.el.WebBeansELResolver is not registered with the (my)faces EL context.

               

              Conclusion 1: Regarding the problem with non-available CDI beans in any CDI-scope the workaround in [RF-12801] Use of Resource Optimization prevents the WebBeansELResolver from registering in OWB - JBoss Issue Tracker actually the only way to do it right now (registring the resolver through faces-config.xml forces myfaces to insert the OWB-ELResolver in the correct context even when OWB itself "forgets" to register things during the javax.faces.event.PostConstructApplicationEvent).

               

              Which brings us to bug #2:

              As erdemyilmaz pointed out in the jira issue the workaround causes the "packed.js is loaded multiple times" bug to strike (again). After looking at IBM Websphere's myfaces implementation I noticed that lfryc s fix regarding [RF-12495] Javascript resource packaging does not work on MyFaces - JBoss Issue Tracker checks for the existance of org.apache.myfaces.shared.renderkit.html.util.ResourceUtils and subsequently calls markScriptAsRendered() and the like on it. Here comes the problem... :-) IBM (in it's infinite wisdom) decided it would be smart to keep myfaces1.2's packaging structure (for whatever twisted reason). The util-class Lukáš' is relying on resides in org.apache.myfaces.shared_impl.renderkit.html.util.ResourceUtils when running on Websphere. I prepared a patch for org.richfaces.resource.external.ExternalResourceTrackerWrapper and org.richfaces.resource.external.MyFacesExternalResourceTracker that work around this problem. Have a look at [RF-13540] Websphere incarnation of MyFaces renderes optimized resources multiple times - JBoss Issue Tracker . Would someone be willing to accept a pull-request?

               

              Conclusion 2: IBM is smarter than the rest of us... Since it will be (mostly) impossible to get IBM to fix the myfaces packaging shipped with WAS (I assume they messed it up for backwards compatibility in the first place) it seems more helpful to fix the workaround-code in RF.

               

              Regarding OWB: I would like to file this as a bug with the OWB guys. Do you have any contact to them? After OWB fixed the problem we might just be lucky and get IBM to fix WAS (fingers crossed).

               

              Comments? Ideas?

               

              Cheers

               

              Sebastian