-
1. Re: @Resource EJBContext in Interceptor JEE5 -> JEE6
jaikiran Jul 20, 2011 9:49 AM (in response to javaphil)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 Jul 20, 2011 10:36 AM (in response to jaikiran)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 Jul 20, 2011 11:08 AM (in response to javaphil)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 Jul 22, 2011 5:15 AM (in response to jaikiran)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 Jul 22, 2011 11:14 AM (in response to javaphil)Looks like there is indeed an issue with @Resource injection into CDI interceptors.
-
6. Re: @Resource EJBContext in Interceptor JEE5 -> JEE6
javaphil Jul 24, 2011 11:33 AM (in response to marius.bogoevici)hmm i hope it will get fixed soon...