6 Replies Latest reply on Jul 24, 2011 11:33 AM by javaphil

    @Resource EJBContext in Interceptor JEE5 -> JEE6

    javaphil

      Hi,

       

      I used an Interceptor with the JEE5 style @Interceptors(MyInterceptor.class) as class Annotation. Inside this Interceptor i could use @Resource EJBContext. Now i'm migrating to JEE6 style with InterceptorBinding, but now the Interceptor does not get a EJBContext.

       

      Using: JBoss 6.1.x build from 14.07.

       

      Please Help. Thanks!

      Philipp

        • 1. Re: @Resource EJBContext in Interceptor JEE5 -> JEE6
          jaikiran

          Please post the relevant code. That'll give us some idea on what's going on.

          • 2. Re: @Resource EJBContext in Interceptor JEE5 -> JEE6
            javaphil

            Ok i'm at home... i try writing it from mind.. tomorrow i can post the exact code

             

            I got an Interceptorclass:

             

            public class MyInterceptor{

             

                 EJBContext ejbContext;

             

                 @Resource

                 public void setEjbContext(EjbContext ejbContext){

                      this.ejbContext = ejbContext;

                 }

             

                 @AroundInvoke

                 public Object intercept(InvocationContext ctx) throw Exception {

                     Principal princ = ejbContext.getCallerPrincipal();

                      //do somethin

                 }

            }

             

            This interceptor i was using with the JEE5 Style:

             

            @Stateless

            @Interceptors(MyInterceptor.class)

            public class MyBeanImpl implements MyBean{

                

                 public void someMethod(){

                      //do work

                 }

             

            }

             

            Now i Changed that to JEE6 style:

             

            I implemented @MyAnnotation:

             

            @Inherited

            @InterceptorBinding

            @Retention(value=Runtime)

            @Target(value={Method, Type})

            public @interface MyAnnotation {}

             

            And i changed the Interceptor:

             

            @Interceptor

            @MyAnnotation

            public class MyInterceptor{

                 //Code inside does not change

            }

             

            And i put a bean.xml inside META-INF

             

            <beans>

              <interceptors>

                     <class>com.my.application.MyInterceptor</class>

              </interceptors>

            </beans>

             

            MyBean i changed to this:

             

            @Stateless

            // removed --> @Interceptors(MyInterceptor.class)

            public class MyBeanImpl implements MyBean{

                

                 @MyAnnotation

                 public void someMethod(){

                      //do work

                 }

             

            }

             

            Now i got a NullPointerException inside MyInterceptor at --> Principal princ = ejbContext.getCallerPrincipal();

             

            Ok tomorrow ill check if i did some Errors while posting this..

             

            Thanks

            • 3. Re: @Resource EJBContext in Interceptor JEE5 -> JEE6
              jaikiran

              Oh, you introduced CDI in there. I'm not too sure but there might have been a bug in there which we were discussing sometime back. Was this ever working in 6.0.0 of AS? I'll see Marius knows about this.

              • 4. Re: @Resource EJBContext in Interceptor JEE5 -> JEE6
                javaphil

                Never tried the InterceptorBinding style in 6.0.0 . But i cant use 6.0.0 because of the Exception wrapping.. when a custom Exception is thrown in Interceptor... in 6.1.x this is not wrapped.

                 

                What has worked is the old style with binding the Interceptor by using @Interceptors(MyInterceptor.class) on the classes that have to be intercepted... With this binding the Interceptor got the @Resource EjbContext injected.

                • 5. Re: @Resource EJBContext in Interceptor JEE5 -> JEE6
                  marius.bogoevici

                  Looks like there is indeed an issue with @Resource injection into CDI interceptors.

                  • 6. Re: @Resource EJBContext in Interceptor JEE5 -> JEE6
                    javaphil

                    hmm i hope it will get fixed soon...