5 Replies Latest reply on Jul 30, 2009 4:19 AM by Mirek Sz

    Injection SessionContext to interceptor

    Mirek Sz Newbie

      Hello,
      when I inject SessionContext by @Resource annotation everything works fine but when I inject it by ejb-jar.xml file I get following error

      Caused by: javax.ejb.EJBException: java.lang.IllegalArgumentException: failed to set value org.jboss.ejb3.stateful.StatefulSessionContextImpl@377d53{containerGuid=jboss.j2ee:jar=TestEJB.jar,name=SimpleEjbImpl,service=EJB3,VMID=0c98273ef3885574:-103e70a0:122ca5af195:-7f95,id=5c4o201w-31yh4q-fxr3xh3b-1-fxr408b5-9s} on field javax.ejb.SessionContext test.InterceptorTest.sessionContext
       at org.jboss.ejb3.cache.simple.SimpleStatefulCache.create(SimpleStatefulCache.java:423)
       at org.jboss.ejb3.stateful.StatefulContainer.createSession(StatefulContainer.java:489)
       at org.jboss.ejb3.session.SessionContainer.createSession(SessionContainer.java:637)
       at org.jboss.ejb3.proxy.factory.session.stateful.StatefulSessionProxyFactoryBase.getNewSessionId(StatefulSessionProxyFactoryBase.java:296)
       at org.jboss.ejb3.proxy.factory.session.stateful.StatefulSessionProxyFactoryBase.createProxyBusiness(StatefulSessionProxyFactoryBase.java:160)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:121)
       at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
       at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:908)
       at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:742)
       at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:695)
       at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:522)
       at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:230)
      


      What could be a problem ?

      Best Regards
      Mirek

        • 1. Re: Injection SessionContext to interceptor
          jaikiran pai Master

          Which version of JBossAS? And is that the entire exception stacktrace? If not, please post the entire exception stacktrace. Also post the relevant code and configuration files.

          • 2. Re: Injection SessionContext to interceptor
            Mirek Sz Newbie

            JBOSS 5.0.0 GA

            full stack trace

            08:59:55,451 ERROR [FieldBeanProperty] failed to set value org.jboss.ejb3.stateful.StatefulSessionContextImpl@11e9be0{containerGuid=jboss.j2ee:jar=TestEJB.jar,name=SimpleEjbImpl,service=EJB3,VMID=0c98273ef3885574:5c4a7667:122ca74914f:-7fa4,id=5c4o201w-23hi0e-fxr4xidy-1-fxr4yjlm-9r} on field javax.ejb.SessionContext test.InterceptorTest.sessionContext
            java.lang.IllegalArgumentException: Can not set javax.ejb.SessionContext field test.InterceptorTest.sessionContext to test.SimpleEjbImpl
             at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
             at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
             at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
             at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:57)
             at java.lang.reflect.Field.set(Field.java:657)
             at org.jboss.injection.lang.reflect.FieldBeanProperty.set(FieldBeanProperty.java:74)
             at org.jboss.injection.EJBContextPropertyInjector.inject(EJBContextPropertyInjector.java:50)
             at org.jboss.injection.EJBContextPropertyInjector.inject(EJBContextPropertyInjector.java:45)
             at org.jboss.ejb3.injection.InjectionInvocation.invokeTarget(InjectionInvocation.java:89)
             at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:83)
             at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
             at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:74)
             at org.jboss.ejb3.EJBContainer.injectBeanContext(EJBContainer.java:1076)
             at org.jboss.ejb3.stateful.StatefulContainer.create(StatefulContainer.java:136)
             at org.jboss.ejb3.cache.simple.SimpleStatefulCache.create(SimpleStatefulCache.java:402)
             at org.jboss.ejb3.stateful.StatefulContainer.createSession(StatefulContainer.java:489)
             at org.jboss.ejb3.session.SessionContainer.createSession(SessionContainer.java:637)
             at org.jboss.ejb3.proxy.factory.session.stateful.StatefulSessionProxyFactoryBase.getNewSessionId(StatefulSessionProxyFactoryBase.java:296)
             at org.jboss.ejb3.proxy.factory.session.stateful.StatefulSessionProxyFactoryBase.createProxyBusiness(StatefulSessionProxyFactoryBase.java:160)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:121)
             at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
             at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:908)
             at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:742)
             at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:695)
             at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:522)
             at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:230)
            08:59:55,451 ERROR [STDERR] java.lang.IllegalArgumentException: failed to set value org.jboss.ejb3.stateful.StatefulSessionContextImpl@11e9be0{containerGuid=jboss.j2ee:jar=TestEJB.jar,name=SimpleEjbImpl,service=EJB3,VMID=0c98273ef3885574:5c4a7667:122ca74914f:-7fa4,id=5c4o201w-23hi0e-fxr4xidy-1-fxr4yjlm-9r} on field javax.ejb.SessionContext test.InterceptorTest.sessionContext
            08:59:55,451 ERROR [STDERR] at org.jboss.injection.lang.reflect.FieldBeanProperty.set(FieldBeanProperty.java:99)
            08:59:55,451 ERROR [STDERR] at org.jboss.injection.EJBContextPropertyInjector.inject(EJBContextPropertyInjector.java:50)
            08:59:55,452 ERROR [STDERR] at org.jboss.injection.EJBContextPropertyInjector.inject(EJBContextPropertyInjector.java:45)
            08:59:55,452 ERROR [STDERR] at org.jboss.ejb3.injection.InjectionInvocation.invokeTarget(InjectionInvocation.java:89)
            08:59:55,452 ERROR [STDERR] at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:83)
            08:59:55,452 ERROR [STDERR] at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
            08:59:55,452 ERROR [STDERR] at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:74)
            08:59:55,452 ERROR [STDERR] at org.jboss.ejb3.EJBContainer.injectBeanContext(EJBContainer.java:1076)
            08:59:55,452 ERROR [STDERR] at org.jboss.ejb3.stateful.StatefulContainer.create(StatefulContainer.java:136)
            08:59:55,452 ERROR [STDERR] at org.jboss.ejb3.cache.simple.SimpleStatefulCache.create(SimpleStatefulCache.java:402)
            08:59:55,452 ERROR [STDERR] at org.jboss.ejb3.stateful.StatefulContainer.createSession(StatefulContainer.java:489)
            08:59:55,452 ERROR [STDERR] at org.jboss.ejb3.session.SessionContainer.createSession(SessionContainer.java:637)
            08:59:55,452 ERROR [STDERR] at org.jboss.ejb3.proxy.factory.session.stateful.StatefulSessionProxyFactoryBase.getNewSessionId(StatefulSessionProxyFactoryBase.java:296)
            08:59:55,452 ERROR [STDERR] at org.jboss.ejb3.proxy.factory.session.stateful.StatefulSessionProxyFactoryBase.createProxyBusiness(StatefulSessionProxyFactoryBase.java:160)
            08:59:55,452 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            08:59:55,452 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            08:59:55,452 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            08:59:55,452 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597)
            08:59:55,452 ERROR [STDERR] at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:121)
            08:59:55,452 ERROR [STDERR] at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
            08:59:55,452 ERROR [STDERR] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:908)
            08:59:55,452 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:742)
            08:59:55,453 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:695)
            08:59:55,453 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:522)
            08:59:55,453 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:230)
            08:59:55,453 ERROR [StatefulSessionProxyFactoryBase] Could not obtain new Session ID from SFSB Container
            javax.ejb.EJBException: java.lang.IllegalArgumentException: failed to set value org.jboss.ejb3.stateful.StatefulSessionContextImpl@11e9be0{containerGuid=jboss.j2ee:jar=TestEJB.jar,name=SimpleEjbImpl,service=EJB3,VMID=0c98273ef3885574:5c4a7667:122ca74914f:-7fa4,id=5c4o201w-23hi0e-fxr4xidy-1-fxr4yjlm-9r} on field javax.ejb.SessionContext test.InterceptorTest.sessionContext
             at org.jboss.ejb3.cache.simple.SimpleStatefulCache.create(SimpleStatefulCache.java:423)
             at org.jboss.ejb3.stateful.StatefulContainer.createSession(StatefulContainer.java:489)
             at org.jboss.ejb3.session.SessionContainer.createSession(SessionContainer.java:637)
             at org.jboss.ejb3.proxy.factory.session.stateful.StatefulSessionProxyFactoryBase.getNewSessionId(StatefulSessionProxyFactoryBase.java:296)
             at org.jboss.ejb3.proxy.factory.session.stateful.StatefulSessionProxyFactoryBase.createProxyBusiness(StatefulSessionProxyFactoryBase.java:160)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:121)
             at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
             at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:908)
             at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:742)
             at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:695)
             at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:522)
             at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:230)
            Caused by: java.lang.IllegalArgumentException: failed to set value org.jboss.ejb3.stateful.StatefulSessionContextImpl@11e9be0{containerGuid=jboss.j2ee:jar=TestEJB.jar,name=SimpleEjbImpl,service=EJB3,VMID=0c98273ef3885574:5c4a7667:122ca74914f:-7fa4,id=5c4o201w-23hi0e-fxr4xidy-1-fxr4yjlm-9r} on field javax.ejb.SessionContext test.InterceptorTest.sessionContext
             at org.jboss.injection.lang.reflect.FieldBeanProperty.set(FieldBeanProperty.java:99)
             at org.jboss.injection.EJBContextPropertyInjector.inject(EJBContextPropertyInjector.java:50)
             at org.jboss.injection.EJBContextPropertyInjector.inject(EJBContextPropertyInjector.java:45)
             at org.jboss.ejb3.injection.InjectionInvocation.invokeTarget(InjectionInvocation.java:89)
             at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:83)
             at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
             at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:74)
             at org.jboss.ejb3.EJBContainer.injectBeanContext(EJBContainer.java:1076)
             at org.jboss.ejb3.stateful.StatefulContainer.create(StatefulContainer.java:136)
             at org.jboss.ejb3.cache.simple.SimpleStatefulCache.create(SimpleStatefulCache.java:402)
             ... 15 more
            
            


            • 3. Re: Injection SessionContext to interceptor
              Mirek Sz Newbie

              IntercetorTest class

              public class InterceptorTest {
              
               SessionContext sessionContext;
               public Object execute(InvocationContext invocation) throws Exception {
               System.out.println(invocation.getTarget());
               Context context = new InitialContext();
               return invocation.proceed();
               }
              }
              


              and fragments of ejb-jar.xml

               <interceptor>
               <interceptor-class>test.InterceptorTest</interceptor-class>
               <around-invoke>
               <method-name>execute</method-name>
               </around-invoke>
               <resource-env-ref>
               <resource-env-ref-name>SessionContext</resource-env-ref-name>
               <resource-env-ref-type>javax.ejb.SessionContext</resource-env-ref-type>
               <injection-target>
               <injection-target-class>test.InterceptorTest</injection-target-class>
               <injection-target-name>sessionContext</injection-target-name>
               </injection-target>
               </resource-env-ref>
               </interceptor>
              


              This error occurs when I invoke method of session bean which is connected with this interceptor

              • 4. Re: Injection SessionContext to interceptor
                jaikiran pai Master

                Looks like a bug. Please create a JIRA at https://jira.jboss.org/jira/browse/EJBTHREE and point to this thread.