Mojarra会话中的服务器状态序列化 [英] Server-state serialization in a session in Mojarra

查看:96
本文介绍了Mojarra会话中的服务器状态序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览一本书中的摘要时,我遇到了这个问题:

Going through an abstract in a book, I came across this:

在服务器端,状态可以存储为浅表副本或存储为 深层复制.在浅表副本中,状态未在 会议.默认情况下,JSF Mojarra使用浅表副本.

On the server side, the state can be stored as a shallow copy or as a deep copy. In a shallow copy, the state is not serialized in the session. By default, JSF Mojarra uses shallow copy.

我真不明白.

由于上述情况,我们将拥有-

Since in the above case, we will have-

javax.faces.STATE_SAVING_METHOD设置为server

和一个输入隐藏字段javax.faces.ViewState,其值类似于此"2870966362946771868:-8449289062699033744".

and an input hidden field javax.faces.ViewState with a value somewhat like this "2870966362946771868:-8449289062699033744".

显然,服务器必须在内部保持与上述隐藏字段相对应的状态.

Obviously, the server must have maintained internally an state corresponding to the above hidden field.

但是从抽象的角度来看,如果状态未在会话中序列化,那么状态在哪里?

But going by the abstract, if the state is not serialized in the session, then where it is?

此外,我注意到一件事,如果我的Managed bean(ViewScoped)没有实现将STATE_SAVING_METHOD设置为server的标记接口Serializable,那么在Mojarra中,NotSerializablEexception不会'不会发生,而在MyFaces中会发生.

Furthermore, I have noticed one thing that if my Managed bean(ViewScoped) is not implementing marker interface Serializable with STATE_SAVING_METHOD set to server, then in Mojarra, the NotSerializablEexception doesn't occur, while in MyFaces it does.

推荐答案

但是从抽象的角度来看,如果状态未在会话中序列化,那么状态在哪里?

存在对HTTP会话中已有实例的引用,这些实例又不一定要序列化.

It exist of references to instances already in the HTTP session which in turn is not necessarily serialized.

为此的关键上下文参数是javax.faces.SERIALIZE_SERVER_STATE,在MyFaces中默认为true,在Mojarra中默认为false.设置为true时,您会很快在错误地不是Serializable的工件上看到NotSerializableException.否则,您将依赖服务器配置.例如,默认情况下,Tomcat在服务器重新启动期间默认序列化整个HTTP会话,包括其所有属性.某些服务器,尤其是在集群中运行的服务器,甚至可以配置为在运行时序列化整个HTTP会话.在这种情况下,您还会在重新启动或故障转移期间看到NotSerializableException.

The key context param for this is javax.faces.SERIALIZE_SERVER_STATE which defaults in MyFaces to true and in Mojarra to false. When set to true, you will sooner see NotSerializableException on artifacts which are mistakenly not Serializable. Otherwise, you're dependent on server configuration. For example, Tomcat by defaults serializes the entire HTTP session including all its attribtues during a server restart. Some servers, particularly those running in cluster, can even be configured to serialize entire HTTP sessions during runtime. In such cases you would also see NotSerializableException during restart or failover.

Mojarra计划将2.3的javax.faces.SERIALIZE_SERVER_STATE设置默认设置为true,特别是因为此设置将主动防止无法预见的开发人员错误,例如分配不可序列化的JSF工件(例如UIComponent甚至是作为非请求范围的bean的属性.否则会导致出现问题,例如将线程卡在UIComponent.popComponentFromEL 上, java.lang.IllegalStateException at com .sun.faces.context.FacesContextImpl.assertNotReleased .

Mojarra has plans to make javax.faces.SERIALIZE_SERVER_STATE setting default to true as per 2.3, particularly because this setting would proactively prevent unforeseen developer mistakes such as assigning non-serializable instances of JSF artifacts such as UIComponent or even FacesContext as properties of a non-requestscoped bean. It would otherwise result in problems as Stuck thread at UIComponent.popComponentFromEL, Java Threads at 100% CPU utilization using richfaces UIDataAdaptorBase and its internal HashMap and java.lang.IllegalStateException at com.sun.faces.context.FacesContextImpl.assertNotReleased.

另一方面,在较旧的MyFaces版本中,此设置破坏了注入可序列化托管Bean中的EJB,这是因为在反序列化过程中使用了错误的类加载器来解析EJB代理.根据 MyFaces问题3581 .另请参见 @ViewScoped @ManagedBean中的@EJB导致java.io.NotSerializableException .

On the other hand, in older MyFaces versions, this setting broke EJBs injected in serializable managed beans due to the wrong classloader being used to resolve EJB proxies during deserialization. This was fixed in MyFaces 2.0.15 and 2.1.9 as per MyFaces issue 3581. See also @EJB in @ViewScoped @ManagedBean causes java.io.NotSerializableException.

这篇关于Mojarra会话中的服务器状态序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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