CHAPTER 11 ADVANCED FILTERING TECHNIQUES 451 Filter
CHAPTER 11 ADVANCED FILTERING TECHNIQUES 453 public class LegacyAdapterRequestWrapper extends HttpServletRequestWrapper { String myDept = null; public LegacyAdapterRequestWrapper(HttpServletRequest inReq, String deptString) { super(inReq); myDept = deptString; } public Map getParameterMap() { Map tmpMap = super.getParameterMap(); tmpMap.put(”DEPT”, myDept); return tmpMap; } public String[] getParameterValues(String paramName) { if (paramName.equalsIgnoreCase(”DEPT”)) { String[] tpAry = new String[1]; tpAry[0] = myDept; return tpAry; } else { return super.getParameterValues(paramName); } } public String getParameter(String paramName) { if (paramName.equalsIgnoreCase(”DEPT”)) { return myDept; } else { return super.getParameter(paramName); } } } In this example, the filter wraps the incoming request. Unlike the VisAudit filter (which wrapped the response), this filter will actually be modifying header information associated with the incoming request. This wrapper class, called LegacyAdapterRequestWrapper, extends the useful HttpServletRequestWrapper class. HttpServletRequestWrapper will take as an argument for its constructor the actual HttpServletRequest to wrap. It implements all of its methods by calling the methods of the wrapped request. By inheriting from this class, we can choose to override only the methods that we re interested in. Note that the class takes the department as an argument for the constructor, and stores the value in an instance variable. The methods that the class provides custom implementation for are getParameterMap(), getParameterValues(), and getParameter(). This ensures that the class can work with most of the resources that may access parameters. In fact, for the specific JSP that will be filtered, the
Note: If you are looking for good and high quality web space to host and run your jsp application check Lunarwebhost jsp web hosting services