FileDocCategorySizeDatePackage
RequestInfoFilter.javaAPI DocExample2668Sun Nov 23 16:09:00 GMT 2003decoratorexample.controller

RequestInfoFilter

public class RequestInfoFilter extends Object implements Filter
A simple filter to print out information about requests that we receive.

Fields Summary
private FilterConfig
filterConfig
Constructors Summary
public RequestInfoFilter()
Constructor

    
          
      
    
Methods Summary
public voiddestroy()
Called when the filter is deactivated

    
public voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
Perform the actual filtering. Log request parameters and attributes to the ServletContext log

        ServletContext sc = filterConfig.getServletContext();
        
        // preprocess the request
        HttpServletRequest hrs = (HttpServletRequest)request;
        sc.log("Request Attributes:");
        sc.log("Method: " + hrs.getMethod());
        sc.log("QueryString: " + hrs.getQueryString());
        sc.log("Context: " + hrs.getContextPath());
        sc.log("RequestURL: " + hrs.getRequestURL());
        sc.log("RequestURI: " + hrs.getRequestURI());
        sc.log("PathInfo: " + hrs.getPathInfo());
        sc.log("ServletPath: " + hrs.getServletPath());
     
        // enumerate all parameters
        sc.log("Parameters:");    
        for (Enumeration e = request.getParameterNames(); e.hasMoreElements(); ) {
             String name = (String) e.nextElement();
             String vals[] = request.getParameterValues(name);
             
             StringBuffer out = new StringBuffer();
             out.append(name + "=");
             
             // each parameter may have multiple values
             for(int i = 0; i < vals.length; i++) {
                 out.append(vals[i]);
             }
             
             // remove the trailing comma
             sc.log(out.substring(0, out.length() - 1));
        }
        
        // invoke the next filter in the chain
        chain.doFilter(request, response);
    
public voidinit(javax.servlet.FilterConfig filterConfig)
Called when the filter is initialized

        this.filterConfig = filterConfig;