I read the section on Filters and the spec seems to be silent on some issues… Can you clarify?

Alessandro A. Garbagnati

1. Can a filter attach new objects to the request without having to create a request wrapper. I have no need to override any methods in request just make available some objects downstream to other filters and the servlet.

2. What happens when a filter throws an exception other than UnavailableException. Does the container continue to go on. I mean is my only choice to have a catch block and not do a doFilter in it or does an exception automatically halt the processing down the filter chain and the servlet.

3. I have an authentication filter and I want to do a mapping to /* so that all requests pass thro' authentication. However I need to add some extra filters to servlets by name. Is this possible.?

4. Is there any way to create a filter chain on the fly? I have to string together a number of reusable components. But which ones I use will depend on some parameters in the URL.

Let me try to give you some answers or, better, the way I interpret the specs.

1) Yes, I definitely think so. You have both the request and response objects and so you should be able to attach objects in the request scope with setAttribute(String, Object).

2) I think that the better way to discover that is to try. Personally I think that for the scenario you have described, the servlet container will get the exception halting the process.

3-4) Yes, you should be able to achieve what you need, maybe trying to create some kind of filter factory and chain the created filter to the one you need.
It looks like an interesting thing to try... As soon I have some free time, I'm going to try it myself.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact