1 16 17 package org.apache.tester; 18 19 20 import java.io.*; 21 import java.util.*; 22 import javax.servlet.*; 23 import javax.servlet.http.*; 24 25 32 33 public class WrapperFilter implements Filter { 34 35 36 38 39 40 42 43 46 protected FilterConfig config = null; 47 48 49 52 protected String requestWrapper = "none"; 53 54 55 58 protected String responseWrapper = "none"; 59 60 61 63 64 67 public void destroy() { 68 69 config = null; 70 requestWrapper = "none"; 71 responseWrapper = "none"; 72 73 } 74 75 76 79 public void doFilter(ServletRequest inRequest, ServletResponse inResponse, 80 FilterChain chain) 81 throws IOException, ServletException { 82 83 ServletRequest outRequest = inRequest; 85 ServletResponse outResponse = inResponse; 86 if (requestWrapper.equals("generic")) { 87 outRequest = new TesterServletRequestWrapper(inRequest); 88 } else if (requestWrapper.equals("http")) { 89 outRequest = new TesterHttpServletRequestWrapper 90 ((HttpServletRequest) inRequest); 91 } 92 if (responseWrapper.equals("generic")) { 93 outResponse = new TesterServletResponseWrapper(inResponse); 94 } else if (responseWrapper.equals("http")) { 95 outResponse = new TesterHttpServletResponseWrapper 96 ((HttpServletResponse) inResponse); 97 } 98 99 chain.doFilter(outRequest, outResponse); 101 102 } 103 104 105 110 public void init(FilterConfig config) throws ServletException { 111 112 this.config = config; 113 String value = null; 114 value = config.getInitParameter("request"); 115 if (value != null) 116 requestWrapper = value; 117 value = config.getInitParameter("response"); 118 if (value != null) 119 responseWrapper = value; 120 121 } 122 123 124 } 125 | Popular Tags |