gpt4 book ai didi

java - JSF session 故障转移和部分状态保存

转载 作者:搜寻专家 更新时间:2023-10-30 21:07:01 25 4
gpt4 key购买 nike

在 JSF 2.0.9、Weblogic 10.3.4 上运行。我们现在在生产环境中运行 JSF,但在 session 复制和故障转移方面遇到了一些问题。我们正在为我们的 bean 使用 viewscope,我确保它们是可序列化的/ transient 的,并且 transient 变量实际上是无状态的。但是 session 故障转移不起作用。我已经进行了广泛的测试,并通过在 web.xml 中设置以下参数设法让它工作

    <context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>


<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>

如果我将 STATE_SAVING_METHOD 设置为 server,我会在故障转移时收到 viewexpired 异常。如果我将 clientPARTIAL_STATE_SAVING 设置为 true,我会收到以下错误:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at javax.faces.component.AttachedObjectListHolder.restoreState(AttachedObjectListHolder.java:165)
at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1433)
at com.sun.faces.application.view.StateManagementStrategyImpl$1.visit(StateManagementStrategyImpl.java:265)
at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1507)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1521)
at com.sun.faces.component.visit.VisitUtils.doFullNonIteratingVisit(VisitUtils.java:75)
at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:282)
at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:181)
at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:448)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:148)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:187)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:111)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:508)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)

所以我的问题是:

  • STATE_SAVING_METHOD - client & PARTIAL_STATE_SAVING - false 是我将故障转移到的唯一方法工作?
  • 客户/虚假组合的成本是多少。这个内存/CPU 很大吗?
  • 这是一个错误吗?如果是,它会在 2.1 或 2.2 中得到解决吗?

提前致谢。

最佳答案

我终于完成了这项工作,但并非没有一些额外的细节。首先,我将以下内容添加到 web.xml(是的,aggressive 拼写错误):

    <context-param>
<param-name>com.sun.faces.enableAgressiveSessionDirtying</param-name>
<param-value>true</param-value>
</context-param>

客户端保存现在是服务器,部分状态保存仍然是 false(true 根本不起作用)

其次,在实现 HttpSessionAttributeListener 之后,我发现保存 session 状态的 com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap 只添加了一次,再也没有删除/添加/替换。因此,尽管它在本地 session 中被更新,但这些更改从未复制到第二个 jvm。 Weblogic 文档声明必须对 session 属性调用 setAttribute 才能进行复制。为了解决这个问题,我创建了一个阶段监听器,如下所示:

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

这只是在每次请求后替换属性并确保它被复制。另外一点,我使用以下内容限制 View 中存储的数据:

<context-param>
<param-name>com.sun.faces.numberOfViewsInSession</param-name>
<param-value>3</param-value>
</context-param>

<context-param>
<param-name>com.sun.faces.numberOfLogicalViews</param-name>
<param-value>1</param-value>
</context-param>

希望这对遇到同样问题的人有所帮助。

关于java - JSF session 故障转移和部分状态保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12094077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com