Bug 49922 - ApplicationFilterChain more than the same filter
Summary: ApplicationFilterChain more than the same filter
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: trunk
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
: 63039 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-09-14 02:32 UTC by heyoulin
Modified: 2018-12-26 17:27 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description heyoulin 2010-09-14 02:32:04 UTC
When i web.xml like this:

<filter>
    <filter-name>Seam Filter</filter-name>
    <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>Seam Filter</filter-name>
    <url-pattern>/app/yofc/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>Seam Filter</filter-name>
    <url-pattern>*.seam</url-pattern>
  </filter-mapping>

then ApplicationFilterChain have two same Seam Filter.

this would cause some app error. Patch:

void addFilter(ApplicationFilterConfig filterConfig) {
    	for(ApplicationFilterConfig filter:filters)
    		if(filter==filterConfig)
    			return;
        if (n == filters.length) {
            ApplicationFilterConfig[] newFilters =
                new ApplicationFilterConfig[n + INCREMENT];
            System.arraycopy(filters, 0, newFilters, 0, n);
            filters = newFilters;
        }
        filters[n++] = filterConfig;

    }
Comment 1 Mark Thomas 2010-10-03 13:27:35 UTC
Fixed in trunk and will be included in 7.0.4 onwards.
Comment 2 Konstantin Kolinko 2013-01-08 21:58:16 UTC
While

a) I do not have a use case where calling the same filter several times would be useful, and

b) I find this feature of allowing only 1 instance of Filter per FilterChain useful and lessing the overall confusion,

I think that this feature is not what is written in the specification.

I raised
https://java.net/jira/browse/SERVLET_SPEC-52


There is a test case for this feature in TestStandardContext class. See r1004006 r1022068 .
Comment 3 Christopher Schultz 2013-01-08 22:30:22 UTC
(In reply to comment #2)
> While
> 
> a) I do not have a use case where calling the same filter several times
> would be useful, and
> 
> b) I find this feature of allowing only 1 instance of Filter per FilterChain
> useful and lessing the overall confusion,
> 
> I think that this feature is not what is written in the specification.

Can this not be solved by declaring the same filter twice like this:

<filter>
  <filter-name>Filter Copy 1</filter-name>
  <filter-class>...</filter-class>
</filter>
<filter>
  <filter-name>Filter Copy 2</filter-name>
  <filter-class>...</filter-class>
</filter>

...

<filter-mapping>
  <filter-name>Filter Copy 1</filter-name>
  <url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
  <filter-name>Filter Copy 1</filter-name>
  <url-pattern>/foo/*</url-pattern>
</filter-mapping>

The above should apply both filters to e.g. /foo/bar.jsp
Comment 4 Mark Thomas 2018-12-26 17:27:05 UTC
*** Bug 63039 has been marked as a duplicate of this bug. ***