Announcement Announcement Module
Collapse
No announcement yet.
Advising FormAction's doValidate? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Advising FormAction's doValidate?

    I need to perform additional logic after FormAction.doValidate() returns. So, I wrote an AfterReturningAdvice and configured it to be called after doValidate, but as FormAction extends MultiAction, everything my AfterReturningAdvice sees is execute(), and in MultiAction.execute() I see:

    Object obj = methodInvoker.invoke(method, new Object[] { context });

    This is the configuration:

    Code:
    public class MyAfterReturningAdvice implements
    		AfterReturningAdvice 
    	{	
    	public void afterReturning(
    			final Object p_returnValue, 
    			final Method p_method, 
    			final Object[] p_args,
    			final Object p_target) 
    		throws Throwable 
    	{
    		
    		// FIXME Always execute method!
    		if (!p_method.getName().equals("doValidate")) {
    			LOG.warn("Method " + p_method.getName());
    			return;
    		}
    // etc...
    Code:
        <bean id="myAdvisor" 
        	class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
        	<property name="advice">
    		    <bean class="MyAfterReturningAdvice">
                         <!-- snip -->
    		    </bean>
        	</property>
            <!-- match everything to see what's going on -->
        	<property name="pattern" value=".*"/>
        </bean>
        
        <bean id="myForm" class="org.springframework.aop.framework.ProxyFactoryBean">    
    		<property name="target" ref="myFormTarget"/>
    		<property name="interceptorNames">
             	<list>
                	<value>myAdvisor</value>
    	         </list>
            </property>
        </bean>
    
        <bean id="myFormTarget"
            class="MyFormAction">
            <!-- snip -->
        </bean>
    So basically my Proxy never sees doValidate, as it is called internally (so to say) through methodInvoker.

    What are my options here? I'd like to avoid overriding e.g. doPostExecute() and etc. as this problem pretty nicelly fits in AOP story.

    Thanks in advance.

    Cheers,
    Davor

  • #2
    Yeah, that's how MultiAction works... so a proxy-based AOP approach won't work here.

    You could get the 'execute' call back and inspect that RequestContext for the 'method' property. A little hacky but it should work.

    You could use AspectJ and do the weaving at compile or load time.

    You could delegate to another object to do the validation and advise it....

    Hope this helps!

    Comment


    • #3
      Originally posted by Keith Donald
      Yeah, that's how MultiAction works... so a proxy-based AOP approach won't work here.

      You could get the 'execute' call back and inspect that RequestContext for the 'method' property. A little hacky but it should work.

      You could use AspectJ and do the weaving at compile or load time.

      You could delegate to another object to do the validation and advise it....

      Hope this helps!

      Thanks for the quick reply. I prefer aspects, but as I'm still in Spring 1.2 state of mind (although using Spring 2.0 here) I guess AspectJ won't play here. Delegate is also a good idea.

      Cheers,
      Davor

      Comment

      Working...
      X