• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Callback Interceptor Methods

 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Lee Kian Giap
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lee

I think callback interceptors cannot throw checked exceptions...

Guys please explain

Thanks
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that javax.ejb.ApplicationException annotation is related to sessions beans transaction managment not to Lifecycle handlers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic