Servlet过滤器不适用于AppEngine手动缩放 [英] Servlet filters not working with AppEngine manual scaling

查看:91
本文介绍了Servlet过滤器不适用于AppEngine手动缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google AppEngine和java。
我通过在appengine-web.xml中添加以下内容来配置手动缩放:

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

但是在我添加这个之后,我无法在web中使用带有以下映射的servlet过滤器。 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>

如果我将*作为url-pattern,过滤器将工作,但这不是我的要求。如果没有手动缩放,它就会按预期工作。



有人可以告诉我为什么我不能使用它吗?

PS:我在开发环境中使用AppEngine SDK 1.9.42版本

以下是我的过滤器代码:

  public class TestFilter implements Filter {
private static final AdvocacyUtils utils = AdvocacyUtils.getInstance();
$ b $ public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)throws IOException,ServletException {
System.out.println(Request filtered。);

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


解决方案

我找到了一些解决方法( here
解决方法是

 < filter-mapping>添加到过滤器映射aditional部分 - 调度程序 
< filter-name> ObjectifyFilter< / filter-name>
< url-pattern> / *< / url-pattern>
< dispatcher> REQUEST< / dispatcher>
< dispatcher> INCLUDE< / dispatcher>
< dispatcher> FORWARD< / dispatcher>
< / filter-mapping>


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 { 
    }
}

解决方案

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>

这篇关于Servlet过滤器不适用于AppEngine手动缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆