-
1. Re: Permanent interceptor
jc7442 Dec 12, 2006 6:28 PM (in response to aleksab)I have done something like this to catch unexpected exception and perform some action before sending the exception to the client.
I use interceptor taht I have added in ejb3-interceptors-aop.xml.
I'm quite happy with that. -
2. Re: Permanent interceptor
aleksab Dec 13, 2006 4:38 AM (in response to aleksab)Sounds like the way to go.
Do you have any tutorial or examples on how to do this? Have search google and the jboss sites, without finding anything really usefull. -
3. Re: Permanent interceptor
jc7442 Dec 14, 2006 12:24 PM (in response to aleksab)Hi,
I'm not sure you can simply add your own domain in the ejb3 interceptors. I just connect on existing one.
If your need is to add your own domain check AOP documentation. From what I remenber it is explain but not so simple to implement.
It looks like that :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE aop PUBLIC
"-//JBoss//DTD JBOSS AOP 1.0//EN"
"http://www.jboss.org/aop/dtd/jboss-aop_1_0.dtd">
...
<!--################################################### -->
<!--My Interceptor-->
<!--typedef name="bmx" expr="class(@javax.ejb.Remote) OR class(@javax.ejb.Local)"/-->
<!-- FIN MyInterceptor-->
<!-- ################################################### -->
<!-- ################################################### -->
<!-- My Interceptor-->
<!--interceptor-ref name="fr.biomerieux.interceptor.ExecutionTimeInterceptor"/-->
<interceptor-ref name="fr.biomerieux.interceptor.ExceptionHanlderInterceptor"/>
<!-- FIN My Interceptor-->
<!-- ################################################### -->
<interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
...
<!-- ################################################### -->
<!-- My Interceptor-->
<!--interceptor-ref name="fr.biomerieux.interceptor.ExecutionTimeInterceptor"/-->
<interceptor-ref name="fr.biomerieux.interceptor.ExceptionHanlderInterceptor"/>
<!-- FIN My Interceptor-->
<!-- ################################################### -->
<interceptor-ref name="org.jboss.ejb3.asynchronous.AsynchronousInterceptor"/>
...
And a intercptor:
public class ExecutionTimeInterceptor implements Interceptor {
/**
* Version number
*/
private final Logger LOGGER = Logger.getLogger(ExecutionTimeInterceptor.class
.getName());
/**
* Log the elapsed time of the execution of a method
*/
public Object invoke(Invocation invocation) throws Throwable {
long start = System.currentTimeMillis();
try {
return invocation.invokeNext();
} finally {
long end = System.currentTimeMillis();
MethodInvocation methodInvocation = (MethodInvocation) invocation;
Method m = methodInvocation.getMethod();
LOGGER.fine(MessageFormat.format(MESSAGE.METHOD_EXECUTION,
new Object[] { m.getDeclaringClass().getName(), m.getName(),
((end - start) / 1000.) }));
}
}
/**
* Return the name of the interceptor
*/
public String getName() {
return ExecutionTimeInterceptor.class.getName();
}
}