How to send response from an interceptor, and halt further execution?
Override the preHandle method and return false if you want to stop execution.
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
response.getWriter().write("something");
return false;
}
You can do like this which will return a json response to the client
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
response.getWriter().write("{ \"error_description\": \"Invalid Value\"}");
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setStatus(400);
return false;
}