Leo Donahue wrote:
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException

Assuming you have only a single Filter configured in web.xml

Assuming you have logic in a doFilter that checks the value of a boolean.
If the boolean is true, then assume you send a http status code back and
use a "return" in the if condition.

example:

        if (someConditionIsTrue)
        {
            HttpServletResponse httpResponse = (HttpServletResponse)
response;
            httpResponse.sendError(HttpServletResponse.WHATEVER_YOU_CHOOSE);
            return;
        }

        chain.doFilter(request, response);


My question is:

If the chain is placed inside an else, which would not run if the condition
is true, does that violate the Filter in any way?  In other words, if one
does not call chain.doFilter within a doFilter method, should one expect
something bad?

What I'm really saying without saying it is, whether I call chain.doFilter
in or out of an "else", on Tomcat I get the sendError status that I expect,
but not from other containers.  I realize that statement is moot on this
list, but I thought I would share it.

Are there any conditions in which Tomcat will decide what to do on its own,
related to sendError, when it can't figure it out from code?

Leo


Using CATALINA_BASE:   "C:\apache-tomcat\apache-tomcat-7.0.62"
Using CATALINA_HOME:   "C:\apache-tomcat\apache-tomcat-7.0.62"
Using CATALINA_TMPDIR: "C:\apache-tomcat\apache-tomcat-7.0.62\temp"
Using JRE_HOME:        "C:\Program Files (x86)\Java\jdk1.7.0_67"
Using CLASSPATH:
"C:\apache-tomcat\apache-tomcat-7.0.62\bin\bootstrap.jar;C:\apache-tomcat\apache-tomcat-7.0.62\bin\tomcat-juli.jar"
Server version: Apache Tomcat/7.0.62
Server built:   May 7 2015 17:14:55 UTC
Server number:  7.0.62.0
OS Name:        Windows 7
OS Version:     6.1
Architecture:   x86
JVM Version:    1.7.0_67-b01
JVM Vendor:     Oracle Corporation


I must admit that your question above was a bit difficult to follow, in terms of if/then/else/unless, particularly late at night. And the last paragraph made me think that perhaps the Tomcat logo might lead you to personalise things a bit more than is really healthy. (Or else I want to have a look at that code, because the Tomcat developers must be even smarter that I thought).

But if your question in the end boils down to : *must* a filter necessarily call the next filter/webapp in the chain, then the answer is in the Servlet Specification.
E.g. Servlet Spec v 3.0 final, Chapt 6 Filtering, Section 6.2 Main concepts, 
item 4 :
"The filter *may* invoke the next entity in the filter chain"..
It even adds : "Alternatively, the filter chain can block the request by not making the call to invoke the next entity, leaving the filter responsible for filling out the response object."

(What you need to do then still, is to insure that you do indeed generate a valid response, whether it's an error or not. That's maybe the point where different containers may react slightly differently.).



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to