首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FIlter链循环问题-超过100个线程在背后工作?

FIlter链循环问题-超过100个线程在背后工作?
EN

Stack Overflow用户
提问于 2014-05-26 17:22:50
回答 2查看 272关注 0票数 0

我的过滤器有个奇怪的问题。我想捕捉从JCIFS Ntlm Http过滤器抛出的异常。过滤器链从我的自定义过滤器开始,我用try-catch块包围了chain.doFilter()部分,以便能够在发生任何异常时重定向响应。下面是web.xml的代码:

代码语言:javascript
复制
    <filter>
        <filter-name>NTLM_FILTER_CHAIN_START_POINT</filter-name>
        <filter-class>filters.JcifsNtlmWrapperFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>NTLM_FILTER_CHAIN_START_POINT</filter-name>
        <url-pattern>/ntlm/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>NTLM_HTTP_AUTHENTICATION_FILTER</filter-name>
        <filter-class>filters.JcifsNtlmFilterImpl</filter-class>
        <!-- init params goes here -->
    </filter>
    <filter-mapping>
        <filter-name>NTLM_HTTP_AUTHENTICATION_FILTER</filter-name>
        <url-pattern>/ntlm/*</url-pattern>
    </filter-mapping>

JcifsNtlmWrapperFilter.java:

代码语言:javascript
复制
public class JcifsNtlmWrapperFilter implements Filter {

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

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        HttpSession session = request.getSession(true);

        try{
            filterChain.doFilter(servletRequest, servletResponse);
        }catch (Exception e){
            System.out.println("--------------- Catching Exception ------------");
            session.setAttribute("error", "NTLMFailedToAuthenticate");
            response.sendRedirect("/");
        }
    }

    @Override
    public void destroy() {}
}

在JcifsNtlmFilterImpl.java中,我只是抛出了一个异常(只是为了测试):

代码语言:javascript
复制
public void doFilter( ServletRequest request,
                          ServletResponse response,
                          FilterChain chain ) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest)request;
        HttpServletResponse resp = (HttpServletResponse)response;
        NtlmPasswordAuthentication ntlm;

        System.out.println("--------------- NTLM Filtering ------------");
        if(1==1){
            System.out.println("--------------- Throwing Exception ------------");
            throw new IOException();
        }


        if ((ntlm = negotiate( req, resp, false )) == null) {
            return;
        }

        chain.doFilter( new NtlmHttpServletRequest( req, ntlm ), response );
    }

一切都按预期运行。用户在NTLM过滤器中看不到任何抛出的错误消息(而是看到普通的身份验证登录页面),但是当我查看glassfish日志时,我看到超过100个线程正在经历这个过滤器周期(从日志中复制粘贴的一小部分):

代码语言:javascript
复制
[#|2014-05-26T14:16:02.892+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=109;_ThreadName=Thread-2;|USER IP:127.0.0.1|#]

[#|2014-05-26T14:16:02.909+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=108;_ThreadName=Thread-2;|--------------- NTLM Filtering ------------|#]

[#|2014-05-26T14:16:02.910+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=108;_ThreadName=Thread-2;|--------------- Throwing Exception ------------|#]

[#|2014-05-26T14:16:02.910+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=108;_ThreadName=Thread-2;|--------------- Catching Exception ------------|#]

[#|2014-05-26T14:16:02.927+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=110;_ThreadName=Thread-2;|USER IP:127.0.0.1|#]

[#|2014-05-26T14:16:02.942+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=111;_ThreadName=Thread-2;|--------------- NTLM Filtering ------------|#]

[#|2014-05-26T14:16:02.942+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=111;_ThreadName=Thread-2;|--------------- Throwing Exception ------------|#]

[#|2014-05-26T14:16:02.942+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=111;_ThreadName=Thread-2;|--------------- Catching Exception ------------|#]

[#|2014-05-26T14:16:02.959+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=107;_ThreadName=Thread-2;|USER IP:127.0.0.1|#]

[#|2014-05-26T14:16:02.978+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=109;_ThreadName=Thread-2;|--------------- NTLM Filtering ------------|#]

[#|2014-05-26T14:16:02.978+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=109;_ThreadName=Thread-2;|--------------- Throwing Exception ------------|#]

[#|2014-05-26T14:16:02.978+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=109;_ThreadName=Thread-2;|--------------- Catching Exception ------------|#]

[#|2014-05-26T14:16:03.004+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=108;_ThreadName=Thread-2;|USER IP:127.0.0.1|#]

[#|2014-05-26T14:16:03.019+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=110;_ThreadName=Thread-2;|--------------- NTLM Filtering ------------|#]

[#|2014-05-26T14:16:03.019+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=110;_ThreadName=Thread-2;|--------------- Throwing Exception ------------|#]

[#|2014-05-26T14:16:03.019+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=110;_ThreadName=Thread-2;|--------------- Catching Exception ------------|#]

[#|2014-05-26T14:16:03.034+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=111;_ThreadName=Thread-2;|USER IP:127.0.0.1|#]

[#|2014-05-26T14:16:03.051+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=107;_ThreadName=Thread-2;|--------------- NTLM Filtering ------------|#]

[#|2014-05-26T14:16:03.051+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=107;_ThreadName=Thread-2;|--------------- Throwing Exception ------------|#]

[#|2014-05-26T14:16:03.052+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=107;_ThreadName=Thread-2;|--------------- Catching Exception ------------|#]

[#|2014-05-26T14:16:03.067+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=109;_ThreadName=Thread-2;|USER IP:127.0.0.1|#]

[#|2014-05-26T14:16:03.081+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=108;_ThreadName=Thread-2;|--------------- NTLM Filtering ------------|#]

[#|2014-05-26T14:16:03.082+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=108;_ThreadName=Thread-2;|--------------- Throwing Exception ------------|#]

[#|2014-05-26T14:16:03.082+0500|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=108;_ThreadName=Thread-2;|--------------- Catching Exception ------------|#]
EN

回答 2

Stack Overflow用户

发布于 2014-05-26 17:29:32

只是猜测,但也许

代码语言:javascript
复制
response.sendRedirect("/");

正在把你送到你的欢迎页面,这恰好是一些东西再次触发过滤器链,冲洗并重复...您是否尝试过重定向到/ntlm/*模式之外的某些特定资源?例如,重定向到http://www.google.com,然后查看这是否会在您的日志中产生相同的结果。

票数 0
EN

Stack Overflow用户

发布于 2014-05-26 18:03:29

如果你想在捕捉到一些异常时返回,而不想调用left filter。

您可能需要从ContainerRequestContext类调用以下代码:requestContext.abortWith(*,*)

可能需要检查Filter类中的相关方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23866841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档