3 Replies Latest reply on Mar 6, 2012 6:16 AM by guinotphil

    Seam 2 invocation issue on conversation scoped component

    guinotphil

          Hello,

       

       

      Still doing a migration of a Seam 2.2.2 application from AS 4 to AS 7.1 Final, I’m having an issue with some Seam conversation scoped components.

       

       

      Let me explain. First here is my component class

       

       

      package myapplication;

       

      @Name(MyComponent.NAME)

      @Scope(ScopeType.CONVERSATION)

      public class MyComponent implements Serializable

      {

          private static final long serialVersionUID = -7739765902798043565L;

          public static final String NAME = "myapplication.mycomponent";

       

          public static MyComponent getInstance() {

              return (MyComponent) Component.getInstance(NAME);

          }

       

          private Integer value = 0;

       

          @Create

          public void init()

              value = 15;

          }

       

          Integer getValue() {

              return value;

          }

      }

       

       

      The issue is that on AS 7, I always get a 0 value on MyComponent.getInstance().getValue() while I should actually get the Integer 15 (which is the case on AS 4).

       

       

      With breakpoints on the init() and getValue() methods, I see that with AS 4, on the init() method the current instance is myapplication.MyComponent (id=834)

      And the strack is:

          myapplication.MyComponent.init(MyComponent.java)

          sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

          sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

          java.lang.reflect.Method.invoke(Method.java:597)

          org.jboss.seam.util.Reflections.invoke(Reflections.java:22)

          org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)

          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)

          org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)

          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

          org.jboss.seam.bpm.BusinessProcessInterceptor.aroundInvoke(BusinessProcessInterceptor.java:51)

          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

          org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)

          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

          org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)

          org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)

          org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)

          myapplication.MyComponent_$$_javassist_seam_19.init(MyComponent_$$_javassist_seam_19.java)

          sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

          sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

          java.lang.reflect.Method.invoke(Method.java:597)

          org.jboss.seam.util.Reflections.invoke(Reflections.java:22)

          org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)

          org.jboss.seam.Component.callComponentMethod(Component.java:2275)

          org.jboss.seam.Component.callCreateMethod(Component.java:2198)

          org.jboss.seam.Component.newInstance(Component.java:2158)

          org.jboss.seam.Component.getInstance(Component.java:2024)

          org.jboss.seam.Component.getInstance(Component.java:1986)

          org.jboss.seam.Component.getInstance(Component.java:1980)

          org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)

          org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)

          org.jboss.seam.Namespace.get(Namespace.java:28)

          …

       

       

      And then, when I call getValue(), the current instance is still myapplication.MyComponent (id=834)

      And the stack:

          myapplication.MyComponent.getValue(MyComponent.java)

          sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

          sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

          java.lang.reflect.Method.invoke(Method.java:597)

          org.jboss.seam.util.Reflections.invoke(Reflections.java:22)

          org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)

          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)

          org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)

          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

          org.jboss.seam.bpm.BusinessProcessInterceptor.aroundInvoke(BusinessProcessInterceptor.java:51)

          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

          org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)

          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

          org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)

          org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)

          org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)

          myapplication.MyComponent_$$_javassist_seam_19.getValue(MyComponent_$$_javassist_seam_19.java)

          myapplication.MyBusinessClass.someBusinessMethod()

          …

       

       

      On the other hand, here is what happens on AS 7.

       

      My breakpoint on init() tells me that the current instance is myapplication.MyComponent (id=651)

      And the stack is

          myapplication.MyComponent.init(yComponent.java:70)

          sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

          sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

          java.lang.reflect.Method.invoke(Method.java:597)

          org.jboss.seam.util.Reflections.invoke(Reflections.java:22)

          org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)

          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)

          org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)

          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

          org.jboss.seam.bpm.BusinessProcessInterceptor.aroundInvoke(BusinessProcessInterceptor.java:51)

          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

          org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)

          org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)

          org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)

          org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)

          org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)

          myapplication.MyComponent_$$_javassist_seam_17.init(MyComponent_$$_javassist_seam_17.java)

          sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

          sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

          java.lang.reflect.Method.invoke(Method.java:597)

          org.jboss.seam.util.Reflections.invoke(Reflections.java:22)

          org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)

          org.jboss.seam.Component.callComponentMethod(Component.java:2275)

          org.jboss.seam.Component.callCreateMethod(Component.java:2198)

          org.jboss.seam.Component.newInstance(Component.java:2158)

          org.jboss.seam.Component.getInstance(Component.java:2024)

          org.jboss.seam.Component.getInstance(Component.java:1986)

          org.jboss.seam.Component.getInstance(Component.java:1980)

          org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)

          org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)

          org.jboss.seam.Namespace.get(Namespace.java:28)

           ...

       

      Here, this works the same way as in AS 4.

       

       

      Then, when I call my getValue() method, the current instance is: myapplication.MyComponent_$$_javassist_seam_17 (id=663)

      And the stack:

          myapplication.MyComponent.getValue(MyComponent.java)

          myapplication.MyComponent_$$_javassist_seam_17.getValue(MyComponent_$$_javassist_seam_17.java)

          myapplication.MyBusinessClass.someBusinessMethod()

           ...

       

       

      It looks that the invocation does not work when calling a method of my component, and so, it refers to a different ‘value’ attribute. In AS 4 the javassist instance’s getValue method called the wrapped instance method, while it no longer do it on AS 7.

       

      Is there something wrong with my component? Or is this a bug? I find it rather strange that the behavior is different for the @Create and other method of the component.

       

       

      Thank you for your help

        • 1. Re: Seam 2 invocation issue on conversation scoped component
          ctomc

          Hi,

           

          how does you deployment looks like?

          Can you post the output of "jar tf <name-of-your-deployment-archive>

           

           

          --

          tomaz

          • 2. Re: Seam 2 invocation issue on conversation scoped component
            guinotphil

            That would be too much to post all the content of the deployed application, but here is some information:

             

            MyEar.ear/

            ----> jboss.seam.jar

            ----> lib/   : some jars including jboss-seam extensions, and the persistence beans in a single jar

            ----> META-INF/

            --------> MANIFEST.MF

            --------> application.xml

            --------> jboss-app.xml

            --------> jboss-deployment-structure.xml

            ----> MyWar.war/

            --------> META-INF/

            ------------> MANIFEST.MF

            ------------> seam-deployment.properties

            --------> WEB-INF/

            ------------> components.xml

            ------------> context.xml

            ------------> faces-config

            ------------> jboss-web.xml

            ------------> web.xml

            --------> and lot of web content

            ----> MyEJB.jar/

            --------> myapplication

            ------------> MyComponent.class

             

            The MyEJB.jar contains also some EJB components, but I can not post all the details here.... I'll try to recreate the issue with a simple seam application, but it is a lot of work to prepare. If you have more specific questions about a particular details of the deployment, please ask.  Thank you.

            • 3. Re: Seam 2 invocation issue on conversation scoped component
              guinotphil

              I've finally found out the component which causes the bug in my application.

               

              The problem actually comes because I override Seam 2's Proxy Factory's ClassLoaderProvider at start-up:

               

              @Scope(ScopeType.APPLICATION)

              @BypassInterceptors

              @Startup(depends={"org.jboss.seam.web.contextFilter"})

              @Name("myapplication.classLoaderProvider")

              public class ClassLoaderProvider

              {

               

                @Create

                public void init()

                {

                // Copied from Seam's example in JavaDoc

                  ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {

                     @Override

                       public ClassLoader get(ProxyFactory pf) {

                         return Thread.currentThread().getContextClassLoader();

                     }

                  };

                }

               

              }

               

               

              I don’t think I really need it, so I'll remove it as a workaround.

               

              However, this did not cause me any class loader issue, but a change in the behavior of javassist.

               

              Indeed package-protected methods of components were not properly invoked as said before.

               

              I don’t know exactly why, if this actually a bug or not. Any idea?

               

              I can post a small war which recreates the effect if needed.