0 Replies Latest reply on Oct 18, 2010 7:23 AM by judac

    AOP over Tomcat base classes

    judac Newbie

      Hi all.

       

           I'm using JavaAssist in one Agent I'm creating to change the behavior of tomcat, but I do not want to customize this on tomcat itself. I want to add some security issues, and for that I want to intercepted the exactly moment when tomcat class receives the client request, and intercepted the last moment that a tomcat class handle the response.

       

          I'm trying to inject a code over two methods on the tomcat base class:

      org/apache/catalina/connector/CoyoteAdapter

       

      In first instance I just want to put an output message to check when this method is requested.

       

       

      try {
           method.insertBefore(
                  " { " +
                  "     System.out.println( \" -[AOP][CoyoteAdapter][parseSessionId] \" );  " +
                  " } ");    
           }
      catch (CannotCompileException e){
           System.out.println("["+className+"]["+method.getName()+"]-> " + e.getMessage());
           e.printStackTrace();
      }
      

       

      The problem is that the

      CannotCompileException 

      throws with the information about one attribute which the method I want to change receives as parameter.

       

       

      protected void parseSessionId(org.apache.coyote.Request req, Request request) {
           ...
      }
      

       

      The class not found is

      org.apache.coyote.Request req

      This Request class is a final class.

       

      Bellow follows the stack trace collected.

      Prepering to transform org.apache.catalina.connector.CoyoteAdapter
      [org/apache/catalina/connector/CoyoteAdapter][parseSessionId]----------------> cannot find org.apache.coyote.Request
      javassist.CannotCompileException: cannot find org.apache.coyote.Request
              at javassist.CtBehavior.insertBefore(CtBehavior.java:574)
              at br.com.cedro.tomcat.transformer.Transformer.transform(Transformer.java:84)
              at sun.instrument.TransformerManager.transform(TransformerManager.java:169)
              at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:365)
              at java.lang.ClassLoader.defineClass1(Native Method)
              at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
              at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
              at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
              at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
              at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
              at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
              at org.apache.catalina.connector.Connector.initialize(Connector.java:1007)
              at org.apache.catalina.core.StandardService.initialize(StandardService.java:680)
              at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:795)
              at org.apache.catalina.startup.Catalina.load(Catalina.java:524)
              at org.apache.catalina.startup.Catalina.load(Catalina.java:548)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261)
              at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
      Caused by: javassist.NotFoundException: org.apache.coyote.Request
              at javassist.ClassPool.get(ClassPool.java:417)
              at javassist.bytecode.Descriptor.toCtClass(Descriptor.java:549)
              at javassist.bytecode.Descriptor.getParameterTypes(Descriptor.java:396)
              at javassist.CtBehavior.getParameterTypes(CtBehavior.java:235)
              at javassist.CtBehavior.insertBefore(CtBehavior.java:555)
              ... 25 more

       

      I appreciate the help. I'm exploring tomcat source for 5 days, and I didn't found the exactly point where I need to customize.

       

      Tks

       

      Juliano.