GWT 和 Jersey 集成
我构建了一个使用 ExtJS 的应用程序,该应用程序通过 Ajax 请求连接到 Jersey RESTful 服务。该应用程序一切正常,但现在我想将其移植到 ExtGWT。
由于 ExtGWT 已经有了 RPC servlet 来处理客户端-服务器通信,Jersey 适合这种场景吗?我是否应该不再使用它,而是从 GWT 的 servlet 直接连接到服务方法?
如果我想使用 Jersey,有什么方法可以像 GWT 的 RPC 一样支持序列化/反序列化吗? - 我认为在这种情况下我不应该再使用 GWT 的 RPC。
我更喜欢 Jersey,因为它有基于 REST 的实现,而我猜 GWT 的 RPC 没有。将来我还计划从 Android/iOS 应用程序访问 Jersey 的 RESTful 服务,而 GWT 的 RPC 不太适合这种情况。
谢谢!
I've built an app that is using ExtJS that connects through Ajax requests to a Jersey RESTful service. All is working well in this app but now I want to port it to ExtGWT.
Since ExtGWT already has the RPC servlets to handle the client-server communication, where can Jersey fit in this scenario? Should I not use it anymore and instead connect from GWT's servlets directly to the service methods?
In case I'd like to use Jersey, is there any way to have same support for serialization / deserialization as with GWT's RPC? - I assume I shouldn't use GWT's RPC anymore in this scenario.
I'd prefer Jersey because it has REST-based implementation while GWT's RPC I guess doesn't. In future I also plan to access Jersey's RESTful services from Android/iOS apps and GWT's RPC wouldn't fit very well in this scenario.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是正确的,您不能将 GWT RPC 与 REST 一起使用。 AFAIK,ExtGWT (GXT) 没有内置支持检索 REST 数据;不过我可能是错的,因为我已经一年多没有使用 GXT 了。
至于使用 GWT RPC,能够在服务器和客户端上重用您的模型非常方便。但是,您的模型不能太复杂(它们需要能够序列化为 JSON);否则,您需要为您的模型创建单独的 DTO。您可以在 GWT RPC 文档中了解更多信息:GWT RPC。
如果是我,我会同时使用 REST 和 GWT RPC。我将使用 GWT RPC 与客户端 GWT 代码进行通信,并使用 Jersey/REST 与外部应用程序进行通信。
You are correct that you can't use GWT RPC with REST. AFAIK, ExtGWT (GXT) doesn't have built in support for retrieving REST data; I could be wrong though, as I haven't used GXT in over a year.
As for using GWT RPC, it's very convenient to be able to reuse your models on both the server and the client. However, your models can't be too complex (they'll need to be able to be serialized to JSON); otherwise you'll need to create separate DTOs for your models. You can read more at the GWT RPC documentation: GWT RPC.
If it were me, I'd use both REST and GWT RPC. I'd use GWT RPC for communication with my client GWT code and Jersey/REST for communication with external apps.
我们编写了一个应用程序(成绩簿),它使用客户端 GWT/GXT 并通过服务器端的 JAX-RS (Jersey) 进行通信:
https://source.sakaiproject.org/contrib/gradebook2/trunk/
最初我们使用 GWT-RPC,但后来选择使用 REST/JSON。两种沟通模式都有其优点/缺点。这里有一些关于他们两个的信息:
code.google.com/webtoolkit/doc/latest/tutorial/clientserver.html
We have written an application (gradebook) that uses client side GWT/GXT and communicates via JAX-RS (Jersey) on the server side:
https://source.sakaiproject.org/contrib/gradebook2/trunk/
Initially we used GWT-RPC but than opted to use REST/JSON. Both communication patterns have their PROS/CONS. There is some information about both of them here:
code.google.com/webtoolkit/doc/latest/tutorial/clientserver.html
您可以顺利地将 Jersey(服务器端)与 RestyGWT(客户端)结合起来。请参阅http://blog.javaforge.net/post/30469901979/gwt-rest 了解更多详情。
You can smoothly combine Jersey (serverside) with RestyGWT (clientside). See http://blog.javaforge.net/post/30469901979/gwt-rest for further details.
请查看 RestyGWT 项目。它将使得调用 JAXRS JSON 资源就像使用 GWT-RPC 一样简单。另外,您通常可以在客户端重用来自服务器端的相同请求响应 DTO。
Please look into the RestyGWT project. It will make calling JAXRS JSON resources as easy as using GWT-RPC. Plus you can typically reuse the same request response DTOs from the server side on the client side.