Announcement Announcement Module
Collapse
No announcement yet.
Access to MethodInvocation in a aAround("some.class") Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Access to MethodInvocation in a aAround("some.class")

    I am using Spring 2.5.1, and have started using annotation based AOP. I hacve a cache implemented by using an around advise, and the method signature is:

    Code:
      
        aAround("some.class")
        public Object cacheIntercept(ProceedingJoinPoint pjp) throws Throwable {...}
    I need access to the advised method, and sadly the pjp doesn't gie me access to this. Is there a way to have the MethodInvocation added to my cacheIntercept method, so I can access the underlying java.lang.reflect.Method?
    e.g.

    Code:
      
        aAround("some.class")
        public Object cacheIntercept(ProceedingJoinPoint pjp, MethodInvocation mi) throws Throwable {...}

    Everything works as it is now, but I have to iterate over the Object[] args to recreate the classes of the parameters to the advised method. If one of the args is null, i have a problem...

    Hope my question makes sense to someone, as I am not too excerienced in the AOP parts of spring.

    (Note: replace aAraund with the annotation, as I haven't reached 15 posts yet, and some spam mechanism prevnts any circeled a letters in my msg)


    Regards,
    Olve

  • #2
    The ProceedingJoinpoint IS your invocation... So I'm not sure what you want here?

    What is it you want to achieve or what is your requirement...

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      The ProceedingJoinpoint IS your invocation... So I'm not sure what you want here?

      What is it you want to achieve or what is your requirement...
      Thank you for your prompt reply!

      In our cache implementation we have a notion of a failoverbean, that has a method with the same signature as the adviced method.

      I set the name of the failoverbean in the annotation instance on the advised method, and our cache then looks up that bean and tries to execute the same method on the failover if the advised method fails.

      In order to use getMethod(String name, Class[] parameterTypes) i need the other methods parameterTypes as well, and those are best found in the java.lang.reflect.Method.

      In ProceedingJoingPoint there is not getMethod(), while MethodInvocation has one.

      So bottom line, I need the name and an array of parameterTypes (Class[] params) for the advised method.

      There might of course be other ways of achieving what I am trying here - but I am not that enlightened yet :-)

      Regards,
      Olve

      Comment


      • #4
        Have you looked at the API?

        Code:
        String methodName = jointPoint().getSignature().getName();
        You can determine the types by calling the getArgs() on the joinPoint and determine the type from there.

        If yu really want to live your life on the edge you could try and cast your Signature to a MethodSignature and do a getMethod from there and retrieve the Method.

        Code:
        MethodSignature methodSig = (MethodSignatur) joinPoint.getSignature();
        Method method = methodSig.getMethod();
        String name = method.getName();
        Class[] types = method.getParameterTypes();

        Comment


        • #5
          Originally posted by Marten Deinum View Post
          Have you looked at the API?
          You can determine the types by calling the getArgs() on the joinPoint and determine the type from there.
          What if an argument is null? This is what I do now, but I run in to problems when a method argument is null.

          Comment


          • #6
            Have you even bothered to read the remainder of my post?

            Comment


            • #7
              Originally posted by Marten Deinum View Post
              Have you even bothered to read the remainder of my post?
              I was a bit fast, yes, and I am sorry, I was staring myself blind on the Signature class, not having the getMethod method.

              And I was not aware that I could safely downcast to MethodInvocation either, but now I am willing to live on the edge.

              Thanks for the help.

              Comment


              • #8
                Originally posted by olve View Post
                And I was not aware that I could safely downcast to MethodInvocation either, but now I am willing to live on the edge.
                Err, that should be MethodSignature not MethodInvocation.

                Thanks again.

                Comment

                Working...
                X