From: grafpoo <nu...@jb...> - 2005-04-28 09:41:20
|
i want to add an aspect on creating and closing hibernate sessions. i am using java 5 with a webapp running jboss-4.0.1sp1. just for a feel-good, my first aspect is a log-everywhere one, but i cannot get it to work, so i am asking for help. i have a feeling that jboss is not even picking up on the fact that i have an aspect, so hopefully that is the lone hurdle. here's what i did. 1) created a class JbossSessionMonitor: package foo.aop; import org.apache.log4j.Logger; import org.hibernate.Session; import org.jboss.aop.Aspect; import org.jboss.aop.Bind; import org.jboss.aop.PointcutDef; import org.jboss.aop.advice.Scope; import org.jboss.aop.joinpoint.MethodInvocation; import org.jboss.aop.pointcut.Pointcut; /** * @author john guthrie */ @Aspect(scope = Scope.PER_VM) public class JbossSessionMonitor { private static Logger logger = Logger.getLogger(JbossSessionMonitor.class); @PointcutDef ("execution( public * org.hibernate.Session -> close(..) )") public static Pointcut closeSessionPointcut; @PointcutDef ("execution( public * org.hibernate.SessionFactory -> openSession(..) )") public static Pointcut openSessionPointcut; @PointcutDef ("execution( public * org.hibernate.Session -> getSession(..) )") public static Pointcut getSessionPointcut; @Bind (pointcut="foo.aop.JbossSessionMonitor.closeSessionPointcut") public Object closeSessionAdvice(MethodInvocation mi) throws Throwable { String msg = "closing session: " + sessionInfo(mi.getTargetObject()); logger.error(msg); System.out.println(msg); return mi.invokeNext(); } @Bind (pointcut="foo.aop.JbossSessionMonitor.openSessionPointcut") public Object openSessionAdvice(MethodInvocation mi) throws Throwable { Object o = mi.invokeNext(); String msg = "opening session: " + sessionInfo(o); logger.error(msg); System.out.println(msg); return o; } @Bind (pointcut="foo.aop.JbossSessionMonitor.getSessionPointcut") public Object getSessionAdvice(MethodInvocation mi) throws Throwable { String msg = "getting session: " + sessionInfo(mi.getTargetObject()); logger.error(msg); System.out.println(msg); return mi.invokeNext(); } private String sessionInfo(Object o) { if (o instanceof Session) { return ((Session) o).toString(); } else { return "NOT-A-SESSION (" + o.getClass().getName() + ")"; } } } from what i could tell from the 'injbossaop' example that comes with jboss-aop, what i needed to do to get this working is/was: 1) create a file foo.aop that has my class (jar-style), plus a jboss-aop.xml in META-INF in foo.aop that just has an empty aop root element (empty because the aspect info is all in annotations 2) my regular foo.war 3) a foo.sar that contains #1 and #2 (foo.aop and foo.war) and a jboss-service.xml with an empty server root element (since i am deploying no mbeans) with this setup, i got no logging. so i changed the jboss-aop.xml to include what i wanted, so it looks like this: <?xml version="1.0" encoding="UTF-8"?> updated the jars and redeployed. still nothing. i next changed the log-level in the jboss log4j.xml to debug level for org.jboss.aop i got no logs, which is what has me thinking that i am not telling jboss the proper place(s) for the aop configuration. View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3875739#3875739 Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3875739 |