2015-06-25 23:11 GMT+03:00 Leo Donahue <donahu...@gmail.com>: > 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
1. A Filter can generate the response by itself. There is no need to call the chain. An example in Tomcat: org.apache.catalina.filters.RemoteAddrFilter org.apache.catalina.filters.RequestFilter#process(...) 2. There are several types of dispatch defined in Servlet specification. See e.g. javax.servlet.DispatcherType enumeration. Usually a Filter is configured to serve 'REQUEST' dispatches. Thus an 'ERROR' dispatch (triggered by sendError()) bypasses the filter. Read about filters in the Servlet specification. Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org