вт, 16 апр. 2024 г. в 18:17, Christopher Schultz <ch...@christopherschultz.net>: > > All, > > I'm not sure if this is the first time I've tried something like this, > but I was surprised by the behavior I observed today when trying to > configure a new Filter. > > I have an existing Filter that looks at Cookies provided in a request. > > I wanted to add a new Filter that takes request parameters and returns > them from request.getCookies() but only for a small number of URL > patterns which we handle only internally, both for security (?) and also > for performance, since this isn't a really common thing for us to do. > > So I have these two filters: > > <filter> > <filter-name>cookieUserFilter</filter-name> > <filter-class>...</filter-class> > </filter> > > <filter> > <filter-name>cookieParameterFilter</filter-name> > <filter-class>...</filter-class> > </filter> > > <filter-mapping> > <filter-name>cookieParameterFilter</filter-name> > <url-pattern>*.xml.do</url-pattern> > <url-pattern>/some/specific/pattern</url-pattern> > <filter-pattern> > > <filter-mapping> > <filter-name>cookieUserFilter</filter-name> > <url-pattern>*.do</url-pattern> > <url-pattern>*.jsp</url-pattern> > <filter-pattern> > > I have tested that both Filters work as expected when called. However, > when I configure them as above and request /foo.xml.do, only the > cookieUserFilter is being called. The cookieParameterFilter is not being > called. >[...] > > What am I missing? > > This is Tomcat 9.0.85 and everything is defined in WEB-INF/web.xml.
Hi, Chris! The Servlet 4.0 specification (the one that applies to Tomcat 9) says: 1) ch. 12.2 Specification of Mappings "A string beginning with a ‘ *. ’ prefix is used as an extension mapping." searching for "extension" finds: 2) ch 12.1 Use of URL Paths "3. If the last segment in the URL path contains an extension (e.g. .jsp), the servlet container will try to match a servlet that handles requests for the extension. An extension is defined as the part of the last segment after the last ’ . ’ character." As it says "after the last '.' character" then by this design <url-pattern>*.xml.do</url-pattern> cannot match anything. (You may look at how o.a.catalina.mapper.Mapper actually works. Look for extensionWrappers and method internalMapExtensionWrapper().) Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org