Q:

Filter specific HTTP verbs in spring mvc

I'm getting a lot of errors in my spring MVC app caused by some clients requesting HTTP PROPFIND:
16:59:39,402 ERROR [foo.bar.controllers.ExceptionHandlingController] (default task-12) Uncaught Error: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PROPFIND' not supported
How can I filter this requests so that they don't generate an error in each controller ?
Thanks!

A:

You can use Spring's HandlerInterceptor as below to allow & process the required requests.
RequestMethodInterceptor class:
package com.myproject.RequestMethodInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RequestMethodInterceptor implements HandlerInterceptor  {
    @Override
    public boolean preHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler) throws Exception {
        //Added PROPFIND method, add any other types NOT allowed
        if(request.getMethod().equals("PROPFIND") ) {
            //Log or Ignore upon your requirement & return false
            return false;
        } else {
            return true;
        }

    }
}

XML Configuration:
<mvc:interceptors>
      <bean class="com.myproject.RequestMethodInterceptor" />
    </mvc:interceptors> 

