• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

System exception captured by an Interceptor

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The EJB 3.1 Spec (12.3.1) states that

If a system exception escapes the interceptor chain the bean instance and any associated interceptor instances are discarded.



Does it mean that if, for example, an stateless bean's method throws a RuntimeException, and it is caught by an @AroundInvoke method, the stateless bean instance is not discarded?

In code:




Thanks,
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Does it mean that if, for example, an stateless bean's method throws a RuntimeException, and it is caught by an @AroundInvoke method, the stateless bean instance is not discarded?


Yes it won't be discarded. The RuntimeException is suppressed and that is allowed.
 
Leo Marzo
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Frits!

I read a bit more the Interceptors 1.1 spec, and i found this:
"Around-invoke methods are allowed to catch and suppress exceptions and recover by calling proceed()."

which confirms what I thought
 
Bartender
Posts: 2416
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a good exercise question.
According to JSR 318, p.386, table 15, it says if the bean throws a system exception in CMT with Required attribute, the stateless bean will be discarded.
Only singleton bean won't be discarded when a system exception is thrown from it.
 
Himai Minh
Bartender
Posts: 2416
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used Ivan's example to demo this concept. And the stateless bean is not discard as it is not null.




[output]
LogInterceptor1 - entering method: method1
Info: LogInterceptor1 - throw a runtime exception and captured.
Info: LogInterceptor1- exiting method: method1
Info: ***StatlessBeanA is not discard.
Info: ***Exiting SingletonClientServlet
[/output]
 
Himai Minh
Bartender
Posts: 2416
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the information, if the exception thrown from the interceptor and it is captured by the interceptor, the stateless bean is not discarded. Assume the servlet is the same as above.



LogInterceptor1 - entering method: method1
Info: This is a demo, it does nothing.
Info: LogInterceptor1 - throw a runtime exception and captured.
Info: LogInterceptor1- exiting method: method1
Info: ***StatlessBeanA is not discard.

 
Himai Minh
Bartender
Posts: 2416
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the information,
If the interceptor throws a RuntimeException that cannot be recovered, an EJB exception is thrown and I assume the stateless bean is discarded as the JSR 318 says so.



LogInterceptor1 - entering method: method1
Info: This is a demo, it does nothing.
Warning: A system exception occurred during an invocation on EJB StatelessSessionBeanA method public void com.ivan.scbcd6.StatelessSessionBeanA.method1()
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5194)
...
Caused by: java.lang.RuntimeException
at com.ivan.scbcd6.LogInterceptor1.log(LogInterceptor1.java:17)
...
Warning: StandardWrapperValve[SingletonClientServlet]: PWC1406: Servlet.service() for servlet SingletonClientServlet threw exception
javax.ejb.EJBException
...
Caused by: java.lang.RuntimeException
at com.ivan.scbcd6.LogInterceptor1.log(LogInterceptor1.java:17)
....

 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Info: ***StatlessBeanA is not discard.


Be careful here: you are checking the reference


You should invoke a method to see if the Stateless Session Bean has been discarded.
 
Himai Minh
Bartender
Posts: 2416
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for Frits' suggestion.

I guess checks if the proxy of the stateless bean is null or not. But this does not check if the actual stateless bean has been discarded or not.


In the servlet client, I used after the interceptor throws the runtime exception.
The output is an EJBException as the statelessBeanA has been discarded by the container after the exception is thrown from the interceptor.


For the information:





LogInterceptor1 - entering method: method1
Info: This is a demo, it does nothing.
Warning: A system exception occurred during an invocation on EJB StatelessSessionBeanA method public void com.ivan.scbcd6.StatelessSessionBeanA.method1()
javax.ejb.EJBException
....
at com.ivan.scbcd6.__EJB31_Generated__StatelessSessionBeanA__Intf____Bean__.method1(Unknown Source)
at com.ivan.scbcd6.client.SingletonClientServlet.doGet(SingletonClientServlet.java:39)
...
Caused by: java.lang.RuntimeException
at com.ivan.scbcd6.LogInterceptor1.log(LogInterceptor1.java:17)
...

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic