Announcement Announcement Module
Collapse
No announcement yet.
small problem with oval and spring aop Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • small problem with oval and spring aop

    Hello,

    pls, sorry my english.

    I'm using oval (spring+oval) for input data validation.

    I have Account class like this:

    Code:
    @Guarded
    public class Account implements Serializable {
        @NotNull(message="email must not be null")
        @Email(message="email is invalid")
        private String email;
            
        public void setEmail(@AssertFieldConstraints("email") String email) {
        	this.email = email;
        }
        
        public String getEmail() {
        	return email;
        }    
    }
    And configuration like this:

    Code:
      <bean id="account" factory-bean="accountDao" factory-method="getAccount">
        <constructor-arg value="1" />
      </bean>
    	
      <bean id="ovalGuardInterceptor" class="net.sf.oval.guard.GuardInterceptor" />
    	
      <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="proxyTargetClass" value="true" />
        <property name="beanNames" value="account" />
        <property name="interceptorNames"><list><value>ovalGuardInterceptor</value></list></property>
      </bean>
    My AccountUpdateController looks like this:

    Code:
    public class AccountUpdateController extends AbstractController {
        private AccountDao accountDao;
        private Account account;
        
        public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
        	Map<String, Object> model = new HashMap<String, Object>();
    	try {
    		account.setEmail(request.getParameter("email"));
    		accountDao.updateAccount(account);
                    model.put("message", "account updated");
    	} catch(ConstraintsViolatedException e) {
                    model.put("message", "error: " + e.getMessage());
    	}
            return new ModelAndView("async/json", "model", model);
        }
        ...
    }
    And that works perfectly. I have exception when user sends wrong email.

    But, account is request-scoped.

    I'm changing my servlet-config to something like this


    Code:
      <bean id="account" factory-bean="accountDao" factory-method="getAccount" scope="request">
        <constructor-arg value="1" />
        <aop:scoped-proxy />
      </bean>
    	
      <bean id="ovalGuardInterceptor" class="net.sf.oval.guard.GuardInterceptor" />
    	
      <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="proxyTargetClass" value="true" />
        <property name="beanNames" value="*account*" />
        <property name="interceptorNames"><list><value>ovalGuardInterceptor</value></list></property>
      </bean>
    And have messages in log like this:

    Code:
    Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class $Proxy25]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy25
    I think i understand that code cannot subclass final class class $Proxy25 (which is subclass of Account i suppose). But how to fix it?

    Another way - just use oval validator and validate object manully after set values.

    But if possible, i'll prefer first way (with aop).

    Could anybody please advise me, how to configure it?

  • #2
    The problem seems to be related to the spring proxying mechanism selection. I described it here - Spring AOP top problem #2 - java.lang.ClassCastException: $Proxy7.

    Initial BeanNameAutoProxyCreator setup worked only with 'account' bean, however, the later used a bean name pattern - '*account*'. It looks like your 'account' bean is correctly processed at the second case but there is another bean that causes the problem. Solution is to explicitly define cglib-based proxying for the problem bean.

    Also I'd recommend spring2 aop usage - 6. Aspect Oriented Programming with Spring (BeanNameAutoProxyCreator belongs to the spring1 aop).

    Comment


    • #3
      Originally posted by denis.zhdanov View Post
      Initial BeanNameAutoProxyCreator setup worked only with 'account' bean, however, the later used a bean name pattern - '*account*'. It looks like your 'account' bean is correctly processed at the second case but there is another bean that causes the problem. Solution is to explicitly define cglib-based proxying for the problem bean.
      If i'm using just 'account' instead of '*account*' - then nothing happends...

      Anyway, i'll exam carefully all things you advised to me this weekends.

      Thank you very much for your time, Denis.

      Comment

      Working...
      X