1 package example.filters; 2 3 import javax.servlet.*; 4 import javax.servlet.http.*; 5 import java.io.IOException ; 6 7 import java.util.Enumeration ; 8 import java.security.Principal ; 9 10 import java.util.logging.Logger ; 11 import java.util.logging.Level ; 12 13 16 17 public class ExampleRequestFilter implements Filter { 18 private static final Logger log = Logger.getLogger("example.filters.ExampleRequestFilter"); 19 20 25 public void init(FilterConfig config) 26 throws ServletException 27 { 28 ServletContext app = config.getServletContext(); 29 30 String myParam = config.getInitParameter("my-param"); 32 if (log.isLoggable(Level.CONFIG)) 33 log.log(Level.CONFIG,"my-param value is `" + myParam + "'"); 34 } 35 36 43 public void doFilter(ServletRequest request, ServletResponse response, 44 FilterChain nextFilter) 45 throws ServletException, IOException 46 { 47 HttpServletRequest req = (HttpServletRequest) request; 48 HttpServletResponse res = (HttpServletResponse) response; 49 50 req = new ExampleRequestWrapper(req); 54 55 nextFilter.doFilter(req, res); 57 } 58 59 63 64 public void destroy() 65 { 66 } 67 68 74 static class ExampleRequestWrapper extends HttpServletRequestWrapper { 75 ExampleRequestWrapper(HttpServletRequest request) 76 { 77 super(request); 78 } 79 80 83 public String getMethod() 84 { 85 return super.getMethod(); 86 } 87 88 91 public String getRequestURI() 92 { 93 return super.getRequestURI(); 94 } 95 96 99 public StringBuffer getRequestURL() 100 { 101 return super.getRequestURL(); 102 } 103 104 112 public String getContextPath() 113 { 114 return super.getContextPath(); 115 } 116 117 127 public String getServletPath() 128 { 129 return super.getServletPath(); 130 } 131 132 142 public String getPathInfo() 143 { 144 return super.getPathInfo(); 145 } 146 147 152 public String getPathTranslated() 153 { 154 return super.getPathTranslated(); 155 } 156 157 162 public String getQueryString() 163 { 164 return super.getQueryString(); 165 } 166 167 177 public String getHeader(String name) 178 { 179 return super.getHeader(name); 180 } 181 182 189 public Enumeration getHeaders(String name) 190 { 191 return super.getHeaders(name); 192 } 193 194 197 public Enumeration getHeaderNames() 198 { 199 return super.getHeaderNames(); 200 } 201 202 208 public int getIntHeader(String name) 209 { 210 return super.getIntHeader(name); 211 } 212 213 223 public long getDateHeader(String name) 224 { 225 return super.getDateHeader(name); 226 } 227 228 231 public Cookie []getCookies() 232 { 233 return super.getCookies(); 234 } 235 236 242 public HttpSession getSession(boolean create) 243 { 244 return super.getSession(create); 245 } 246 247 253 public String getRequestedSessionId() 254 { 255 return super.getRequestedSessionId(); 256 } 257 258 261 public boolean isRequestedSessionIdValid() 262 { 263 return super.isRequestedSessionIdValid(); 264 } 265 266 269 public boolean isRequestedSessionIdFromCookie() 270 { 271 return super.isRequestedSessionIdFromCookie(); 272 } 273 274 277 public boolean isRequestedSessionIdFromURL() 278 { 279 return super.isRequestedSessionIdFromURL(); 280 } 281 282 285 public String getAuthType() 286 { 287 return super.getAuthType(); 288 } 289 290 293 public String getRemoteUser() 294 { 295 return super.getRemoteUser(); 296 } 297 298 301 public boolean isUserInRole(String role) 302 { 303 return super.isUserInRole(role); 304 } 305 306 309 public Principal getUserPrincipal() 310 { 311 return super.getUserPrincipal(); 312 } 313 } 314 } 315 316 | Popular Tags |