RequestResponseInterceptor

/*
 * Copyright (c) 2013 LIAONING SHIDAI_WANHENG CO.,LTD. All Rights Reserved.
 * This work contains SHIDAI_WANHENG CO.,LTD.'s unpublished
 * proprietary information which may constitute a trade secret
 * and/or be confidential. This work may be used only for the
 * purposes for which it was provided, and may not be copied
 * or disclosed to others. Copyright notice is precautionary
 * only, and does not imply publication.
 *
 */
package com.mtf.vega.interceptor;


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


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView;


import com.mtf.vega.controller.BaseController;


/**
 * 响应编码拦截器
 *
 * @author Wade.Zhu
 * @version 1.0 2014-04-15 Wade.Zhu created.
 * @version <ver>
 */
public class RequestResponseInterceptor implements HandlerInterceptor {


private static final Log logger = LogFactory.getLog(RequestResponseInterceptor.class);

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object object, Exception exception) throws Exception {
if (object instanceof BaseController) {
BaseController bc = (BaseController) object;
bc.removeRequest();
bc.removeResponse();
}
}


@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object object, ModelAndView modelAndView) throws Exception {

}


@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) throws Exception {
BaseController controller = null;

if (object instanceof HandlerMethod) { // <mvc:annotation-driven />
HandlerMethod hm = (HandlerMethod) object;
Object bean = hm.getBean();
if (bean != null && bean instanceof BaseController) {
controller = (BaseController) bean;
}
} else if (object instanceof BaseController) {
controller = (BaseController) object;
}

if (controller != null) {
controller.setRequest(request);
controller.setResponse(response);
}

return true;
}
}
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yueyue____1/article/details/80690920
个人分类: Java_EE
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭