Servlet filters not working with AppEngine manual

2019-09-12 06:00发布

I am using Google AppEngine with java. I have configured for manual scaling by adding the following in appengine-web.xml

<manual-scaling>
    <instances>1</instances>
</manual-scaling>

But after I add this, I am not able to use servlet filters with the following mapping in web.xml.

<filter>
    <filter-name>testFilter</filter-name>
    <filter-class>com.fms.test.TestFilter</filter-class> 
</filter>
<filter-mapping>
    <filter-name>testFilter</filter-name>
    <url-pattern>/_ah/api/*</url-pattern>  
    <url-pattern>/_ah/spi/*</url-pattern>  
</filter-mapping>

The filters will work if I give * as url-pattern, but that is not my requirement. Without the manual scaling, it is working as expected.

Can anybody tell me why I cant use it?

PS: I am in development environment and using AppEngine SDK version 1.9.42

Here is my filter code:

public class TestFilter implements Filter { 
    private static final AdvocacyUtils utils = AdvocacyUtils.getInstance();

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("Request filtered.");
    }

    @Override
    public void destroy() {
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException { 
    }
}

1条回答
一夜七次
2楼-- · 2019-09-12 06:09

I've found some workaround (here) Solution is to add into the "filter-mapping" aditional section - "dispatcher" like in this snippet:

<filter-mapping>
    <filter-name>ObjectifyFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>
查看更多
登录 后发表回答