Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about Interceptors

 
Kaxhif Khan
Ranch Hand
Posts: 50
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Whats difference between JEE6 and JEE7 ? Does EJB specification is also different for JEE6 and JEE7 ?
2) Here is second question with some code

i) AInterceptor does not have 'Interceptor' annotation but still get called in normal order, does this mean that 'Interceptor' annotation is not important ?
ii) "doLog" method in BookServiceImpl got called 2 times ? Why ?
 
Himai Minh
Ranch Hand
Posts: 1359
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't tried your code yet.
1) The EJB spec is for EJB 3.1. It does not matter it is for JEE6 or JEE7.
2) i) What EJB container do you use? GlassFish? I will try and see why the interceptor A is still called without @Interceptor.
ii) There are two doLog interceptor methods. One is in AInterceptor. The other one is in BookServiceImpl
 
Himai Minh
Ranch Hand
Posts: 1359
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried your code. Even if I don't put @Interceptor for AInterceptor, my GlassFish still consider this as an interceptor.
The reason why the doLog method is called twice because of @Interceptors includes both interceptors:


First, it calls the @AroundInvoke in AInterceptor, then it calls the @AroundInvoke in BookServiceImpl.
Next, the doLog of the BookServiceImpl is called.
That is why the doLog in BookServiceImpl is called twice.

Try to do this:

You will see the doLog of the BookServiceImpl will only called once.
 
Kaxhif Khan
Ranch Hand
Posts: 50
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes but why it is called two times ? Is it logically correct that we specify an interceptor and it is getting called twice ?
 
Himai Minh
Ranch Hand
Posts: 1359
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The first doLog invocation comes from @Interceptors({AInterceptor.class, BookServiceImpl.class})
When AInterceptor finishes its @AroundInvoke method, it proceeds to the next interceptor method, which is BookServiceImpl.doLog.

The second doLog invocation comes from the @AroundInvoke method in BookServiceImpl itself.

I remember the order specified by the spec is:
1. the AroundInvoke method associated with the method , searchBookById() in this case.
2. the AroundInvoke method associated with the class, to which searchBookById() belongs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic