4

我的应用程序使用 GWT-RPC 与服务器通信。无论如何在不更改 RPC 层的情况下使用 JSON 透明地序列化我的数据吗?

恕我直言,这可以通过更改序列化程序并在 UI 中使用 autobean codex 来实现。

为什么我需要那个?

  • 我想进行跨域 RPC 调用
  • 我想从非 GWT 应用程序调用服务器端,而不在服务器端提供额外的层。
4

2 回答 2

3

更新我刚刚偶然发现了http://code.google.com/p/gerrit/source/browse/README?repo=gwtjsonrpc它是积极维护的(因为它是 Gerrit 的一部分,Android 团队使用的代码审查工具)

看看http://code.google.com/p/gwt-rpc-plus/但它不再维护......

如果你真的需要它并且不想离开 GWT-RPC,那么替换 GWT 的序列化器应该是可能的:这正是 deRPC( com.google.gwt.rpc) 所做的。标准的 GWT-RPC ( com.google.gwt.user.rpc),但它需要做的远不止这些(即:为客户端生成序列化代码,因为在运行时没有反射)。

于 2012-02-01T17:13:11.197 回答
1

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.

于 2012-02-01T16:30:14.837 回答