You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Wall <d....@computer.org> on 2015/08/28 20:47:39 UTC

Can filters be loaded more than once?

I'm using Tomcat 8.0.23, but wondered if a filter defined in the Tomcat 
conf/web.xml as well as defined in my app's WEB-INF/web.xml file causes 
the filter to be loaded twice or whether duplicate filters are ignored?

If duplicates are ignored, what makes it a "duplicate"?  Just the name, 
the filter-name and url-pattern combo?  The filter-class?

Is the filter-name field can sensitive?  Noted that Tomcat uses a 
lowercase 's' for it's filter name.

In Tomcat's conf/web.xml:

     <filter>
<filter-name>setCharacterEncodingFilter</filter-name>
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
         <init-param>
             <param-name>encoding</param-name>
             <param-value>UTF-8</param-value>
         </init-param>
         <async-supported>true</async-supported>
     </filter>

     <filter-mapping>
<filter-name>setCharacterEncodingFilter</filter-name>
         <url-pattern>/*</url-pattern>
     </filter-mapping>

In my webapp's WEB-INF/web.xml:

<filter>
<filter-name>SetCharacterEncodingFilter</filter-name>
     <filter-class>
org.apache.catalina.filters.SetCharacterEncodingFilter
     </filter-class>
     <async-supported>true</async-supported> <!-- Enable if using Vaadin 
PUSH -->
     <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
     </init-param>
</filter>

<filter-mapping>
     <filter-name>SetCharacterEncodingFilter</filter-name>
     <url-pattern>/*</url-pattern>
</filter-mapping>

When using Atmosphere with Vaadin PUSH, I occasionally get an exception 
that indicates an issue with async operations, and it shows my filter 
twice in the stack trace:

*java.lang.IllegalStateException: A filter or servlet of the current 
chain does not support asynchronous operations.**
*        at 
org.apache.catalina.connector.Request.startAsync(Request.java:1610)
       at 
org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1037)
       at 
javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:392)
       at 
org.atmosphere.cpr.AtmosphereRequest.startAsync(AtmosphereRequest.java:723)
       at 
org.atmosphere.container.Servlet30CometSupport.suspend(Servlet30CometSupport.java:93)
       at 
org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:68)
       at 
org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2075)
       at 
com.vaadin.server.communication.PushRequestHandler.handleRequest(PushRequestHandler.java:226)
       at 
com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1408)
       at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:351)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
       at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
       at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at 
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
       at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
       at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
*at 
org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)*
       at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
       at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
*at 
org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)*
       at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
       at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
       at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
       at 
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:614)
       at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
       at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
       at 
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
       at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
       at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
       at 
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
       at 
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)

Re: Can filters be loaded more than once?

Posted by David Wall <d....@computer.org>.
Thanks for the help, Chris.  I did note that some of the webapp web.xml 
files didn't include the async option.  I've decided for now we'll use 
Tomcat's conf/web.xml to set this basic filter and let our webapps not 
have to think about it.

On 8/28/15 12:27 PM, Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> David,
>
> On 8/28/15 2:47 PM, David Wall wrote:
>> I'm using Tomcat 8.0.23, but wondered if a filter defined in the
>> Tomcat conf/web.xml as well as defined in my app's WEB-INF/web.xml
>> file causes the filter to be loaded twice or whether duplicate
>> filters are ignored?
>>
>> If duplicates are ignored, what makes it a "duplicate"?  Just the
>> name, the filter-name and url-pattern combo?  The filter-class?
> I've never looked into this, but I would imagine that Tomcat does no
> checking for duplicate filter definitions. Otherwise, the above
> questions are raised :)
>
>> Is the filter-name field can sensitive?
> Almost certainly.
>
>> Noted that Tomcat uses a lowercase 's' for it's filter name.
>>
>> In Tomcat's conf/web.xml:
>>
>> <filter> <filter-name>setCharacterEncodingFilter</filter-name>
>> <filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</
> filter-class>
>>   <init-param> <param-name>encoding</param-name>
>> <param-value>UTF-8</param-value> </init-param>
>> <async-supported>true</async-supported> </filter>
>>
>> <filter-mapping>
>> <filter-name>setCharacterEncodingFilter</filter-name>
>> <url-pattern>/*</url-pattern> </filter-mapping>
> Note that the above Filter is commented-out by default.
>
>> In my webapp's WEB-INF/web.xml:
>>
>> <filter> <filter-name>SetCharacterEncodingFilter</filter-name>
>> <filter-class>
>> org.apache.catalina.filters.SetCharacterEncodingFilter
>> </filter-class> <async-supported>true</async-supported> <!-- Enable
>> if using Vaadin PUSH --> <init-param>
>> <param-name>encoding</param-name> <param-value>UTF-8</param-value>
>> </init-param> </filter>
>>
>> <filter-mapping>
>> <filter-name>SetCharacterEncodingFilter</filter-name>
>> <url-pattern>/*</url-pattern> </filter-mapping>
>>
>> When using Atmosphere with Vaadin PUSH, I occasionally get an
>> exception that indicates an issue with async operations, and it
>> shows my filter twice in the stack trace:
>>
>> *java.lang.IllegalStateException: A filter or servlet of the
>> current chain does not support asynchronous operations.** *
>> at
>> org.apache.catalina.connector.Request.startAsync(Request.java:1610)
> Boy,
> it would be nice if Tomcat told you which Filter of or Servlet of
> the current change didn't support asynchronous operations. I don't
> immediately see a good way of getting that information from the
> Request object. :(
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Comment: GPGTools - http://gpgtools.org
>
> iQIcBAEBCAAGBQJV4LYQAAoJEBzwKT+lPKRYjMoQAJuw/bu4Efmw/Mc0tm6hXaaU
> fJBSSsfZJfPGzahCvMGRTciTEe/E7cjsSIHgkdZKy1UUYSx2mnLZNTkiMaQRu2Sg
> XmmN6nzKC7dtNPrYGgkN+RqbUJXjpeO0vV6RLJHdzGcQ9vQ4409t733QQuFbuzeS
> DfcCCnSiwK8i4APQyuQWpuT4Th/kyehZfp4mtlIQHN6BsmekRH6VUIHI9rRajPgF
> zUtPEXnqdlXOD5B2dtRDePQNBVIO5s8Es+GzD68L2m/XseIt6WxbHUYe8lGcKp6g
> 7O7LBfe+VhgCaIsoC/aPJ9hyA75z1p/O1h8Rcb8ft4G8BYdvVYQl6Dc76XzYdVYy
> RdSu5FaGBRsCAromAJ0/ThSa2oKPMcrINUkMDdoMGE12Rr5+d/QVO6jMlpq0MgqY
> PkXox+eB7pzcFFUkU4wWDOe3xqVHgMWW4E3dop+tfCHti9HDhfcgUNP6ch7MAEIm
> 8+3iZ8DKeyqmvp1TQn9HQcM/I+or0qE3GvQsYZR00Z4C7Rp4/QdmMMhZwNoqgnHw
> kCxrIgCA2KPeEBYVkTsx9LG0P8dzitDps3EFLTsETSygfd1JmrCPx+8PlrAgjkcM
> 7FnrJAHX1fZ28EoNMmdf8f0FJ3InmBB9APO3Kw+YbayJeZxuV4gg/dAPZT3PGI0p
> RYZ2Ubhc8zpwgOTjEHMC
> =DJRR
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


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


Re: Can filters be loaded more than once?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

David,

On 8/28/15 2:47 PM, David Wall wrote:
> I'm using Tomcat 8.0.23, but wondered if a filter defined in the
> Tomcat conf/web.xml as well as defined in my app's WEB-INF/web.xml
> file causes the filter to be loaded twice or whether duplicate
> filters are ignored?
> 
> If duplicates are ignored, what makes it a "duplicate"?  Just the
> name, the filter-name and url-pattern combo?  The filter-class?

I've never looked into this, but I would imagine that Tomcat does no
checking for duplicate filter definitions. Otherwise, the above
questions are raised :)

> Is the filter-name field can sensitive?

Almost certainly.

> Noted that Tomcat uses a lowercase 's' for it's filter name.
> 
> In Tomcat's conf/web.xml:
> 
> <filter> <filter-name>setCharacterEncodingFilter</filter-name> 
> <filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</
filter-class>
>
>  <init-param> <param-name>encoding</param-name> 
> <param-value>UTF-8</param-value> </init-param> 
> <async-supported>true</async-supported> </filter>
> 
> <filter-mapping> 
> <filter-name>setCharacterEncodingFilter</filter-name> 
> <url-pattern>/*</url-pattern> </filter-mapping>

Note that the above Filter is commented-out by default.

> In my webapp's WEB-INF/web.xml:
> 
> <filter> <filter-name>SetCharacterEncodingFilter</filter-name> 
> <filter-class> 
> org.apache.catalina.filters.SetCharacterEncodingFilter 
> </filter-class> <async-supported>true</async-supported> <!-- Enable
> if using Vaadin PUSH --> <init-param> 
> <param-name>encoding</param-name> <param-value>UTF-8</param-value> 
> </init-param> </filter>
> 
> <filter-mapping> 
> <filter-name>SetCharacterEncodingFilter</filter-name> 
> <url-pattern>/*</url-pattern> </filter-mapping>
> 
> When using Atmosphere with Vaadin PUSH, I occasionally get an
> exception that indicates an issue with async operations, and it
> shows my filter twice in the stack trace:
> 
> *java.lang.IllegalStateException: A filter or servlet of the
> current chain does not support asynchronous operations.** *
> at 
> org.apache.catalina.connector.Request.startAsync(Request.java:1610)

Boy,
> 
it would be nice if Tomcat told you which Filter of or Servlet of
the current change didn't support asynchronous operations. I don't
immediately see a good way of getting that information from the
Request object. :(

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJV4LYQAAoJEBzwKT+lPKRYjMoQAJuw/bu4Efmw/Mc0tm6hXaaU
fJBSSsfZJfPGzahCvMGRTciTEe/E7cjsSIHgkdZKy1UUYSx2mnLZNTkiMaQRu2Sg
XmmN6nzKC7dtNPrYGgkN+RqbUJXjpeO0vV6RLJHdzGcQ9vQ4409t733QQuFbuzeS
DfcCCnSiwK8i4APQyuQWpuT4Th/kyehZfp4mtlIQHN6BsmekRH6VUIHI9rRajPgF
zUtPEXnqdlXOD5B2dtRDePQNBVIO5s8Es+GzD68L2m/XseIt6WxbHUYe8lGcKp6g
7O7LBfe+VhgCaIsoC/aPJ9hyA75z1p/O1h8Rcb8ft4G8BYdvVYQl6Dc76XzYdVYy
RdSu5FaGBRsCAromAJ0/ThSa2oKPMcrINUkMDdoMGE12Rr5+d/QVO6jMlpq0MgqY
PkXox+eB7pzcFFUkU4wWDOe3xqVHgMWW4E3dop+tfCHti9HDhfcgUNP6ch7MAEIm
8+3iZ8DKeyqmvp1TQn9HQcM/I+or0qE3GvQsYZR00Z4C7Rp4/QdmMMhZwNoqgnHw
kCxrIgCA2KPeEBYVkTsx9LG0P8dzitDps3EFLTsETSygfd1JmrCPx+8PlrAgjkcM
7FnrJAHX1fZ28EoNMmdf8f0FJ3InmBB9APO3Kw+YbayJeZxuV4gg/dAPZT3PGI0p
RYZ2Ubhc8zpwgOTjEHMC
=DJRR
-----END PGP SIGNATURE-----

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