Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specific return type on AspectJ around call

I am looking to create around advice on methods with a specific return type. I'm curious if something like that is possible. I have this method for example:

@Around("execution(* com.mytest.example.*Resource.*(..))")
public Object restCallMade(ProceedingJoinPoint pjp) {
    Response response = null;

    try {
        response = (Response) pjp.proceed();

        // Do other stuff
    } catch (Throwable e) {

    }

    return response;
}

However, if possible I would like that this advice only gets called if the return type of the method is Response. Is that possible?

like image 678
DavidR Avatar asked Oct 27 '25 05:10

DavidR


1 Answers

Just use the (fully qualified) type name instead of the joker * in the pointcut's method signature:

@Around("execution(org.foo.Response com.mytest.example.*Resource.*(..))")
public Response restCallMade(ProceedingJoinPoint pjp) {
    Response response = null;
    try {
        response = (Response) pjp.proceed();
        // Do other stuff
    } catch (Throwable t) {}
    return response;
}
like image 133
kriegaex Avatar answered Oct 28 '25 18:10

kriegaex