gpt4 book ai didi

GWT Atmosphere + RequestFactory

转载 作者:行者123 更新时间:2023-12-01 10:06:32 28 4
gpt4 key购买 nike

我想产生以下行为:

用户在浏览器中保存一些实体。在服务器端保存实体后,它会生成通知,并且它必须通过带有更新的实体实例的 Atmosphere 通知所有其他客户端。

所以问题是如何通过Atmosphere 接口(interface)推送POJO 实体?最后一个支持可序列化类型通过线路传输,而 RequestFactory 有另一种序列化机制。

所以我需要将 POJO 实体转换为 autobean,因为这是由 RF 完成并发送给客户端的。有人知道怎么做吗?

最佳答案

您可以只使用创建 AutoBeans 并在您的客户端代码中使用它们而不是 POJO。AutoBeans 可以很容易地在 GWT 中序列化为 JSON 或从 JSON 序列化,并且可以传输 JSON。这就是我在基于网络套接字的 GWT 应用程序中所做的。

在服务器上,您可以创建与在客户端上使用的相同的 AutoBean 工厂。我们使用 AutoBeanFactorySource 代替 GWT.create:

MyDataFactory factory = AutoBeanFactorySource.create(MyDataFactory.class)
AutoBean<MyData> myDataAutoBean = factory.myData();
MyData data = myDataAutoBean.as();
data.setValue(1); // call all kinds of setters

// to converto AutoBean to JSON
String json = AutoBeanCodex.encode(myDataAutoBean).getPayload();

在客户端,我们使用 AutoBeanCodex将 json 解码为 AutoBean

关于GWT Atmosphere + RequestFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9872795/

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