Hello,
I'm developping a web-app and i'm using Spring framework. Thing is, i never properly learned to use Spring and i'm kind of lost in all this.
However, using Annotations-based controllers, i was able to create most of my app!
Now, the problem is that i would need to be able ton intercept requests before they're sent to the controllers (i need it so i can validate the user has acces to the page he requests). I just spent about 5 hours searching for information about this and i actually found quite a lot, none of them worked as intended, i was never able to make my interceptor display a simple "Hello World".
Here's what i have in my *-servlet.xml (i also have the other beans definition of course):
<!-- this should be the class that contains the "hello world" -->
<bean id="myInterceptor" class="com.ibm.brmt.srb.admin.web.controller.TimeBasedAccessInterceptor"/>
<!-- this should "map" my interceptor no? -->
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list>
<ref bean="myInterceptor"/>
</list>
</property>
</bean>
and here is my TimeBasedAccessInterceptor class (the name isn't relevant and probably will be changed)
package web.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class TimeBasedAccessInterceptor extends HandlerInterceptorAdapter{
public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws Exception {
System.out.println("-------------------------------------------------------------------------------------------");
}
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) throws Exception {
System.out.println("-------------------------------------------------------------------------------------------");
}
public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception {
System.out.println("-------------------------------------------------------------------------------------------");
return false;
}
}
the codes compile and run but what's in the TimeBasedAccessInterceptor class is never called(i even used breakpoints). can someone help me?
as requested, here is a "preview" of the way i implements the controller in the *-servlet.xml
<bean id="controllerName" class="web.controller.controllerNameController">
<property name="property1" ref="beanRef" />
<property name="property1" ref="beanRef2"/>
</bean>
and in the controllerNameController.java:
package web.controller;
@Controller
public class controllerNameController{
@RequestMapping
public void find(String[] enabledLvlCodes, String reset, String readRuleId, Filter filter, Errors errors,
Model model, HttpSession session) {
//Code goes here
}
}