-
1. Re: [CDI Interceptor] Recursive calls possible?
mkouba Sep 18, 2012 3:55 AM (in response to grubi)1 of 1 people found this helpfulHi,
only invocation of a method of a bean via a contextual reference or business method of a session bean via an EJB remote or local reference is intercepted (it is called business method invocation).
In other words what you describe is expected behaviour (if I understand your use-case correctly ;-).
public class Bar { @Inject Foo foo; public void pingFoo() { // This is the invocation via the contextual reference foo - is intercepted foo.ping(); } } @MyInterceptorBinding public class Foo { public void ping() { // This is NOT the invocation via the contextual reference - it is not intercepted pong(); } public void pong() { } }
WRT recursive calls -> it is possible (and again it's not business method invocation) but will likely result in StackOverflowError
-
2. Re: [CDI Interceptor] Recursive calls possible?
grubi Sep 18, 2012 5:13 AM (in response to mkouba)Hi,
thanks for your response. You got it as i meant it Is there any way to achieve what I want? Any extension or something like this?
It is not really required, but would allow me to implement a more flexible interceptor for my use-case. The only workaround I've found is to get a reference to the same bean via the BeanManager. But that is not really a nice approach.
@contextual reference: When I print out the objects (the injected foo and <this> in Foo), I get the same output. But <this> will reference the pure POJO without any CDI specifics?
-
3. Re: [CDI Interceptor] Recursive calls possible?
mkouba Sep 18, 2012 11:00 AM (in response to grubi)Hm, I don't know of any such extension... Also this could be tricky to implement. I'd rather find another way (maybe change app desing :-).
WRT contextual reference -> it depends on the bean's scope. If the bean has a normal scope, then the contextual reference for the bean is a client proxy (= not the same object). If the bean has a pseudo-scope (dependent = Foo in our example) you get the reference to the bean instance (the same obj).
-
4. Re: [CDI Interceptor] Recursive calls possible?
grubi Sep 19, 2012 8:34 AM (in response to mkouba)It would only be a nice-to-have-feature. No need to change the app design
Thanks for your explanations!