@@ -0,0 +1,1620 @@
+/*%0A * www.yiji.com Inc.%0A * Copyright (c) 2014 All Rights Reserved%0A */%0A%0A/*%0A * %E4%BF%AE%E8%AE%A2%E8%AE%B0%E5%BD%95:%0A * daidai@yiji.com 2015-04-22 15:39 %E5%88%9B%E5%BB%BA%0A *%0A */%0Apackage com.yiji.framework.watcher.adaptor.web;%0A%0Aimport java.io.IOException;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Aimport javax.servlet.*;%0Aimport javax.servlet.http.HttpServletRequest;%0A%0Aimport com.yjf.common.log.Logger;%0Aimport com.yjf.common.log.LoggerFactory;%0A%0A/**%0A * @author daidai@yiji.com%0A */%0A%0Apublic class WatcherFilter implements Filter %7B%0A%09private Logger logger = LoggerFactory.getLogger(getClass());%0A%09private static final String ALLOWABLE_IP_REGEX = %22(127%5B.%5D0%5B.%5D0%5B.%5D1)%7C%22 + %22(localhost)%7C%22 + %22(10%5B.%5D%5C%5Cd%7B1,3%7D%5B.%5D%5C%5Cd%7B1,3%7D%5B.%5D%5C%5Cd%7B1,3%7D)%7C%22%0A%09%09%09%09%09%09%09%09%09%09%09%09%09%09+ %22(172%5B.%5D((1%5B6-9%5D)%7C(2%5C%5Cd)%7C(3%5B01%5D))%5B.%5D%5C%5Cd%7B1,3%7D%5B.%5D%5C%5Cd%7B1,3%7D)%7C%22%0A%09%09%09%09%09%09%09%09%09%09%09%09%09%09+ %22(192%5B.%5D168%5B.%5D%5C%5Cd%7B1,3%7D%5B.%5D%5C%5Cd%7B1,3%7D)%22;%0A%09private static final Pattern pattern = Pattern.compile(ALLOWABLE_IP_REGEX);%0A%09%0A%09@Override%0A%09public void init(FilterConfig filterConfig) throws ServletException %7B%0A%09%09%0A%09%7D%0A%09%0A%09@Override%0A%09public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException %7B%0A%09%09if (request instanceof HttpServletRequest) %7B%0A%09%09%09HttpServletRequest httpServletRequest = (HttpServletRequest) request;%0A%09%09%09String host = httpServletRequest.getRemoteHost();%0A%09%09%09Matcher matcher = pattern.matcher(host);%0A%09%09%09if (matcher.find()) %7B%0A%09%09%09%09chain.doFilter(request, response);%0A%09%09%09%7D else %7B%0A%09%09%09%09logger.info(%22host: %7B%7D%EF%BC%8C %E6%97%A0%E6%9D%83%E8%AE%BF%E9%97%AE%E7%9B%91%E6%8E%A7%E9%A1%B5%EF%BC%81%22, host);%0A%09%09%09%09response.getWriter().write(%22%E6%B2%A1%E6%9C%89%E8%AE%BF%E9%97%AE%E6%9D%83%E9%99%90%EF%BC%81%22);%0A%09%09%09%7D%0A%09%09%7D else %7B%0A%09%09%09chain.doFilter(request, response);%0A%09%09%7D%0A%09%7D%0A%09%0A%09@Override%0A%09public void destroy() %7B%0A%09%09%0A%09%7D%0A%7D%0A

add watcherFilter