Win a copy of liveProject: Protecting User Data with Spring Security and OAuth2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Question about Interceptors

 
Ranch Hand
Posts: 51
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Bartender
Posts: 2071
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 2071
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 51
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 2071
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic