Orchestra 和 RichFaces 问题

发布于 2024-09-16 17:02:09 字数 4042 浏览 9 评论 0原文

我在我的应用程序中使用 Orchestra 和 RichFaces。当访问我的应用程序中的页面时,我多次收到以下错误,并且页面无法加载:

WARN _ReentrantLock:103 - Waited for longer than 30000 milliseconds for access to lock org.apache.myfaces.orchestra.lib._ReentrantLock@78214f6b which is locked by thread http-8080-2

我相信问题的核心是我用于身份验证的过滤器。下面是它的代码(conversationController 是一个对话范围的 bean):

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,  FilterChain chain)
    throws IOException, ServletException
    {           
        FacesContextBuilder builder = new FacesContextBuilder();

        FacesContext facesContext = builder.getFacesContext(request, response);
        ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
        Application application = facesContext.getApplication();
        ELContext elContext = facesContext.getELContext();
        ConversationController conversationController = (ConversationController) application.getELResolver().getValue(elContext, null, "conversationController");
        SessionController sessionController = (SessionController) application.getELResolver().getValue(elContext, null, "sessionController");
        ApplicationController applicationController = (ApplicationController) application.getELResolver().getValue(elContext, null, "applicationController");
        EntityRegistry entityRegistry = conversationController.getEntityRegistry();     

        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse= (HttpServletResponse) response;

        User currentUser = sessionController.getCurrentUser();

        Boolean isTesting = (Boolean) servletContext.getAttribute("ginger.TESTING");
        if (isTesting == null) isTesting = false;

        if (currentUser == null)
        {
            if (httpRequest.isSecure() || isTesting)
            {               
                Cookie[] cookies = httpRequest.getCookies();
                Cookie cookie = null;

                if (cookies != null)
                {
                    for (int i=0; i<cookies.length; i++)
                    {
                        if (cookies[i].getName().equals("ginger.USERCOOKIE"))
                        {
                            cookie = cookies[i];
                            break;
                        }
                    }
                }

                if (cookie != null)
                {
                    currentUser = entityRegistry.getUserByCookie(cookie.getValue()); 
                }

                if (currentUser == null)
                {
                    currentUser = new UnregisteredUser();

                    String cookieValue = String.valueOf(applicationController.getRandom());

                    currentUser.setCookie(cookieValue);

                    entityRegistry.storeUser(currentUser);

                    cookie = new Cookie("ginger.USERCOOKIE", cookieValue);
                    cookie.setPath(applicationController.getPath());
                    cookie.setMaxAge(365*24*60*60);
                    if (!isTesting) cookie.setSecure(true);

                    httpResponse.addCookie(cookie);
                }

                sessionController.setCurrentUser(currentUser);

                @SuppressWarnings("unchecked")
                String url = URLConstructor.constructUrl(servletContext, httpRequest, httpResponse, false, httpRequest.getRequestURI(), httpRequest.getParameterMap());

                httpResponse.sendRedirect(url);
            }
            else
            {
                @SuppressWarnings("unchecked")
                String url = URLConstructor.constructUrl(servletContext, httpRequest, httpResponse, true, httpRequest.getRequestURI(), httpRequest.getParameterMap());

                httpResponse.sendRedirect(url);
            }
        }
        else
        {
            chain.doFilter(request, response);
        }

        builder.removeFacesContext();
    }

I use Orchestra and RichFaces in my application. When accessing a page in my application I get the following error many times and the page doesn't load:

WARN _ReentrantLock:103 - Waited for longer than 30000 milliseconds for access to lock org.apache.myfaces.orchestra.lib._ReentrantLock@78214f6b which is locked by thread http-8080-2

I believe at the heart the problem is a filter that I use for authentication. Here is its code (conversationController is a conversation scoped bean):

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,  FilterChain chain)
    throws IOException, ServletException
    {           
        FacesContextBuilder builder = new FacesContextBuilder();

        FacesContext facesContext = builder.getFacesContext(request, response);
        ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
        Application application = facesContext.getApplication();
        ELContext elContext = facesContext.getELContext();
        ConversationController conversationController = (ConversationController) application.getELResolver().getValue(elContext, null, "conversationController");
        SessionController sessionController = (SessionController) application.getELResolver().getValue(elContext, null, "sessionController");
        ApplicationController applicationController = (ApplicationController) application.getELResolver().getValue(elContext, null, "applicationController");
        EntityRegistry entityRegistry = conversationController.getEntityRegistry();     

        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse= (HttpServletResponse) response;

        User currentUser = sessionController.getCurrentUser();

        Boolean isTesting = (Boolean) servletContext.getAttribute("ginger.TESTING");
        if (isTesting == null) isTesting = false;

        if (currentUser == null)
        {
            if (httpRequest.isSecure() || isTesting)
            {               
                Cookie[] cookies = httpRequest.getCookies();
                Cookie cookie = null;

                if (cookies != null)
                {
                    for (int i=0; i<cookies.length; i++)
                    {
                        if (cookies[i].getName().equals("ginger.USERCOOKIE"))
                        {
                            cookie = cookies[i];
                            break;
                        }
                    }
                }

                if (cookie != null)
                {
                    currentUser = entityRegistry.getUserByCookie(cookie.getValue()); 
                }

                if (currentUser == null)
                {
                    currentUser = new UnregisteredUser();

                    String cookieValue = String.valueOf(applicationController.getRandom());

                    currentUser.setCookie(cookieValue);

                    entityRegistry.storeUser(currentUser);

                    cookie = new Cookie("ginger.USERCOOKIE", cookieValue);
                    cookie.setPath(applicationController.getPath());
                    cookie.setMaxAge(365*24*60*60);
                    if (!isTesting) cookie.setSecure(true);

                    httpResponse.addCookie(cookie);
                }

                sessionController.setCurrentUser(currentUser);

                @SuppressWarnings("unchecked")
                String url = URLConstructor.constructUrl(servletContext, httpRequest, httpResponse, false, httpRequest.getRequestURI(), httpRequest.getParameterMap());

                httpResponse.sendRedirect(url);
            }
            else
            {
                @SuppressWarnings("unchecked")
                String url = URLConstructor.constructUrl(servletContext, httpRequest, httpResponse, true, httpRequest.getRequestURI(), httpRequest.getParameterMap());

                httpResponse.sendRedirect(url);
            }
        }
        else
        {
            chain.doFilter(request, response);
        }

        builder.removeFacesContext();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼中杀气 2024-09-23 17:02:09

我通过在提交响应之前释放 FacesContext 解决了这个问题。像这样:

@SuppressWarnings("unchecked")
String url = URLConstructor.constructUrl(servletContext, httpRequest, httpResponse, true, httpRequest.getRequestURI(), httpRequest.getParameterMap());
builder.removeFacesContext();
httpResponse.sendRedirect(url);

我不完全理解这一点,但似乎新请求仍在使用旧的 FacesContext,这会干扰 _ReentrantLock 解锁。

I solved this by releasing the FacesContext before the response is committed. Like this:

@SuppressWarnings("unchecked")
String url = URLConstructor.constructUrl(servletContext, httpRequest, httpResponse, true, httpRequest.getRequestURI(), httpRequest.getParameterMap());
builder.removeFacesContext();
httpResponse.sendRedirect(url);

I don't understand this completely but it seems that the new request was still using the old FacesContext and this interfered with the _ReentrantLock getting unlocked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文