package com.terra.proxy.intercepter; import com.terra.proxy.properties.TerraProperties; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import javax.servlet.*; import java.io.IOException; public class VisitInterceptor implements Filter { @Autowired private TerraProperties properties; public VisitInterceptor(TerraProperties prop){ properties=prop; } @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO } @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { String fromips=req.getRemoteHost(); String[] blackips= properties.getProxy().getBlacklist().split(";"); for(String temp : blackips) if(temp.equals(fromips)||fromips.indexOf(temp)!=-1){ return; } chain.doFilter(req, res); } @Override public void destroy() { // TODO } public static void main(String[] args) { String str="/50048/MapServer/export"; String s= StringUtils.substringAfter(str,"Server"); System.out.println("s = " + s); } }