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. I'm explicitly defining them in that order to ensure that the cookieParameterFilter is called /first/ to ensure that the parameters are converted into Cookies before the cookieUserFilter is called.

In order to get the cookieParameterFilter to be called, I have to configure it like this in my filter-mapping:

<filter-mapping>
  <filter-name>cookieParameterFilter</filter-name>
  <url-pattern>*.do</url-pattern>
<url-pattern>*.xml.do</url-pattern><!-- this probably no longer matters -->
  <url-pattern>/some/specific/pattern</url-pattern>
<filter-pattern>

This means it will apply to all requests, which isn't what I want.

The only thing I can think of is that *.xml.do isn't mapped to any specific servlet, while *.do /is/. Will <filter>s only apply to URL patterns that are explicitly-mapped to a specific servlet?

That doesn't sound right to me. I have other mappings that only map to a URL space and not anything that has a specific servlet mapping.

What am I missing?

This is Tomcat 9.0.85 and everything is defined in WEB-INF/web.xml.

-chris

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

Reply via email to