title: How do I do load time weaving of JSP's with AspectJ 1.6 and Tomcat 6?
body: <p>Here is my situation:</p>
  
  <p>I have a web application in Eclipse. At the moment it is an AspectJ web application. </p>
  
  <p>I have an aspect in my "src" folder called <code>JSPCSRFTokenInjection.aj</code> that has pointcuts to capture the <code>JspWriter.write</code> method and some other stuff. It looks like so:</p>
  
  <pre><code>package com.aspects; 
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.jsp.JspWriter;
  
  import org.apache.log4j.Logger;
  
  import com.thesis.aop.util.StopWatch;
  
  public aspect JSPCSRFTokenInjection{ 
  Logger logger; 
  StopWatch watch;
  
  private String currentCSRFToken = null;
  
  //Constuctor for the Aspect. I do some init of loggers and
  //such here.
  public JSPCSRFTokenInjection(){ 
      //PropertyConfigurator.configure("log4j.properties"); 
      logger = Logger.getLogger("csrfMitigationLogger"); 
      logger.info("CSRF Injection Aspect Created"); 
      watch = new StopWatch(); 
  } 
  
  
  //Capturing the CSRF Token from the request by intercepting the 
  //_jspService method inside of the JSP
  public pointcut csrf_jspServiceIntercept(HttpServletRequest req, 
      HttpServletResponse resp) : 
      call(public void _jspService(HttpServletRequest, HttpServletResponse)) 
      &amp;&amp; args(req, resp);
  
  
  before(HttpServletRequest req, HttpServletResponse resp) : 
      csrf_jspServiceIntercept(req, resp){
      currentCSRFToken = (String) req.getParameter("csrfSalt");
      logger.info("Got CSRF Token from request: " + currentCSRFToken);
  }
  
  //Pointcut and advice for capturing the writing into a JSP.
  public pointcut csrf_captureFormWriting(String msg, JspWriter writer) :
      call(public void JspWriter.write(String)) 
      &amp;&amp; args(msg) 
      &amp;&amp; target(writer)
      &amp;&amp; if(msg.toLowerCase().contains("&lt;/form&gt;"));
  
  before(String msg, JspWriter writer) : csrf_captureFormWriting(msg, writer){
      try{
          logger.info("WRITING TO JSP");
          writer.write("TEST_CSRF");
          writer.write("&lt;input type='hidden' name='csrfSalt' value='" +     currentCSRFToken + "'/&gt;");
      }
      catch(Exception e){
          e.printStackTrace();
      }
  }
  
  } 
  </code></pre>
  
  <p>I also have an <code>aop.xml</code> file in the <code>WebApp/WebContent/META-INF/</code> directory. 
  For reference my <code>web.xml</code> file is in <code>WebApp/WebContent/WEB-INF/</code> directory .</p>
  
  <p>The <code>aop.xml</code> looks like so:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj       /dtd/aspectj.dtd"&gt;
  &lt;aspectj&gt;
  &lt;weaver options="-showWeaveInfo -verbose -debug -Xset:weaveJavaPackages=true"&gt;
      &lt;!-- Weave types that are within the javax.* or org.aspectj.*
      packages. Also weave all types in the foo package that do
      not have the @NoWeave annotation. --&gt;
      &lt;include within="javax.*"/&gt;
      &lt;include within="com.*"/&gt;
      &lt;include within="org.*"/&gt;
      &lt;include within="org.aspectj.*"/&gt;
  &lt;/weaver&gt;
  &lt;aspects&gt;
      &lt;!-- declare two existing aspects to the weaver --&gt;
      &lt;aspect name="com.aspects.JSPCSRFTokenInjection"/&gt;
      &lt;aspect name="com.aspects.MitigateCSRFAspect"/&gt;
      &lt;!-- Of the set of aspects declared to the weaver
      use aspects matching the type pattern "com..*" for weaving. --&gt;
      &lt;include within="com.*"/&gt;
      &lt;include within="org.*"/&gt;
      &lt;!-- Of the set of aspects declared to the weaver
      do not use any aspects with the @CoolAspect annotation for weaving --&gt;
  &lt;/aspects&gt;
  &lt;/aspectj&gt;
  </code></pre>
  
  <p>I am also adding the <code>-javaagent:C:/aspectj1.6/lib/aspectjweaver.jar</code> to my JVM parameters in Tomcat. </p>
  
  <p>If it helps, I am using the SysDeo plugin for tomcat. Also, compile time weaving is working fine on other parts of the application, however, I am unable to weave in any of my aspects affecting JSP's.</p>