[jboss-user] [JBoss AOP] - Re: Tracing/Logging - Actual RMI calls vs calls between EJBs

ykrishnaprasad do-not-reply at jboss.com
Tue Dec 12 17:20:42 EST 2006


Thanks a bunch guys!
I think i got the basic caller pointcut working for MethodCalledByMethodInvocation.

Here is a simple set of classes that i used for this purpose:


  | package DCR2;
  | 
  | public class HelloAOP {
  | 	public static void main(String args[]){
  | 		new callTest().printText();
  | 	}
  | 	public void callMe(){
  | 		System.out.println("AOP!");
  | 	}	
  | }
  | 
  | 
  | package DCR2;
  | 
  | public class callTest {
  | 	public void printText(){
  | 		callMe();
  | 	}
  | 	public void callMe(){
  | 		System.out.println("AOP!");
  | 	}
  | }
  | 
  | package DCR2;
  | 
  | import org.jboss.aop.advice.Interceptor;
  | import org.jboss.aop.joinpoint.Invocation;
  | import org.jboss.aop.joinpoint.MethodCalledByMethodInvocation;
  | 
  | public class HelloAOPInterceptor implements Interceptor{
  | 	public String getName(){
  | 		return "HelloAOPInterceptor";
  | 	}
  | 	public Object invoke(Invocation invocation) throws Throwable{
  | 		if (invocation instanceof MethodCalledByMethodInvocation){
  | 			System.out.print("MethodCalledByMethodInvocation, ");
  | 		}
  | 		else System.out.print("Hello, ");
  | 		return invocation.invokeNext();
  | 	}
  | }
  | 
  | 
  | 

And my jboss-aop.xml looks like:


  | 
  | 
  | <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  | <aop>
  |     <bind pointcut="call(public void DCR2.callTest->callMe()) and withincode(public void DCR2.callTest->printText())">
  |         <interceptor class="DCR2.HelloAOPInterceptor"/>
  |     </bind>
  | </aop>
  | 

The output after running the project should be:

MethodCalledByMethodInvocation, AOP!

The reason i used the callTest class in between is that i could not get the interceptor to work if i had a statement 

  | new HelloAOP().callMe();
  | 
  | (a method call in the constructor)
  | 
  | instead of:
  | new callTest().printText();
  | 

What i could do on the whole is to see if a call for a method is coming from another method or not. My next step is to see if i can differentiate between a method call coming from a JSP page(JSP->EJB) and the method calling method(EJB->EJB).

I may have to comeback for your help again.



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3993189#3993189

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3993189



More information about the jboss-user mailing list