Archive for the 'Development' Category

How to obtain a target object from an AOP proxy in Spring


Have you ever been in a situation or you need to access the target object, proxied by Spring AOP or CGLIB ?
Yes?

Check out this obscure Interface that I’ve found in the Spring API:
org.springframework.aop.framework.Advised

Any AOP proxy obtained from Spring can be cast to this interface to allow manipulation of its AOP advice. With this in mind, you can track down the target object, and get the information you need.

Here’s an example:

Object myBean = yourSpringContext.getBean(beanName);
if(myBean instanceof Advised){
      Advised advised = (Advised) actionBean;
      // Get the target object: The proxied object
      Object myObject = advised.getTargetSource().getTarget();
}


 

Synchronizer Token Pattern in Struts


The main problem that this pattern is trying to solve is the double submissions of forms.
For example, look at this list of event that can lead to a double submission.

  • Clicking more than once on a submit control
  • Using Refresh button
  • Using the browser back button to resubmit form
  • Using Browser history feature and re-submit form.
  • Malicious submissions to the server

[more ...]


 

Defining Advice


Advice will be executed before, after and even around a method that have been selected by a pointcut. In this discussion, I will show you how to define Advice in various

Again, for the purpose of my post, consider that I use AOP annotations.

Advice Type

Advice comes in many flavours. I will explain in detail and demonstrate the differences that exist between them. Here’s the list that Spring AOP support.

  • Before
  • After
  • After returning
  • After throwing
  • Around

[more ...]