Bug 43338

Summary: Setting '*' as the servlet-name in filter-mapping causes IllegalArgumentException.
Product: Tomcat 6 Reporter: Keiichi Fujino <keiichi.fujino>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: srowen
Priority: P1    
Version: 6.0.14   
Target Milestone: default   
Hardware: All   
OS: All   

Description Keiichi Fujino 2007-09-10 03:45:11 UTC
SRV 6.2.5 says supporting for '*' as the servlet-name in filter-mapping.
I set following filter-mapping.
    <filter-mapping>
        <filter-name>SampleFilter</filter-name>
        <servlet-name>*</servlet-name>
    </filter-mapping>

However, InvocationTargetException occurred in Digester. 
It is as follows.

Sep 10, 2007 7:16:56 PM org.apache.tomcat.util.digester.Digester endElement
SEVERE: End event threw exception
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.apache.tomcat.util.IntrospectionUtils.callMethod1
(IntrospectionUtils.java:899)
	at org.apache.tomcat.util.digester.SetNextRule.end
(SetNextRule.java:193)
	at org.apache.tomcat.util.digester.Rule.end(Rule.java:229)
	at org.apache.tomcat.util.digester.Digester.endElement
(Digester.java:1058)
	omit...
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.IllegalArgumentException: Filter mapping must specify 
either a <url-pattern> or a <servlet-name>
	at org.apache.catalina.core.StandardContext.addFilterMap
(StandardContext.java:2160)
	... 44 more
   omit...


I made a StandardContext's patch.

Index:/tomcat6-trunk/java/org/apache/catalina/core/StandardContext.java
===================================================================
--- /tomcat6-trunk/java/org/apache/catalina/core/StandardContext.java
	(revision 574195)
+++ /tomcat6-trunk/java/org/apache/catalina/core/StandardContext.java
	(working copy)
@@ -2156,7 +2156,9 @@
         if (findFilterDef(filterName) == null)
             throw new IllegalArgumentException
                 (sm.getString("standardContext.filterMap.name", filterName));
-        if ((servletNames.length == 0) && (urlPatterns.length == 0))
+        if (!filterMap.getMatchAllServletNames() && 
+        		!filterMap.getMatchAllUrlPatterns() && 
+                (servletNames.length == 0) && (urlPatterns.length == 0))
             throw new IllegalArgumentException
                 (sm.getString("standardContext.filterMap.either"));
         // FIXME: Older spec revisions may still check this

I made a StandardContext's patch.

Regards.
Comment 1 Peter Rossbach 2007-09-14 23:53:05 UTC
OK!

I check you fix later today

Peter
Comment 2 Peter Rossbach 2007-09-15 00:56:16 UTC
Many thanks to report this bug
Peter
Comment 3 Mark Thomas 2008-11-03 06:29:12 UTC
*** Bug 42683 has been marked as a duplicate of this bug. ***