Question

I have a WAR file that defines a filter to run on all URLs:

<!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
...
<filter>
    <filter-name>OurRedirectServletFilter</filter-name>
    <filter-class>com.mycompany.RedirectServletFilter</filter-class>
</filter>
...
<filter-mapping>
    <filter-name>OurRedirectServletFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

The filter is designed to perform some redirects from 'convenience' URLs to a corresponding 'actual' URL, but I don't think that's really relevant to the problem.

On WebSphere 7.0, this filter doesn't run for requests to the root URL, e.g. /ctxroot or /ctxroot/; instead I just get a 404 response. It does run for /ctxroot/blah, whether blah is a valid or invalid path.

I've tried adding additional filter mappings for URL patterns <url-pattern>/</url-pattern> and <url-pattern></url-pattern>, but I get the same behavior.

I've tested on base WAS 7.0.0.0, and with the latest fix pack applied, i.e. WAS 7.0.0.27.

The filter works as expected on WAS 8.5 and I'm pretty sure on WAS 8.0, as well as on every version of WebLogic, JBoss, and Tomcat that I've tried. This then seems to be a bug with WAS 7.0, but I'd still like to find a workaround. Anybody know of one?

Was it helpful?

Solution

I eventually looked at the body of the 404 error response and saw error code SRVE0190E, which led me to this helpful page. The issue is that filters aren't called by default for URLs that correspond to resources that don't exist (though I swear I tested that for a URL other than the context root, and my filter was called).

It's possible to configure WebSphere to call filters in this situation by setting a custom property as further described in the linked page:

com.ibm.ws.webcontainer.invokefilterscompatibility=true

I also found that for the case of the context root URL, setting a welcome-file entry in web.xml that maps to an existing resource causes the filter to be called:

<welcome-file-list>
    <welcome-file>fakehome.html</welcome-file>
</welcome-file-list>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top