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

标签 gwt gwt-rpc reverse-proxy

我正在 Glassfish 3.0.1 上部署 GWT 2.4 应用程序。我可以通过http://host:PORT/appContext/轻松访问我的应用程序
但是,当我使用 Apache 反向代理应用程序时,出现异常,摘录如下(摘自 Glassfish 日志):

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.

按照Chi的建议,实现IsSerialized解决了这个问题。在 related question 。 相关问题中还有其他解决方法。

我的问题是这个问题的根本原因是什么,两个看似无关的解决方案(实现标记接口(interface)和扩展 servlet 类)如何解决这个问题? related question 中提到的两种方法都有缺点吗? ?

注意:如果直接访问应用程序,则不会发生异常。

注2:与异常相关的类已经实现了Serialized接口(interface),就GWT而言,该接口(interface)应该等同于IsSerialized。

最佳答案

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

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

编辑

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

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

你会注意到它说:

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

因此,您需要覆盖 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>

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

关于gwt - 反向代理对 GWT 应用程序有何影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7610969/

相关文章:

gwt - Scala 可以用于编写 GWT 应用程序吗?

python - 调试睡衣python代码

java - GWT RPC : DTO vs. DAO?

ssl - 在 nginx 上游使用 ssl 的 proxy_pass

iis - 使用 ARR(应用程序请求路由)的反向代理 - POST 方法不起作用

css - DataGrid/CellTable 样式挫折——覆盖行样式

java - GWT MAP 中的 Activity 指示器

gwt - 如何重新发送 GWT RequestFactory 请求

amazon-web-services - CloudFront 如何从 S3 在现有分发服务网站上设置反向代理

java - 将 GWT 添加到现有的 Maven Web 应用程序