0
votes

For some reason, my pointcut is not triggered. Note: I am using spring-style aspects, not AspectJ style.

XML snippet

<bean id="authenticationAspect" class="ssel.banking.security.AuthenticationAspect" />

<aop:config>
    <aop:aspect ref="authenticationAspect">
        <aop:pointcut id="interceptControllerInvocation"
            expression="execution(* org.springframework.web.servlet.mvc.Controller+.handleRequestInternal(javax.servlet.http.HttpServletRequest, ..)) 
                                      and args(request, ..) 
                                      and target(controller)"/>

        <aop:around pointcut-ref="interceptControllerInvocation" 
            method="authenticationAdvice"/>
    </aop:aspect>
</aop:config>

Class defined by my bean

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class AuthenticationAspect {

    public ModelAndView authenticationAdvice(ProceedingJoinPoint pjp, HttpServletRequest request, Controller controller) throws Throwable{

        String URL = request.getRequestURL().toString();
        String viewName = URL.substring(0, URL.length() - 4);
        System.out.println(viewName);

        return (ModelAndView) pjp.proceed();
    }

}

Am I missing something?

1
Adding on to what Zoran Regvart said, if handleRequestInternal is not being called across a bean boundaries (i.e. it is being called from another method in the bean like handleRequest it won't be proxied because it is a reentrant call. - mkobit

1 Answers

1
votes

Most probably invocation of handleRequestInternal method is not done across bean boundaries, but from the bean itself. I guess you're using AbstractController as a base for your controllers, and you can see that handleRequest method is calling handleRequestInternal directly.

You cannot instrument that code without using aspect compiler and change the class bytecode. And you probably don't want to do that with library code (AbstractController).