<commit_before>package main.java.filters;

import main.java.dao.MongoDBAccessLogDao;
import main.java.model.AccessLogModel;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;

public class LoggingRequestFilter implements Filter {

    private ServletContext context;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.context = filterConfig.getServletContext();
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        HttpServletRequest req = (HttpServletRequest) request;
        AccessLogModel accessLogModel = new AccessLogModel();
        accessLogModel.setCreated(new Date());
        accessLogModel.setIp(request.getRemoteAddr());
        accessLogModel.setUrlPath(req.getRequestURI());
        accessLogModel.setUserAgent(req.getHeader("User-Agent"));
        MongoDBAccessLogDao mongoDBAccessLogDao = new MongoDBAccessLogDao();
        mongoDBAccessLogDao.createAccessLog(accessLogModel);

        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }
}<commit_msg>change to get forward ip<commit_after>package main.java.filters;

import main.java.dao.MongoDBAccessLogDao;
import main.java.model.AccessLogModel;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;

public class LoggingRequestFilter implements Filter {

    private ServletContext context;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.context = filterConfig.getServletContext();
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        HttpServletRequest req = (HttpServletRequest) request;
        AccessLogModel accessLogModel = new AccessLogModel();
        accessLogModel.setCreated(new Date());
        accessLogModel.setIp(resolveIp(req));
        accessLogModel.setUrlPath(req.getRequestURI());
        accessLogModel.setUserAgent(req.getHeader("User-Agent"));
        MongoDBAccessLogDao mongoDBAccessLogDao = new MongoDBAccessLogDao();
        mongoDBAccessLogDao.createAccessLog(accessLogModel);

        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }

    protected String resolveIp( HttpServletRequest request ) {
        String ipAddress = request.getHeader("X-FORWARDED-FOR");
        if (ipAddress == null) {
            ipAddress = request.getRemoteAddr();
        }
        return ipAddress;
    }
}
{'fraction_non_alphanumeric': 0.08635199414562751, 'fraction_numerical': 0.0, 'mean_word_length': 3.899641577060932, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3513417', 'n_tokens_mistral': 728, 'n_tokens_neox': 735, 'n_words': 153}