Spring-Cloud-Filter(过滤器)
@Configuration
@Order(1)//设置优先级值越小优先级越高
//filterName 过滤器名称 urlPatterms 要过滤的地址
@WebFilter(filterName="urlfilter",urlPatterns="/*")
public class UrlFilter implements Filter {
private Logger logger = org.slf4j.LoggerFactory.getLogger(UrlFilter.class);
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
logger.info("初始化地址过滤器,,,");
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
String sendCharSet = httpServletRequest.getCharacterEncoding();
String sendUrl = httpServletRequest.getRequestURI();
String sendUrl_ =httpServletRequest.getQueryString();
logger.info("字符串格式----->>>{}",sendCharSet);
logger.info("前置请求地址----->>>{}",sendUrl + sendUrl_);
chain.doFilter(request, response);
}
@Override
public void destroy() {
// TODO Auto-generated method stub
logger.info("销毁地址过滤器,,,");
}
}