2016-10-31 11 views

答えて

1

あなたは以下のようHandlerInterceptorを実装することで、特定の要求フィルタリングすることができます:

RequestMethodInterceptorクラス:

public class RequestMethodInterceptor implements HandlerInterceptor { 

    @Override 
    public boolean preHandle(HttpServletRequest request, 
      HttpServletResponse response, Object handler) throws Exception { 
     //Get the 'Accept' header value 
     String headerValue = request.getHeader("Accept"); 

     //check the request contains expected header value 
     if(!headerValue.equals("application/vnd.woot4moo-v1+json")) { 
      //Reject and Log or Ignore upon your requirement & return false 
      return false; 
     } else { 
      return true; 
     } 
    } 
} 

XML構成:

<mvc:interceptors> 
     <bean class="xyz.RequestMethodInterceptor" /> 
    </mvc:interceptors> 
関連する問題