Subversion Repositories bacoAlunos

Rev

Rev 1945 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package pt.estgp.estgweb.web.filters;

/**
 * Created by jorgemachado on 24/05/16.
 */


import org.apache.log4j.Logger;
import pt.estgp.estgweb.utils.Globals;

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

public class UrlDisplayFilter implements 1.5.0/docs/api/java/util/logging/Filter.html">Filter {

    private static 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(UrlDisplayFilter.class);
    public static final List<String> URL_STAT_IGNORE_EXTENSIONS = Globals.URL_STAT_IGNORE_EXTENSIONS;

    @1.5.0/docs/api/java/lang/Override.html">Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain) throws 1.5.0/docs/api/java/io/IOException.html">IOException, ServletException {

        HttpServletRequest req = (HttpServletRequest) request;
        1.5.0/docs/api/java/lang/String.html">String relativePath = req.getServletPath();
        if (relativePath == null)
            relativePath = "";

        if (req.getPathInfo() != null && req.getPathInfo().length() > 0)
        {
            relativePath += req.getPathInfo();
        }

        for (1.5.0/docs/api/java/lang/String.html">String ignore : URL_STAT_IGNORE_EXTENSIONS)
        {
            if (relativePath.endsWith(ignore))
            {
                chain.doFilter(request, response);
                return;
            }
        }

        //String sessId = req.getSession() != null ? req.getSession().getId() : " no session ";

        1.5.0/docs/api/java/lang/String.html">String ipAddress = req.getHeader("X-FORWARDED-FOR");
        if (ipAddress == null) {
            ipAddress = request.getRemoteAddr();
        }

        logger.info("url[" + req.getRequestURL().toString() + "] reqSessionId[" + req.getRequestedSessionId() + "] servletPath[" + req.getServletPath() + "] ip[" + ipAddress + "]");
        chain.doFilter(request, response);
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public void destroy() {

    }

}