I have an interceptor class:
package cz.coffeeexperts.feedback.server.web.interceptors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
public class RestAuthorizationInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler)
throws Exception {
System.out.println("fuu");
response.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
return false;
}
}
I configured it inside my spring -webmvc.xml as follows:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<mvc:annotation-driven/>
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/rest/api/01/status" />
<bean class="cz.coffeeexperts.feedback.server.web.interceptors.RestAuthorizationInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
</beans>
However, when I go to http://localhost:8080/myserver/rest/api/01/status, I get a regular response with a status code of 200 (same as before I added the interceptor). In addition, the message “fuu” is not printed (therefore, the preHandle method is not called).
Any ideas? I started doing this with this example: http://javapapers.com/spring/spring-mvc-handler-interceptor/ , but all the other examples look the same, I can’t find where I am wrong.
I am using spring 3.2.4.RELEASE
Important editing, it works with this:
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="cz.coffeeexperts.feedback.server.web.interceptors.RestAuthorizationInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
So the question is, what's wrong with my path?