1
22
23 package com.liferay.portal.kernel.servlet;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.kernel.util.StringPool;
28
29 import java.io.IOException;
30
31 import javax.servlet.Filter;
32 import javax.servlet.FilterChain;
33 import javax.servlet.FilterConfig;
34 import javax.servlet.ServletException;
35 import javax.servlet.ServletRequest;
36 import javax.servlet.ServletResponse;
37 import javax.servlet.http.HttpServletRequest;
38
39
45 public abstract class BaseFilter implements Filter {
46
47 public void init(FilterConfig config) throws ServletException {
48 _config = config;
49 }
50
51 public abstract void doFilter(
52 ServletRequest req, ServletResponse res, FilterChain chain)
53 throws IOException, ServletException;
54
55 public FilterConfig getFilterConfig() {
56 return _config;
57 }
58
59 public void destroy() {
60 }
61
62 protected void doFilter(
63 Class<?> filterClass, ServletRequest req, ServletResponse res,
64 FilterChain chain)
65 throws IOException, ServletException {
66
67 long startTime = 0;
68
69 String threadName = null;
70 String depther = null;
71 String path = null;
72
73 if (_log.isDebugEnabled()) {
74 HttpServletRequest httpReq = (HttpServletRequest)req;
75
76 startTime = System.currentTimeMillis();
77
78 threadName = Thread.currentThread().getName();
79
80 depther = (String)req.getAttribute(_DEPTHER);
81
82 if (depther == null) {
83 depther = StringPool.BLANK;
84 }
85 else {
86 depther += StringPool.EQUAL;
87 }
88
89 req.setAttribute(_DEPTHER, depther);
90
91 path = httpReq.getRequestURI();
92
93 _log.debug(
94 "[" + threadName + "]" + depther + "> " +
95 filterClass.getName() + " " + path);
96 }
97
98 chain.doFilter(req, res);
99
100 if (_log.isDebugEnabled()) {
101 long endTime = System.currentTimeMillis();
102
103 depther = (String)req.getAttribute(_DEPTHER);
104
105 _log.debug(
106 "[" + threadName + "]" + depther + "< " +
107 filterClass.getName() + " " + path + " " +
108 (endTime - startTime) + " ms");
109
110 if (depther.length() > 0) {
111 depther = depther.substring(1);
112 }
113
114 req.setAttribute(_DEPTHER, depther);
115 }
116 }
117
118 private static final String _DEPTHER = "DEPTHER";
119
120 private static Log _log = LogFactoryUtil.getLog(BaseFilter.class);
121
122 private FilterConfig _config;
123
124 }