Originally posted by Michael Vargenstien:
5) So how does using a custom wrapper object sent on the Filter.doChain(req,customResponseObject) notify the servlet that the incoming request is from a filter?
The only thing I can think of (guessing) is that the HttpServletResponse(response) decoration occuring, somehow says, "Hey, I'm custom and I need you servlet to respond at TheAwesomeFilter.do
@5) Looks like you wrapped the response in this case, not the request.
I think you are having a hard time understanding because you're expecting a response wrapper to do something it was never meant to do.
It might become slightly clearer if you read up on the Decorator pattern. Basically, you'd wrap the request or response to change the way the request or response behaves and this happens transparently to the servlets - the servlets have no clue if they're communicating with a true naked request/response or a wrapped version of either one.
You have to look at the APIs of request and response to see what methods you might want to alter the behavior of.
I once had an application where we wanted every single text field to be trimmed so that there would never be leading or trailing space characters. A lot of the fields were number and money values and a value like "20 " with a space wouldn't pass number validation. I could have trimmed every single value at 1000 or so different spots in code but that would have been a nightmare to maintain. All I had to do was wrap the request in a wrapper that overrides the methods for getting parameters, and all those methods would do is trim the values before return them from the method. So the problem was solved with a filter and wrapper and I didn't have to change one line of code in Servlets or any other code.