Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB 3.0 - Interceptors

 
Fabian Gutierrez
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The core ejb 3.0 spec in section 12.3.1, reads:

"If an interceptor class itself has superclasses, the interceptor methods defined by the interceptor class�s superclasses are invoked before the interceptor method defined by the interceptor class, most general superclass first."

However, if i have this classes:

public class FatherInterceptor {
@PostConstruct
public void after1(InvocationContext contexto) {
System.out.println("Father:created...");
}
}

public class SonInterceptor extends FatherInterceptor {
@PostConstruct
public void after2(InvocationContext contexto) {
System.out.println("Son:created...");
}
}

@Interceptors(SonInterceptor.class)
public class MyBean implements MyBeanInterface{
...
}

I excepted an output like this:
Father:created...
Son:created...

but it only prints
Father:created...

So...is this the expected behaviour?

ps
i'm using Sun Aplication Server 9


Best regards..

Fabian
 
Fabian Gutierrez
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, basically, the problem originated because i didn't call the proceed mthod on the InvocationContext, which also works like a chain..

public class FatherInterceptor {
@PostConstruct
public void after1(InvocationContext contexto) {
System.out.println("Father:created...");
try {
contexto.proceed();
} catch (Exception ex) {
...
}
}

}

Best reagards..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic