Example usage for org.springframework.web.context.request WebRequestInterceptor WebRequestInterceptor

List of usage examples for org.springframework.web.context.request WebRequestInterceptor WebRequestInterceptor

Introduction

In this page you can find the example usage for org.springframework.web.context.request WebRequestInterceptor WebRequestInterceptor.

Prototype

WebRequestInterceptor

Source Link

Usage

From source file:com.example.CommonModelConfiguration.java

private WebRequestInterceptor interceptor() {
    return new WebRequestInterceptor() {

        @Override/*from   www  .  j a  v a  2  s  .  c o m*/
        public void preHandle(WebRequest request) throws Exception {
        }

        @Override
        public void postHandle(WebRequest request, ModelMap model) throws Exception {
            if (request.getAttribute("contextPath", WebRequest.SCOPE_REQUEST) == null) {
                model.put("contextPath", server.getContextPath() == null ? "" : server.getContextPath());
                model.put("api", cloud.getApi());
            } else {
                // Slightly bizarre. Prevents error in template view when forwarding
                // to a view with the user already present.
                model.remove("user");
            }
        }

        @Override
        public void afterCompletion(WebRequest request, Exception ex) throws Exception {
        }
    };
}

From source file:ca.weblite.contacts.webservice.RESTServiceConfiguration.java

@Override
public void addInterceptors(InterceptorRegistry registry) {

    registry.addInterceptor(new HandlerInterceptorAdapter() {

        @Override// w ww.j  av  a 2 s .co m
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
                throws Exception {
            System.out.println("About to handle request");
            response.getWriter().write("In handler");
            return super.preHandle(request, response, handler); //To change body of generated methods, choose Tools | Templates.
        }

    });

    registry.addWebRequestInterceptor(new WebRequestInterceptor() {

        public void preHandle(WebRequest wr) throws Exception {
            System.out.println("About to handle web request");

        }

        public void postHandle(WebRequest wr, ModelMap mm) throws Exception {

        }

        public void afterCompletion(WebRequest wr, Exception excptn) throws Exception {

        }
    });
    super.addInterceptors(registry); //To change body of generated methods, choose Tools | Templates.
}