反向代理对 GWT 应用程序有何影响?

发布于 2024-12-07 10:12:11 字数 1039 浏览 2 评论 0原文

我正在 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”,并且没有自定义字段序列化器。 出于安全目的,该类型不会被序列化。

按照 Chi相关问题。 相关问题中还有其他解决方法。

我的问题是,造成这种情况的根本原因是什么?两个看似无关的解决方案(实现标记接口和扩展 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巾帼英雄 2024-12-14 10:12:11

我遇到了完全相同的问题,当我跟踪源代码时,我发现反向代理时找不到 GWT 序列化文件的目录(我认为因为该目录是相对路径)。这就是为什么即使您已经实现了 IsSerialized,您也会收到序列化异常。

我最终的解决方案是为我的 RPC 迁移到 Restful JSON。使用 JSON 将允许您进行反向代理,因为它不需要查找这些序列化文件。

编辑

如果您仍然想使用 GWT RPC,我知道它是如何实现的(尽管我自己还没有实现它)。

首先,查看有关这些 rpc 文件的 GWT 帮助:
https://developers.google.com/web-toolkit/doc/2.4 /DevGuideCompilingAndDebugging#key_application_files

你会注意到它说:

序列化策略文件必须可由 RPC RemoteServiceServlet 通过 ServletContext.getResource() 调用访问

因此,您需要覆盖 RemoteServiceServlet 并重新指向 RPC(序列化策略)文件的位置。

以下是取自此网站的一项建议:http:// /code.google.com/p/google-web-toolkit/issues/detail?id=4817

    public class MyRemoteServiceServlet extends RemoteServiceServlet
    {

    ...

    @Override
    protected SerializationPolicy doGetSerializationPolicy(
            HttpServletRequest request, String moduleBaseURL, String strongName) {
            //get the base url from the header instead of the body this way 
            //apache reverse proxy with rewrite on the header can work
            String moduleBaseURLHdr = request.getHeader("X-GWT-Module-Base");

            if(moduleBaseURLHdr != null){
                    moduleBaseURL = moduleBaseURLHdr;
            }

            return super.doGetSerializationPolicy(request, moduleBaseURL, strongName);
    }

    ...

在 apache 配置中添加:

    ProxyPass /app/ ajp://localhost:8009/App-0.0.1-SNAPSHOT/

    <Location /app/>

    RequestHeader edit X-GWT-Module-Base ^(.*)/app/(.*)$ $1/App-0.0.1-SNAPSHOT/$2

    </Location>

希望我上面的建议至少为某人指明了正确的方向。
如果有人实现了这个并且它有效,请告诉我们。

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:

The serialization policy file must be accessible by your RPC RemoteServiceServlet via the ServletContext.getResource() call

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

    public class MyRemoteServiceServlet extends RemoteServiceServlet
    {

    ...

    @Override
    protected SerializationPolicy doGetSerializationPolicy(
            HttpServletRequest request, String moduleBaseURL, String strongName) {
            //get the base url from the header instead of the body this way 
            //apache reverse proxy with rewrite on the header can work
            String moduleBaseURLHdr = request.getHeader("X-GWT-Module-Base");

            if(moduleBaseURLHdr != null){
                    moduleBaseURL = moduleBaseURLHdr;
            }

            return super.doGetSerializationPolicy(request, moduleBaseURL, strongName);
    }

    ...

In apache config add:

    ProxyPass /app/ ajp://localhost:8009/App-0.0.1-SNAPSHOT/

    <Location /app/>

    RequestHeader edit X-GWT-Module-Base ^(.*)/app/(.*)$ $1/App-0.0.1-SNAPSHOT/$2

    </Location>

Hopefully my suggestion above at least points someone in the right direction.
Please let us know if someone implements this and it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文