Rev 1824 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1378 | jmachado | 1 | package pt.estgp.estgweb.web.filters; |
2 | |||
3 | /** |
||
4 | * Created by jorgemachado on 24/05/16. |
||
5 | */ |
||
1824 | jmachado | 6 | |
7 | import org.apache.log4j.Logger; |
||
8 | import pt.estgp.estgweb.utils.Globals; |
||
9 | |||
1378 | jmachado | 10 | import javax.servlet.*; |
1824 | jmachado | 11 | import javax.servlet.http.HttpServletRequest; |
1378 | jmachado | 12 | import java.io.IOException; |
1824 | jmachado | 13 | import java.util.List; |
1378 | jmachado | 14 | |
1824 | jmachado | 15 | public class UrlDisplayFilter implements 1.5.0/docs/api/java/util/logging/Filter.html">Filter { |
1378 | jmachado | 16 | |
1824 | jmachado | 17 | 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); |
18 | public static final List<String> URL_STAT_IGNORE_EXTENSIONS = Globals.URL_STAT_IGNORE_EXTENSIONS; |
||
19 | |||
1378 | jmachado | 20 | @1.5.0/docs/api/java/lang/Override.html">Override |
21 | public void init(FilterConfig filterConfig) throws ServletException { |
||
22 | |||
23 | } |
||
24 | |||
25 | public void doFilter(ServletRequest request, ServletResponse response, |
||
26 | FilterChain chain) throws 1.5.0/docs/api/java/io/IOException.html">IOException, ServletException { |
||
27 | |||
1824 | jmachado | 28 | HttpServletRequest req = (HttpServletRequest) request; |
29 | 1.5.0/docs/api/java/lang/String.html">String relativePath = req.getServletPath(); |
||
30 | if (relativePath == null) |
||
31 | relativePath = ""; |
||
1378 | jmachado | 32 | |
1824 | jmachado | 33 | if (req.getPathInfo() != null && req.getPathInfo().length() > 0) |
34 | { |
||
35 | relativePath += req.getPathInfo(); |
||
36 | } |
||
37 | |||
38 | for (1.5.0/docs/api/java/lang/String.html">String ignore : URL_STAT_IGNORE_EXTENSIONS) |
||
39 | { |
||
40 | if (relativePath.endsWith(ignore)) |
||
41 | { |
||
42 | chain.doFilter(request, response); |
||
43 | return; |
||
44 | } |
||
45 | } |
||
46 | |||
47 | //String sessId = req.getSession() != null ? req.getSession().getId() : " no session "; |
||
48 | |||
1827 | jmachado | 49 | 1.5.0/docs/api/java/lang/String.html">String ipAddress = req.getHeader("X-FORWARDED-FOR"); |
50 | if (ipAddress == null) { |
||
51 | ipAddress = request.getRemoteAddr(); |
||
52 | } |
||
53 | |||
54 | logger.info("url[" + req.getRequestURL().toString() + "] reqSessionId[" + req.getRequestedSessionId() + "] servletPath[" + req.getServletPath() + "] ip[" + ipAddress + "]"); |
||
1378 | jmachado | 55 | chain.doFilter(request, response); |
56 | } |
||
57 | |||
58 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
59 | public void destroy() { |
||
60 | |||
61 | } |
||
62 | |||
63 | } |