package com.gescc.hedwig.interceptor;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gescc.hedwig.mapper.AppFileMapper;

public class RegAppInterceptor implements Filter {

	private Logger LOG = LoggerFactory.getLogger(RegAppInterceptor.class);
	@Resource(name = "appFileMapper")
	private AppFileMapper appFileMapper = new AppFileMapper();

	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}


	@Override
	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		String ip = req.getRemoteAddr();
		try{
			if(appFileMapper.hasApp(ip.toString())){
				LOG.error("Same IP is exist");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		chain.doFilter(req, res); 
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub

	}
}

@@ -193,16 +193,56 @@
 Config;%0A
+import javax.servlet.RequestDispatcher;%0A
 import j
@@ -999,23 +999,12 @@
 p(ip
-.toString()
 ))%7B%0A
+
 %09%09%09%09
@@ -1039,16 +1039,54 @@
 );%0A%09%09%09%7D%0A
+%09%09%09else%0A%09%09%09%09chain.doFilter(req, res);%0A
 %09%09%7Dcatch
@@ -1128,39 +1128,11 @@
 ();%0A
+
 %09%09%7D
-%0A%09%09chain.doFilter(req, res);
  %0A%09%7D

check ip