I've made a little Interceptor to do the trick here, but when configuring, I'm
unsure how to signal to AOP that I'd like to intercept "all client calls to the
service methods", not "all calls to service methods, including internal ones
when a service method calls another".
I've currently configured ejb3-interceptors-aop.xml with the following:
<interceptor class="my.UncaughtExceptionInterceptor "
scope="PER_VM"/>
and in each domain:
<interceptor-ref name="my.UncaughtExceptionInterceptor"/>
under:
<bind pointcut="execution(public * *->*(..))">
What should I denote as my pointcut?...I do still need to be able to throw all checked
exceptions, and I'd only like to catch UNCHECKED exceptions invoked by the client.
Perhaps in the "catch" block of my advice I'd be best to do some:
if(t instanceof EJBException)
...nonsense. Anyone with better suggestions?
package my.interceptor;
|
| import org.apache.commons.logging.Log;
| import org.apache.commons.logging.LogFactory;
| import org.jboss.aop.advice.Interceptor;
| import org.jboss.aop.joinpoint.Invocation;
|
| import my.ServiceException;
|
| /**
| * Ensures that all unchecked exceptions caught and rethrown as an EJBException
| * are logged on the server side
| *
| * @author ALR
| *
| */
| public class UncaughtExceptionInterceptor implements Interceptor {
|
| // Class Members
| private static final Log logger = LogFactory
| .getLog(UncaughtExceptionInterceptor.class);
|
| public String getName() {
| return this.getClass().getName();
| }
|
| /**
| * Carries out the invocation as normal, catching any resulting exceptions
| * thrown from the container and ensuring that they're logged properly
| * before being rethrown to the client
| */
| public Object invoke(Invocation invocation) throws Exception {
|
| try {
| logger
| .trace(this.getClass().getName()
| + " intercepted invocation.");
| return invocation.invokeNext();
| } catch (Throwable t) {
| String errorMessage = "Uncaught exception found in Services invocation to
"
| + invocation.getTargetObject()
| + "."
| + invocation.toString();
| logger.warn(errorMessage);
| throw new ServiceException(errorMessage, t);
| }
|
| }
|
| }
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4005531#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...