Announcement Announcement Module
Collapse
No announcement yet.
AspectJ - ProceedingJoinPoint Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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.

      Comment


      • #4
        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());
                }
            }

        Comment


        • #5
          Thanks a lot John!!!!! I will try it out.

          Comment

          Working...
          X