@@ -43,29 +43,20 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
43
43
throws IOException , ServletException {
44
44
45
45
if (active && request instanceof HttpServletRequest ) {
46
- try {
47
- TeeHttpServletRequest teeRequest = new TeeHttpServletRequest ((HttpServletRequest ) request );
48
- TeeHttpServletResponse teeResponse = new TeeHttpServletResponse ((HttpServletResponse ) response );
46
+ TeeHttpServletRequest teeRequest = new TeeHttpServletRequest ((HttpServletRequest ) request );
47
+ TeeHttpServletResponse teeResponse = new TeeHttpServletResponse ((HttpServletResponse ) response );
49
48
50
- // System.out.println("BEFORE TeeFilter. filterChain.doFilter()");
49
+ try {
51
50
filterChain .doFilter (teeRequest , teeResponse );
52
- // System.out.println("AFTER TeeFilter. filterChain.doFilter()");
53
-
51
+ } finally {
54
52
teeResponse .finish ();
55
53
// let the output contents be available for later use by
56
54
// logback-access-logging
57
55
teeRequest .setAttribute (AccessConstants .LB_OUTPUT_BUFFER , teeResponse .getOutputBuffer ());
58
- } catch (IOException e ) {
59
- e .printStackTrace ();
60
- throw e ;
61
- } catch (ServletException e ) {
62
- e .printStackTrace ();
63
- throw e ;
64
56
}
65
57
} else {
66
58
filterChain .doFilter (request , response );
67
59
}
68
-
69
60
}
70
61
71
62
@ Override
@@ -76,9 +67,9 @@ public void init(FilterConfig filterConfig) throws ServletException {
76
67
77
68
active = computeActivation (localhostName , includeListAsStr , excludeListAsStr );
78
69
if (active )
79
- System . out . println ("TeeFilter will be ACTIVE on this host [" + localhostName + "]" );
70
+ logInfo ("TeeFilter will be ACTIVE on this host [" + localhostName + "]" );
80
71
else
81
- System . out . println ("TeeFilter will be DISABLED on this host [" + localhostName + "]" );
72
+ logInfo ("TeeFilter will be DISABLED on this host [" + localhostName + "]" );
82
73
83
74
}
84
75
@@ -101,13 +92,13 @@ public static List<String> extractNameList(String nameListAsStr) {
101
92
return nameList ;
102
93
}
103
94
104
- static String getLocalhostName () {
95
+ String getLocalhostName () {
105
96
String hostname = "127.0.0.1" ;
106
97
107
98
try {
108
99
hostname = InetAddress .getLocalHost ().getHostName ();
109
100
} catch (UnknownHostException uhe ) {
110
- uhe . printStackTrace ( );
101
+ logWarn ( "Unknown host" , uhe );
111
102
}
112
103
return hostname ;
113
104
}
@@ -132,4 +123,26 @@ static boolean mathesExcludesList(String hostname, List<String> excludesList) {
132
123
return excludesList .contains (hostname );
133
124
}
134
125
126
+ /**
127
+ * Log a warning.
128
+ *
129
+ * Can be overwritten to use a logger.
130
+ *
131
+ * @param msg The message.
132
+ * @param ex The exception.
133
+ */
134
+ protected void logWarn (String msg , Throwable ex ) {
135
+ System .err .println (msg + ": " + ex );
136
+ }
137
+
138
+ /**
139
+ * Log an info message.
140
+ *
141
+ * Can be overwritten to use a logger.
142
+ *
143
+ * @param msg The message to log.
144
+ */
145
+ protected void logInfo (String msg ) {
146
+ System .out .println (msg );
147
+ }
135
148
}
0 commit comments