I just posted a message to commons about aspectj. :) Very, very cool stuff+ACE- What 
I'd like to see next from that arena is the ability to define pointcuts and aspects 
dynamically rather than with a recompile.

Donnie


+AD4- -----Original Message-----
+AD4- From: Nicholas Lesiecki +AFs-mailto:nick+AEA-eblox.com+AF0-
+AD4- Sent: Thursday, January 10, 2002 5:52 PM
+AD4- To: Struts Developers List
+AD4- Subject: AspectJ and Struts Exception handling:
+AD4- 
+AD4- 
+AD4- Hello,
+AD4- 
+AD4- A while back Rick Hightower submitted a request to change the way 
+AD4- Struts handles errors. His problem (and mine) is that Struts 
+AD4- tends to catch exceptions and throw different exceptions 
+AD4- indicating the problem. Needless to say this can badly obscure 
+AD4- the original cause of the error.
+AD4- 
+AD4- So today I set about remedying it using AspectJ--an aspect 
+AD4- oriented extension to Java produced by Xerox PARC 
+AD4- (http://www.aspectj.org). I added the following aspect to the 
+AD4- org.apache.struts package:
+AD4- 
+AD4- public aspect ExceptionLogger+AHs-
+AD4- 
+AD4-   before(Throwable e) : args(e) +ACYAJg- handler(Throwable+-)+AHs-
+AD4-     System.err.println(+ACI-Exception caught in the Struts framework:+ACI-)+ADs-
+AD4-     e.printStackTrace(System.err)+ADs-
+AD4-   +AH0-
+AD4- +AH0-
+AD4- 
+AD4- Then I compiled Struts with an Ant task for AspectJ compilation:
+AD4- 
+AD4- +ADw-target name+AD0AIg-compile.library+ACI- depends+AD0AIg-prepare.library+ACI-
+AD4-      description+AD0AIg-Compile Struts library files+ACIAPg-
+AD4-         +ADw-ajc srcdir+AD0AIgAkAHs-src.share.dir+AH0AIg-
+AD4-             destdir+AD0AIgAkAHs-build.home+AH0-/library/classes+ACIAPg-
+AD4-             +ADw-classpath refid+AD0AIg-compile.classpath+ACI-/+AD4-
+AD4-         +ADw-/ajc+AD4-
+AD4-     +AFs-...task continues as normal...+AF0-
+AD4- 
+AD4- Now all exceptions caught in the Struts framework are 
+AD4- automatically logged to System.err. 
+AD4- 
+AD4- So my question is:
+AD4- 
+AD4- Should we consider the use of AspectJ in Struts? This would 
+AD4- potentially have no effect on the users of the framework, but 
+AD4- could be valuable for implementing logging and error-handling 
+AD4- policies. The above code could be modified to write to a log4j 
+AD4- log if that would be more convenient.
+AD4- 
+AD4- Does this intrigue anyone? Should we continue investigation?
+AD4- 
+AD4- Cheers,
+AD4- 
+AD4- Nicholas Lesiecki
+AD4- 
+AD4- (For more info on AspectJ, look for my forthcoming article on 
+AD4- IBM's developerWorks.)
+AD4- 
+AD4- Technical Team Lead
+AD4- eBlox, Inc.
+AD4- (520) 615-9345 x104
+AD4- Check out my new book+ACE-:
+AD4- Java Tools for Extreme Programming: Mastering Open Source Tools, 
+AD4- including Ant, JUnit, and Cactus
+AD4- 
+AD4- http://www.amazon.com/exec/obidos/ASIN/047120708X/
+AD4- 
+AD4- 
+AD4- 
+AD4- 
+AD4- --
+AD4- To unsubscribe, e-mail:   
+ADw-mailto:struts-dev-unsubscribe+AEA-jakarta.apache.org+AD4-
For additional commands, e-mail: 
+ADw-mailto:struts-dev-help+AEA-jakarta.apache.org+AD4-



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to