Results 1 to 9 of 9

Thread: WebFlow action bean needs AOP

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Posts
    25

    Arrow WebFlow action bean needs AOP

    In my Project i use Spring WebFlow.
    I have a bean defined in one of my flow.xml files

    Code:
    <bean id="customerActions" class="com.system.actions.CustomerAction" >
    		<property name="webService" ref="customerWebService"/>
    		 <property name="agentService" ref="agentClient"/>  
    	</bean>
    Customer Action extends MultiAction class from webflow.

    Now i have a SecurityAspect class annotiated as AspectJ
    Code:
    @Aspect
    public class SecurityAspect {		
    	private SecuritySession session;
    	
    	@Before("@annotation(com.system.lib.Security)")
    	public void checkSecurity(JoinPoint jp) throws Throwable{
    		String userid = session.getUserid();
            if (userid == null) {          
                throw new SecurityException("User credentials must be present before attempting to invoke the method: "+ getMethod(jp).getName() );
            }   
            
    		
    	}
    }
    My CustomerAction contains annotation that should be intercepted by this SecurityAspect.
    However that is not the case, the aspect is never executed.


    I don't understand why this bean is omitted, it is spring managed.
    Is it possible that webflow has its own spring managed context and my SecurityAspect lives in a separate managed context?

    If someone has an opinion or knowledge on this please share.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    With Spring AOP you can only execute external method calls. Spring Web Flow Actions have only 1 method which is externally called namly the execute methods. All other method calls are internal calls and aren't going to be proxied or executed.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Nov 2007
    Posts
    25

    Default external method calls

    here is the CustomerAction
    I have a public method called setup
    Code:
    public class CustomerAction extends MultiAction{		
    	
    	@Security(group="POLCUSTOMER" )
    	public Event setup( RequestContext context ){
    		Customer c = ((Customer)context.getConversationScope().get("customer") );
    		CustomerRenderer renderer = new CustomerRenderer();		
    		renderer.setCustomer(c);
    		if( c != null ){
    			renderer.setBusinessVisible( c.getNameType().getValue().equals("I") == false );
    		}
    		// help generate a Command button for transision
    		String command = ((String)context.getFlashScope().get("commandFlow") );
    		renderer.setFlowCommand(command);		
    		context.getConversationScope().put("customerRenderer", renderer);
    		
    		
    		
    		return success();
    	}
    I have a create-customer-flow.xml
    that invokes this public method

    Code:
    	 
    	<start-actions>		
    		<action method="setup" bean="customerActions" />
    		<action method="getCustomerType" bean="customerActions" />	
    		<action method="getStateList" bean="customerActions" />	
    		<action method="getTitleList" bean="customerActions"/>
    		<action method="getSuffixList" bean="customerActions"/>
    	</start-actions>
    	
    	
    
    	<start-state idref="displayForm" />

    So i have to realize that all these methods cannot be intercepted by Spring AOP Aspects?

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    I have a create-customer-flow.xml that invokes this public method
    It still calls the execute method, however the MultiAction uses some reflection to invoke the configured method on itself, effectivly making it an internal call.

    So i have to realize that all these methods cannot be intercepted by Spring AOP Aspects?
    Not with the proxy based approach. If you want to intercept those calls you will need a full AOP solution (like AspectJ) and use either load- or compile time weaving.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Nov 2007
    Posts
    25

    Default Thank you

    thank you mdeinum for the swift clarification.

    I understand now.

  6. #6

    Default Webflow AspectJ PointCut

    You say use AspectJ because it uses compile-time weaving...

    I'm trying @AspectJ with java 5 annot. and
    just trying to get it working.

    I've added the configs:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="
               http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
               http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    
    
        <aop:aspectj-autoproxy>
           <aop:include name="errorLogger" />
        </aop:aspectj-autoproxy>
    
        <bean id="errorLogger" class="org.springframework.webflow.samples.util.ErrorLogger" />
    </beans>
    ErrorLogger has the following
    Code:
    @Aspect
    public class ErrorLogger implements Serializable {
    
        @Pointcut("execution(* org.springframework.webflow.samples.util.SearchCriteria.*(..))")
        public void say(){}
    
        @Before("say()")
        public void sayHi(){
            System.out.println("sayHi()");
        }
    }
    org.springframework.webflow.samples.util.SearchCri teria has method
    Code:
    public void throwExcept(){
            System.out.println("throwExcept()");
            try{
                //int error = 2/0;
                System.out.println("Annie are u OK?");
            }
            catch(Exception e){
               System.out.println("throwExcept()"+e.getMessage());
               e.printStackTrace();
              //throw new Exception(e);
            }
         }
    to trigger the aspect in the flow...
    Code:
    <var name="searchCriteria" class="org.springframework.webflow.samples.util.SearchCriteria" />
    
            <on-start>
                <evaluate expression="searchCriteria.throwExcept()" />
            </on-start>

    when this runs I get
    Code:
    2009-11-28 17:14:38,031 DEBUG [org.springframework.webflow.execution.AnnotatedAction] - <Putting action execution attributes map[[empty]]>
    throwExcept()
    Annie are u OK?
    so the aspect doesn't get triggered.

    However if I change the pointcut to..
    Code:
    @Before("execution(public * *(..))")
    the aspect does get triggered and I get "sayHi" everywhere
    eventually crashing the API.

    So what gives? why doesn't
    Code:
    @Pointcut("execution(* org.springframework.webflow.samples.util.SearchCriteria.*(..))")
    This work? I've tried many variations but no way of selecting my method ( as a test run).

    Is Webflow complicating the way Spring AOP normally works?

Posting Permissions

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