JSF Session Fail over and Partial State Saving

前端 未结 2 393
天涯浪人
天涯浪人 2020-12-23 23:15

Running on JSF 2.0.9, Weblogic 10.3.4. We\'re now running JSF in our production environment but have encountered some issues with Session Replication and fail over. We are

2条回答
  •  盖世英雄少女心
    2020-12-23 23:43

    I finally got this working but not without some extra bits and bobs. Firstly I added the following to the web.xml (yes agressive is spelled incorrectly):

        
            com.sun.faces.enableAgressiveSessionDirtying
            true
        
    

    The client saving is now server and partial-state saving is false still (true simply doesn't work)

    Secondly after implementing a HttpSessionAttributeListener I discovered that the com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap which holds the state in the session only got added once and never removed/added/replaced again. Therefore although it was being updated in the local session these changes were never replicated to a second jvm. Weblogic docs state that setAttribute must be called on session attributes for replication to work. To fix this I created a phase listener as follows:

    public class ViewPhaseListener implements PhaseListener {
    
        public void afterPhase(PhaseEvent phaseEvent)
        {
    
        }
    
        public void beforePhase(PhaseEvent phaseEvent)
        {
            HttpServletRequest request = ((HttpServletRequest) phaseEvent.getFacesContext().getExternalContext().getRequest());
            HttpSession session = request.getSession();
    
            session.setAttribute("com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap", session.getAttribute("com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap"));
    
        }
    
        public PhaseId getPhaseId()
        {
            return PhaseId.RENDER_RESPONSE;
              //To change body of implemented methods use File | Settings | File Templates.
        }
    }
    

    This simply replaces the attribute after each request and ensures it replicates. As an additional point I am limiting the data stored in the views with the following:

    
            com.sun.faces.numberOfViewsInSession
            3
        
    
        
            com.sun.faces.numberOfLogicalViews
            1
        
    

    Hope this helps anyone with the same issues.

提交回复
热议问题