2 Replies Latest reply on Nov 4, 2004 2:19 PM by ad-rocha

    Intercept invoke(Object, Object[])

      Hi,

      I'd like to intercept all calls to java.lang.reflect.Method->invoke(Object, Object[]) inside method junit.framework.TestCase->runTest() made from classes that extends junit.framework.TestCase.

      I'm using runtime weaving via xml and created the class:

      public class TestCaseInterceptor extends ReflectionAspect {
      
       protected Object interceptMethod(Invocation invocation, Method method,
       Object instance, Object[] args) throws Throwable {
       System.out.println("XXXXXXXX"+invocation);
       return instance;
       }
      
      }


      I don't know how to create the xml file and restrict my pointcut, so my second approch was to create a normal java class and try this xml file (still not working):

      <interceptor class="aftt.weaving.TestCaseInterceptor"/>
      
       <bind pointcut="execution(public Object java.lang.reflect.Method->invoke(Object, Object[]) throws
       IllegalAccessException, IllegalArgumentException, InvocationTargetException)
       AND
       withincode(protected void $instanceof{junit.framework.TestCase}->runTest() throws Throwable)">
      
       <interceptor-ref name="aftt.weaving.TestCaseInterceptor"/>
       </bind>


      How can I do it?

      Thanks,

      Andre

        • 1. Re: Intercept invoke(Object, Object[])
          kabirkhan

          Hi,

          Does this help?

          <bind pointcut="call(public java.lang.Object java.lang.reflect.Method->invoke(java.lang.Object, java.lang.Object[])
           throws java.lang.IllegalAccessException, java.lang.IllegalArgumentException,
           java.lang.reflect.InvocationTargetException)
           AND
           withincode(protected void $instanceof{junit.framework.TestCase}->runTest() throws Throwable)">
          
           <interceptor-ref name="aftt.weaving.TestCaseInterceptor"/>
           </bind>
          


          1) java system classes cannot be instrumented so caller pointcuts must be used. The reflection aspect was written for this, so use 'call' instead of 'execution'.
          2) Everything must use fully qualified names. Even stuff in the java.lang package

          HTH
          Kabir

          • 2. Re: Intercept invoke(Object, Object[])

            Thanks Kabir,

            It's working now!

            Andre