consman (3) [Avatar] Offline
#1
This is a great book and I am really enjoying it. Ramnivas, can you please provide an example of @AfterReturning where you are capturing both the return type and input parameters of the advised method? Your example on p. 186 is close, but only collects the return types.

Thank you so much.
--Bob
consman (3) [Avatar] Offline
#2
Re: Collection of Return Values and Input Parameters in @AfterReturning Ad
I figured it out by viewing several of the other examples at once:

package model;

public class AdvisedClass {

public String advisedMethod (int param1, int param2){

return "The sum is: " + (param1 + param2);
}

public static void main(String[] args) {

AdvisedClass advisedClass = new AdvisedClass();
System.out.println( advisedClass.advisedMethod(6,smilie);

}

}

**********

package model;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.AfterReturning;

@Aspect
public class BobsAspects {

@Pointcut("call(String AdvisedClass.advisedMethod( int, int)) && target (advisedClass) && args (one, two)")
public void sumOperation (AdvisedClass advisedClass, int one, int two){}

@AfterReturning(value="sumOperation(advisedClass, one, two)", returning = "ret")
public void iterceptThem(AdvisedClass advisedClass, int one, int two, Object ret){

System.out.println(" Advice says: We've intercepted the method and ret is: " + ret);
System.out.println(" Advice says: We've intercepted the method and input params are : "
+ one + " and " + two);

}

}

//Does anyone know how to get the
//indentation to work properly?