反向代理对 GWT 应用程序有何影响?
我正在 Glassfish 3.0.1 上部署 GWT 2.4 应用程序。我可以通过 http://host:PORT/appContext/ 轻松访问我的应用程序
但是,当我使用 Apache 反向代理应用程序,但出现异常,摘录如下(摘自 Glassfish 日志):
分派传入 RPC 调用时出现异常 com.google.gwt.user.client.rpc.SerializationException: 类型“com.ozdokmeci.basicgwtproject.shared.GroupData”无法分配给“com.google.gwt.user.client.rpc.IsSerialized”,并且没有自定义字段序列化器。 出于安全目的,该类型不会被序列化。
我的问题是,造成这种情况的根本原因是什么?两个看似无关的解决方案(实现标记接口和扩展 servlet 类)如何解决这个问题? 相关问题?
注意:如果直接访问应用程序,则不会发生该异常。
注意2:与异常相关的类已经实现了 Serialized 接口,就 GWT 而言,该接口应该等效于 IsSerialized .
I am deploying a GWT 2.4 app on Glassfish 3.0.1. I can easily access my application via http://host:PORT/appContext/
However, when I reverse proxy the application with Apache I get an exception with the following excerpt (from Glassfish logs):
Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException:
Type 'com.ozdokmeci.basicgwtproject.shared.GroupData' was not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' and did not have a custom field serializer.
For security purposes, this type will not be serialized.
Implementing IsSerializable
solves the problem as advised by Chi in a related question.
There are also other workarounds in the related question.
My question is what is the underlying cause of this and how come two seemingly unrelated solutions (implementing a marker interface and extending a servlet class) solve this problem? Also are there any disadvantages to both of the methods mentioned in the related question?
Note: The exception does not occur if the app is reached directly.
Note2: Class related to the exception already implements the interface Serializable, which should be equivalent to the IsSerializable as far as GWT is concerned.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了完全相同的问题,当我跟踪源代码时,我发现反向代理时找不到 GWT 序列化文件的目录(我认为因为该目录是相对路径)。这就是为什么即使您已经实现了 IsSerialized,您也会收到序列化异常。
我最终的解决方案是为我的 RPC 迁移到 Restful JSON。使用 JSON 将允许您进行反向代理,因为它不需要查找这些序列化文件。
编辑
如果您仍然想使用 GWT RPC,我知道它是如何实现的(尽管我自己还没有实现它)。
首先,查看有关这些 rpc 文件的 GWT 帮助:
https://developers.google.com/web-toolkit/doc/2.4 /DevGuideCompilingAndDebugging#key_application_files
你会注意到它说:
因此,您需要覆盖 RemoteServiceServlet 并重新指向 RPC(序列化策略)文件的位置。
以下是取自此网站的一项建议:http:// /code.google.com/p/google-web-toolkit/issues/detail?id=4817
在 apache 配置中添加:
希望我上面的建议至少为某人指明了正确的方向。
如果有人实现了这个并且它有效,请告诉我们。
I had the exact same issue and when I traced through the source code I found that the directory of GWT serialization files was not being found when reverse-proxying (I think because the directory was a relative path). This is why you are getting serialization exceptions even though you have implemented IsSerializable.
My solution in the end was to move to restful JSON for my RPC. Using JSON will allow you to reverse proxy because it doesnt need to find these Serialization files.
Edit
If you want to still use GWT RPC though, I have an idea of how it's possible (though I havent implemented it myself).
First, take a look at the GWT Help about these rpc files:
https://developers.google.com/web-toolkit/doc/2.4/DevGuideCompilingAndDebugging#key_application_files
You will notice it says:
So you will need to override RemoteServiceServlet and re-point the location of the rpc (serialization policy) files.
Here is one suggestion, taken from this site: http://code.google.com/p/google-web-toolkit/issues/detail?id=4817
In apache config add:
Hopefully my suggestion above at least points someone in the right direction.
Please let us know if someone implements this and it works.