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