Announcement Announcement Module
Collapse
No announcement yet.
AspectJ LTW problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AspectJ LTW problem

    I am trying to apply aspectj ltw around advice to the java.util.TimeZone class

    My first step is just to get AspectJ LTW working so i created a simple aspect:

    Code:
    @Aspect
    public class MyTestAspect extends SecurityContextAwareImpl
        {
        static Logger logger = Logger.getLogger(MyTestAspect.class);
    
    
        public MyTestAspect()
            {
            }
    
        @Around("execution(* *.*(..))")
        public Object test(ProceedingJoinPoint pjp) throws Throwable
            {
            System.err.println("hello world");
            Object returnValue = pjp.proceed();
            return returnValue;
            }
        }
    I added the agent call to my run time parameters
    Code:
    -javaagent:"C:\path to\spring-agent.jar"
    I added this tag to my bean configuration:
    Code:
    <context:load-time-weaver/>

    And I added the META-INF/aop.xml file in my classpath and tried various include options just to see if i could get it to work:

    Code:
    <!DOCTYPE aspectj PUBLIC
            "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
    <aspectj>
        <weaver
            options="-verbose -showWeaveInfo">
           <include within="java.util.TimeZone"/>
        </weaver>
    
        <aspects>
            <aspect name="com.mbs.is.model.business.system.MyTestAspect"/>
        </aspects>
      </aspectj>
    When I start my app I get no errors but i never see my "hello world" even though I put calls in TimeZone everywhere. I tried adding:
    <include within="com.*"/>

    It still appears as if my aspect is completely ignored.

    I assume I have a configuration problem. What am I missing?

  • #2
    You cannot advise classes in JDK (well, there is an option that can help a bit, but don't go there). So you may want to use a call() pointcut instead of execution(), assuming that calls to TimeZone are being made in your code.

    -Ramnivas

    Comment


    • #3
      Originally posted by ramnivas View Post
      You cannot advise classes in JDK (well, there is an option that can help a bit, but don't go there). So you may want to use a call() pointcut instead of execution(), assuming that calls to TimeZone are being made in your code.

      -Ramnivas
      Well that crushes all my hopes and dreams. I was trying to figure out a way to set it up so the default timezone of my server was the same as my client during each client request.

      Comment


      • #4
        Sorry about that :-)

        Actually, I think you can keep your hopes and dreams alive! Why can't you advise the call to the TimeZone method? Some code on the server side must be making those calls in response to a client making a request.

        -Ramnivas

        Comment


        • #5
          Originally posted by ramnivas View Post
          Sorry about that :-)

          Actually, I think you can keep your hopes and dreams alive! Why can't you advise the call to the TimeZone method? Some code on the server side must be making those calls in response to a client making a request.

          -Ramnivas
          Well when dates are dealt with on the server, by default they use the default time zone. So it isn't my code calling it so much as the java.util.Date class and java.util.Calendar class.

          It seemed to me like this was the perfect application for AOP. The alternative is me having to write date formatting code anytime i deal with a date on the server side. For queries, reports, processes, etc. This kind of minutia is a pain to deal with in my code and of course to maintain.

          Before I was using rmiinvokers to talk to my server and had a server install for every user. So i just ran the server in the default time zone of the user. But now I am using a single tomcat instance with httpinvokers and so i have clients from all different timezones making requests.

          Comment

          Working...
          X