Results 1 to 5 of 5

Thread: AspectJ LTW problem

  1. #1

    Default 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. #2
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    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
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  3. #3

    Default

    Quote 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.

  4. #4
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    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
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  5. #5

    Default

    Quote 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •