Announcement Announcement Module
Collapse
No announcement yet.
Intercepting all methods of an interface Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Have you actually read my post?! Even if you have 200 methods it works with just those 5 lines of coding. You still have to do the if stuff because for some reason you want to inspect the arguments of the method. If you want to do that in 1 class you will have to fix something for that.

    Either it is an if else or you create an interceptor per method call. Which seems a bit like an overkill to me.

    Comment


    • #17
      Hi Marten,

      I put the aspect in the same context of my controllers.

      I corrected my aspect as you suggested:

      Code:
      package it.esel.ge.aop;
      
      import org.aspectj.lang.ProceedingJoinPoint;
      import org.aspectj.lang.annotation.Around;
      import org.aspectj.lang.annotation.Aspect;
      import org.aspectj.lang.annotation.Pointcut;
      
      @Aspect
      public class ValidUserSessionAdvice {
          
          @Pointcut("execution(* *..*Controller+.handleRequest(..))")
          public void handleRequest() {}
          
          @Around("ihandleRequest()")
          public Object invoke(ProceedingJoinPoint pjp) throws Throwable {
              Object[] arguments = pjp.getArgs();
              System.out.println(arguments[0].getClass().getName());
              return pjp.proceed(arguments);
          }
      
      }
      My controllers and the aspect are defined in <webapp name>-servlet.xml:

      Code:
      <!--
        - DispatcherServlet application context for the Spring web MVC
        - implementation of AnagrafeWeb's web tier.
        -->
      <beans>
      
          <!-- ========================= VIEW DEFINITIONS ========================= -->
      
          <bean id="viewResolver1" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
              <property name="basename" value="views"/>
          </bean>
      
          <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
              <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
              <property name="prefix" value="/WEB-INF/jsp/"/>
              <property name="suffix" value=".jsp"/>
          </bean>
      
      ...
      
          <bean name="/ricerca.do" class="it.esel.ge.controllers.RicercaController">
              <property name="tableJoinsService" ref="tableJoins" />
          </bean>
      
      ...
      
          <bean id="validUserSessionAdvice" class="it.esel.ge.aop.ValidUserSessionAdvice" />
      
      <beans>
      The aspectj-autoproxy it's enabled into the ApplicationContext (<aop:aspectj-autoproxy />).

      The above controller is as follow:

      Code:
      package it.esel.ge.controllers;
      
      ...
      import it.esel.ge.controllers.base.AWController;
      ...
      
      public class RicercaController extends AWController implements IController {
      
          private final static String QUERY_INFO_MESSAGE = "Query ricerca dati: ";
          
      ...
          private IJoinsService tableJoinsService;
              
          /**
           * @author Riccardo Foraf˛
           * @since Mar 7, 2008
           *
           * @param tableJoinsService
           */
          public void setTableJoinsService(IJoinsService tableJoinsService) {
              this.tableJoinsService = tableJoinsService;
          }
          
          /*
           * Riccardo Foraf˛
           * Mar 7, 2008
           *
           * (non-Javadoc)
      * @see it.esel.ge.controllers.base.AWController#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
           */
          public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
      
              Map<Object, Object> model = new HashMap<Object, Object>();
              ModelAndView modelAndView = null;
      ...
      and it's extend a base controller that implemets the Controller interface:

      Code:
      package it.esel.ge.controllers.base;
      
      import org.springframework.web.servlet.mvc.Controller;
      ...
      public class AWController extends ApplicationObjectSupport implements Controller {
      
          protected static ReloadableResourceBundleMessageSource propertiesRepository;
          protected static MessageSource staticPropertiesRepository;
      ...    
          public AWController() {
              super();
          }
          
      ...    
          public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
              return null;
          }
      
      ...
      I do apologize to boring you, but I'm not able to understand what I'm doing wrong.

      Could you help me please?

      Thank you.

      Riccardo.

      Comment

      Working...
      X