[jboss-user] [JBoss Seam] - Re: Exception handling with interceptors
jteb
do-not-reply at jboss.com
Fri Feb 8 09:44:57 EST 2008
I've been using Interceptors for this kind of work. However one can only define EJB3 interceptors at the class level.
What I do is a workaround, which I find rather nasty, but since I haven't thought of another way yet and this works, I'll point it out.
I define an annotation which has Interceptors defined on it, with targets TYPE and METHOD. I put it on the class where I want a method to be intercepted and put it on the method(s) to be intercepted inside that class as well.
In the aroundInvoke, I do a check on that same annotation being present on the calling method. Something like the following:
| @AroundInvoke
| public Object aroundInvoke(InvocationContext ctx) {
| Object result = null;
| if(ctx.getMethod().getAnnotation(SomeAnnotation.class) != null) {
| try {
| result = ....
| // The rest of your code
| }
| catch( ... ) {
| }
| }
| return result;
| }
|
Might not be the most elegant method, but it works for me.
I hope that helps you!
Regards,
Jan
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4127837#4127837
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4127837
More information about the jboss-user
mailing list