| Author |
Callback Interceptor Methods
|
Amirr Rafique
Ranch Hand
Joined: Nov 14, 2005
Posts: 324
|
|
Hi mates
I came across following line which confused my concept
Lifecycle callback interceptor methods may throw system runtime exceptions, but not application exceptions.
My understanding is Callback interceptor methods can throw all RuntimeExceptions i.e. system exceptions and runtime exceptions annotated as @ApplicationException.
Please confirm
|
"Know where to find the solution and how to use it - that's the secret of success."
|
 |
Lee Kian Giap
Ranch Hand
Joined: Jan 23, 2008
Posts: 210
|
|
I tested it using three type of exception in Glassfish
1) application exception extends Exception
2) system exception extends RuntimeException
3) runtime exception with @ApplicationException
throw exception from a @PostConstruct method
all successfully compiled, and when execute, all throws EJBException to client
|
SCJP 6, SCWCD 5, SCBCD 5
|
 |
Amirr Rafique
Ranch Hand
Joined: Nov 14, 2005
Posts: 324
|
|
Lee
I think callback interceptors cannot throw checked exceptions...
Guys please explain
Thanks
|
 |
Amirr Rafique
Ranch Hand
Joined: Nov 14, 2005
Posts: 324
|
|
Following are the restrictions of callback interceptors
The following are the restrictions for the @PrePassivate method:
• The return type of the method must be void.
• The method must not throw a checked exception.
• The method may be public, protected, package private or priv
• The method must not be static.
• The method must not be final.
• This annotation does not have any attributes
|
 |
Lee Kian Giap
Ranch Hand
Joined: Jan 23, 2008
Posts: 210
|
|
Yes, I also confirm that callback interceptors cannot throw checked exceptions
=====================
server log shows
[#|2009-10-14T20:34:57.671+0800|WARNING|sun-appserver2.1|javax.enterprise.system.stream.err|_ThreadID=54;_ThreadName=p: thread-pool-1; w: 69;_RequestID=977c8be3-2f82-4b3d-8290-7cd3fcfb377f;|
YES...here|#]
[#|2009-10-14T20:34:57.671+0800|INFO|sun-appserver2.1|javax.enterprise.system.container.ejb|_ThreadID=54;_ThreadName=p: thread-pool-1; w: 69;|EJB5070: Exception creating stateless session bean : [{0}]
ejb3inaction.example.MyException1
my explaination is :
I try with this code, it successfully compile , run , and throw MyException1. The problem is according to spec, the designation of a @PostContruct method in bean class must be as follows
void <METHOD>()
so, since the designation of @PostConstruct method cannot have throws clause, it cannot throw checked exception ... but just wierd that why glassfish still successfully compile it, run it, and even throw the exception
=============================
I tested with the following code,
server log shows
[#|2009-10-14T20:32:20.437+0800|WARNING|sun-appserver2.1|javax.enterprise.system.stream.err|_ThreadID=54;_ThreadName=p: thread-pool-1; w: 69;_RequestID=977c8be3-2f82-4b3d-8290-7cd3fcfb377f;|
YES...here|#]
[#|2009-10-14T20:32:20.453+0800|INFO|sun-appserver2.1|javax.enterprise.system.container.ejb|_ThreadID=54;_ThreadName=p: thread-pool-1; w: 69;|EJB5070: Exception creating stateless session bean : [{0}]
ejb3inaction.example.MyException2
=============================
I tested with the following code,
server log shows
[#|2009-10-14T20:27:54.703+0800|WARNING|sun-appserver2.1|javax.enterprise.system.stream.err|_ThreadID=49;_ThreadName=p: thread-pool-1; w: 67;_RequestID=51aff2a6-4895-4265-9b98-43a55bd38ae6;|
YES...here|#]
[#|2009-10-14T20:27:54.703+0800|INFO|sun-appserver2.1|javax.enterprise.system.container.ejb|_ThreadID=49;_ThreadName=p: thread-pool-1; w: 67;|EJB5070: Exception creating stateless session bean : [{0}]
ejb3inaction.example.MyException3
===================
Can I conclude that it can throw both runtime exception or runtime exception with @ApplicationException ?
Anyone please confirm this ?
|
 |
Marcin Faryna
Greenhorn
Joined: Jul 16, 2009
Posts: 15
|
|
|
I understand that javax.ejb.ApplicationException annotation is related to sessions beans transaction managment not to Lifecycle handlers.
|
SCJP 6, SCBCD 5
|
 |
 |
|
|
subject: Callback Interceptor Methods
|
|
|