-
1. Re: Be happy you have interceptors!
jamesjmp Aug 27, 2009 10:32 AM (in response to asookazian)Hi Arbi:
I´ve never used interceptors up to now but could you provide an example for a start please.
than you! -
2. Re: Be happy you have interceptors!
asookazian Aug 27, 2009 7:14 PM (in response to asookazian)public class ProfilingInterceptor { Log log = Logging.getLog(ProfilingInterceptor.class); @org.jboss.seam.annotations.intercept.AroundInvoke public Object profile(InvocationContext ic) throws Exception { log.info("*** Entering method: " + ic.getMethod().getName()); long startTime = 0; long endTime = 0; try { startTime = System.currentTimeMillis(); return ic.proceed(); } finally { endTime = System.currentTimeMillis(); log.info("*** Method " + ic.getClass() + "." + ic.getMethod() + " executed in " + (endTime - startTime) + "ms ***"); } } }
ejb-jar.xml:
<?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0"> <interceptors> <interceptor> <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class> </interceptor> <interceptor> <interceptor-class>com.cox.ers.utils.ProfilingInterceptor</interceptor-class> </interceptor> </interceptors> <assembly-descriptor> <interceptor-binding> <ejb-name>*</ejb-name> <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class> <interceptor-class>com.cox.ers.utils.ProfilingInterceptor</interceptor-class> </interceptor-binding> </assembly-descriptor> </ejb-jar>
Best part is you don't touch your Seam components at all to setup this interceptor.
-
3. Re: Be happy you have interceptors!
asookazian Aug 27, 2009 7:15 PM (in response to asookazian)The above example I refactored. It used to be a EJB3 interceptor. Keep in mind that only interface methods will be intercepted.
-
4. Re: Be happy you have interceptors!
luxspes Aug 27, 2009 9:42 PM (in response to asookazian)
Arbi Sookazian wrote on Aug 27, 2009 01:52:
We have a performance problem in a .NET app here at work (not mine!) and apparently .NET does not have interceptors or AOP as part of the framework (although I found a library called Aspect# online).And if you are using the Enterprise Library you can use Unity Interceptors
-
5. Re: Be happy you have interceptors!
asookazian Aug 27, 2009 10:50 PM (in response to asookazian)Nice heads up on unity interceptors. Unfortunately, they're using an older version (prior to EL 4.1). That means no MVC yet either, but I believe that's a separate library, it's all so confusing, just like JEE...
-
6. Re: Be happy you have interceptors!
jamesjmp Aug 28, 2009 9:18 AM (in response to asookazian)thank you very much!
I would like to rate you but as you know I cant´as I haven´t started the topic ;-( -
7. Re: Be happy you have interceptors!
magix Sep 3, 2009 3:11 PM (in response to asookazian)Can I confine the interceptors also to certain methods only, e.g. all methods that start with get... in a certain package etc?
Matthias