@AfterReturning for multiple methods in a same controller AOP

64 views Asked by At

I want to call multiple methods included in a same controller. But methods are different from input parameters. So I need to use one aspect method for those three methods included in same controller.

 @AfterReturning("execution(* com.intervest.medical.aggregator.controller.CommonController.*(..)) && args(request,registerParam,..)")

Above line of code is oky for one method. because that method's arguements are request and registerParam. but other two methods don't include these parameters. Those methods have parameters different from this. So How do I change these line of code which suit for all the three methods.

 public RegisterResult doScreenXXX(HttpServletRequest request, @RequestBody RegisterParam registerParam) {}
 
 public XMLOutput getXXX(@RequestBody String hash) throws Exception {}
  
 public XMLOutput reScreenAndGetXXXX(@RequestBody RegisterParam registerParam) {}

I have mentioned those three methods in below.

I have used joinPoint.getArgs()[] also. but didn't get any positive response. Is this correct?

    @Pointcut("execution(* com.intervest.medical.aggregator.controller.CommonController.*(..)) && args(request,registerParam,..)")
    public void doScreenAspect(HttpServletRequest request, @RequestBody RegisterParam registerParam){}

    @Pointcut("execution(* com.intervest.medical.aggregator.controller.CommonController.*(..)) && args(registerParam,..)")
    public void rescreeningAspect(@RequestBody RegisterParam registerParam){}

    @Pointcut("execution(* com.intervest.medical.aggregator.controller.CommonController.*(..)) && args(hash,..)")
    public void getXMLAspect(@RequestBody String hash){}


    @AfterReturning("doScreenAspect(request,registerParam) || rescreeningAspect(registerParam) || getXMLAspect(hash)")
    public void aspect(JoinPoint joinPoint, @RequestBody RegisterParam registerParam, HttpServletRequest request, @RequestBody String hash) {
        System.out.println("TRTRTRTRTRTRTRTRTRTT");
        System.out.println(joinPoint.getArgs());
      }

Hope your help for clarify this issue.

Thank you

0

There are 0 answers