3 Replies Latest reply on Feb 10, 2005 1:18 AM by mphansen

    Integration with tomcat

    mphansen

      Hi,

      I'm trying to use jboss-aop 1.1 with tomcat 4.0.29 and jdk 1.4.2.

      I would like to use loadtime instrumentation. However, I'm not successful.

      I use the following code:

      <aop>
       <bind pointcut="execution(public void com.mycompany.mypackage.MyClass>myMethod(..))">
       <interceptor class="com.mycompany.myutils.MethodInterceptor"/>
       </bind>
      </aop>
      


      package com.mycompany.myutils;
      
      import org.jboss.aop.advice.Interceptor;
      import org.jboss.aop.joinpoint.Invocation;
      import org.jboss.aop.joinpoint.MethodInvocation;
      
      public class MethodInterceptor implements Interceptor
      {
       public String getName() { return MethodInterceptor.class.getName(); }
      
       public Object invoke(Invocation invocation) throws Throwable
       {
       try
       {
       MethodInvocation mi = (MethodInvocation)invocation;
       System.out.println("<<< Entering MethodInterceptor for: " + mi.getMethod().toString());
       return invocation.invokeNext();
       }
       finally
       {
       System.out.println(">>> Leaving MethodInterceptor");
       }
       }
      }
      


      I package the java class in myaspects.jar and put in CATALINA_HOME together with jboss-aop.xml. I modify catalina.sh to the following:

      JBOSS_AOP_HOME="/home/me/bin/jboss-aop_1.1"
      JBOSS_AOP_LIBS="$JBOSS_AOP_HOME/lib/javassist.jar:\
      $JBOSS_AOP_HOME/ib/trove.jar:$JBOSS_AOP_HOME/lib/concurrent.jar:\
      $JBOSS_AOP_HOME/lib/jboss-common.jar:$JBOSS_AOP_HOME/lib/jboss-aop.jar"
      JAVA_OPTS="$JAVA_OPTS -Djboss.aop.path=$CATALINA_HOME/jboss-aop.xml -Djava.system.class.loader=org.jboss.aop.standalone.SystemClassLoader"
      CLASSPATH="$CLASSPATH:${JBOSS_AOP_LIBS}:$CATALINA_HOME/myaspects.jar"
      
       "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
       -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
       -Dcatalina.base="$CATALINA_BASE" \
       -Dcatalina.home="$CATALINA_HOME" \
       -Djava.io.tmpdir="$CATALINA_TMPDIR" \
       org.apache.catalina.startup.Bootstrap "$@" start \
       >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &
      


      My problem is that nothing happens. Nothing is written to the logs as should be done my MethodInterceptor.

      Apparently something is working. For example, if a change the pointcut expression in jboss-aop.xml to be unparsable then the system complains about it (an exception is thrown about parse error in catalina.log).

      Has anyone any suggestions to what I'm doing wrong? Is loadtime instrumentation supported with tomcat? Any help would be appreciated.

        • 1. Re: Integration with tomcat
          bill.burke

          The SystemClassLoader has been deprecated. Please look at the other documentation on how to do loadtime transformation with JDK 1.4 (the doco with the distribution as I have not yet put up AOP 1.1 on the website).

          Bill

          • 2. Re: Integration with tomcat
            mphansen

            Hi Bill,

            Thanks for your reply.

            I have also tried the following, which should follow the 1.1 documentation. However, in this case nothing happens either. Also any errors in jboss-aop.xml will not result in parse errors so I assume the file is not picked up by the framework.

            JBOSS_AOP_HOME="/home/me/bin/jboss-aop_1.1"
            JBOSS_AOP_LIBS="$JBOSS_AOP_HOME/lib/javassist.jar:\
            $JBOSS_AOP_HOME/ib/trove.jar:$JBOSS_AOP_HOME/lib/concurrent.jar:\
            $JBOSS_AOP_HOME/lib/jboss-common.jar:$JBOSS_AOP_HOME/lib/jboss-aop.jar"
            JAVA_OPTS="$JAVA_OPTS -Djboss.aop.path=$CATALINA_HOME/jboss-aop.xml"
            CLASSPATH="$CLASSPATH:${JBOSS_AOP_LIBS}:$CATALINA_HOME/myaspects.jar"
            
             "$_RUNJAVA" -Xbootclasspath/p:$JAVA_AOP_LIBS $JAVA_OPTS $CATALINA_OPTS \
             -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
             -Dcatalina.base="$CATALINA_BASE" \
             -Dcatalina.home="$CATALINA_HOME" \
             -Djava.io.tmpdir="$CATALINA_TMPDIR" \
             org.apache.catalina.startup.Bootstrap "$@" start \
             >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &
            


            • 3. Re: Integration with tomcat
              mphansen

              Sorry for the trouble.

              I forgot the step about generating the instrumented class loader. It it now working.