GWT 将 RPC 转换为 JSON
我的应用程序使用 GWT-RPC 与服务器通信。有没有办法使用 JSON 透明地序列化我的数据而不更改 RPC 层?
恕我直言,这可以通过更改序列化器并在 UI 中使用 autobean codex 来实现。
为什么我需要那个?
- 我想要进行跨域 RPC 调用
- 我想从非 GWT 应用程序调用服务器端,而不在服务器端提供额外的层。
My application uses GWT-RPC to communicate to the server. Is there anyway to transparentlly serialzie my data using JSON without changing the RPC layer?
IMHO this could be acheived by changing the serializers and using autobean codex in the UI.
Why do I need that?
- I want to make cross domain RPC calls
- I want to call the server side from a non GWT-app without providing an extra layer in server side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新我刚刚偶然发现http:// 积极维护(因为它是 Android 团队使用的代码审查工具 Gerrit 的一部分)
/code.google.com/p/gerrit/source/browse/README?repo=gwtjsonrpc正在 看看 http://code.google.com/p/gwt-rpc-plus/ 但它不再维护...
如果您确实需要它并且不想放弃 GWT-RPC,那么替换 GWT 的序列化器应该是可能的:这正是 deRPC (
com.google. gwt.rpc
)确实。 标准 GWT-RPC (com.google.gwt.user.rpc
),但它需要做的还不止这些(即:为客户端生成序列化代码-side,因为运行时没有反射)。UPDATE I just stumbled upon http://code.google.com/p/gerrit/source/browse/README?repo=gwtjsonrpc which is actively maintained (as it's part of Gerrit, the code-review tool used by the Android team)
Have a look at http://code.google.com/p/gwt-rpc-plus/ but it's no longer maintained...
If you really need it and don't want to move away from GWT-RPC, then replacing GWT's serializers should be possible: that's exactly what deRPC (
com.google.gwt.rpc
) does re. standard GWT-RPC (com.google.gwt.user.rpc
), but it needs to do a bit more than that (namely: generate the serialization code for the client-side, as there's no reflection at runtime).这将是一项艰巨的任务。我不认为序列化器的更改会起作用,GWT-RPC 序列化器正在像流一样处理输入(基本上从服务器发送的数据实际上是 JSON 格式,但它们只能由 GWT-RPC 解析)。您将必须创建全新的生成器,它将创建用于解析和对象序列化/反序列化的代码。 AutoBean 框架在这种情况下可能会非常有帮助。最后,您应该能够从 GWT-RPC 序列化迁移到其他协议,而无需实际更改使用 GWT-RPC 服务的当前代码。
最大的问题是跨域消息传递。通常你会使用 JSONP,但问题是 JSONP 基本上只允许 GET 请求,如果你需要向其他服务器发送大量数据,你可能无法将所有数据放入单个请求中。您可以通过跨域文档消息传递来解决此类问题(例如,您将打开 iframe,它将从远程服务器加载特殊的通信 javascript,并且您将通过
postMessage
使用此 iframe 作为您的服务的代理),但是IE7 不支持此功能。This going to be a hard task. I don't think the changing of serializers will work, GWT-RPC serializers are working with input as with a stream (basically data sent from server are in fact in JSON format, but they can be parsed only by GWT-RPC). You will have to create totally new generator, which will create code for parsing and object serialization/deserialization. AutoBean framework might be very helpful in this case. In the end you should be able to to migrate from GWT-RPC serialization to some other protocol without actually changing current code, which is using GWT-RPC services.
The biggest problem is cross-domain messaging. Normally you would use JSONP, but the problem is that JSONP basically allows only GET requests, if you need send a lot of data to the other server, you might not be able to fit everything into single requests. You can solve such problem with cross domain document messaging (e.g. you will open iframe, which will load special communication javascript from remote server, and you will use this iframe as proxy for your service via
postMessage
) , but this feature is not supported in IE7.