Results 1 to 5 of 5

Thread: AspectJ - ProceedingJoinPoint

  1. #1

    Default AspectJ - ProceedingJoinPoint

    Hi

    is it possible to access the Method object via ProceedingJoinPoint?

    I want do something similar to-

    @Around(execution(* *.*(..)))
    public object makeCall(ProceedingJoinPoint pjp){

    //somehow get access to underline Method object
    Method method = ......
    method.invoke(objext,args);
    }

    Thanks in advance.

  2. #2
    Join Date
    Nov 2010
    Posts
    15

    Default why access to method object?

    if you want to invoke the method, which lies in the nature of an around advice do this:
    Object ret = pjp.proceed();

    where ProceedingJoinPoint pjp

  3. #3

    Default

    Actually I want to invoke that method on a different target. This is possible in classic spring around invoice

    public Object invoke(MethodInvocation methodInvocation) throws Throwable{

    Object result = methodInvocation.getMethod().invoke(object, methodInvocation.getArguments());

    }

    I want to do similar using Aspect.
    Thanks.

  4. #4
    Join Date
    Nov 2010
    Posts
    15

    Default get intercepted java.lang.reflect.Method object from ProceedingJoinPoin

    here it is (can be cleaned up a bit, but for the sake of understanding the concept it's ok):

    Code:
     private Method getInterceptedMethod(ProceedingJoinPoint pjp) {
            Signature signature = pjp.getSignature();
            Class<? extends Object>[] args = new Class[pjp.getArgs().length];
    
            int i = 0;
            for (Object o : pjp.getArgs()) {
                args[i] = o.getClass();
                i++;
            }
            try {
                return signature.getDeclaringType().getDeclaredMethod(signature.getName(), args);
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage());
            }
        }

  5. #5

    Default

    Thanks a lot John!!!!! I will try it out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •