0 Replies Latest reply on Jul 21, 2009 8:11 AM by Mirek Sz

    Injecting SessionContext

    Mirek Sz Newbie

      Hi,
      I have a problem with injecting sessionContext value

      My interceptor class:

      public class InterceptorTest {
      
       javax.ejb.SessionContext sessionContext;
      
       public Object execute(InvocationContext invocation) throws Exception {
       System.out.println("session contect "+sessionContext);
       return invocation.proceed();
       }
      }
      


      this interceptor is describe like that



       <interceptors>
       <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>
       </interceptors>
      


      When I invoke some method which use this interceptor I get exception

      Exception in thread "main" javax.ejb.EJBException: java.lang.IllegalArgumentException: failed to set value org.jboss.ejb3.stateless.StatelessSessionContextImpl@1ad3046 on field javax.ejb.SessionContext test.InterceptorTest.sessionContext
      


      But when I add @Resource annotation on SessionContext sessionContext;
      it works fine, but I want do this by ejb-jar.xml. What could be a problem? I use JBOSS 5.0

      Best regards