Search code examples
javaajaxspringspring-mvcdwr

DWR and Spring Interceptor setup


I wanted all my DWR 3.0 request to intercept through Spring 2.5 HandlerAdapter Interceptor. Here is app-servlet.xml setup.

<dwr:controller id="dwrController" debug="true" />
<dwr:url-mapping interceptors="myInterceptors" /> 
<dwr:configuration />

<util:list id="myInterceptors" >
  <!-- Interceptors -->
  <bean id="roleInterceptor" class="mypackage.RoleInterceptor">
    <property name="userRoleDAO" ref="userRoleDAO" />
    <property name="pageNavigationRepository" ref="pageNavigationRepository" />
    <property name="portalAuditRepository" ref="portalAuditRepository" />
  </bean>
</util:list>

Below is my web.xml setting for DWR controller.

  <servlet>
     <servlet-name>dwr</servlet-name>
     <servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class>
     <init-param>
       <param-name>debug</param-name>
       <param-value>true</param-value>
     </init-param>
 </servlet>
 <servlet-mapping>
     <servlet-name>dwr</servlet-name>
     <url-pattern>/dwr/*</url-pattern>
  </servlet-mapping>

This setup does not work and DWR requests do not invoke the roleInterceptor. I use the same interceptor for non-dwr spring requests and it invokes the interceptor. Have I missed anything here ?


Solution

  • Finally after some research, I got this working. The dwr controller mapping and dwr url maapping would only work if I use Spring DispatcherServlet instead of DwrSpringServlet to process all my /dwr/* requests. I updated the web.xml and was able to intercept all dwr AJAX requests through Spring MVC interceptor bean.