gwt 序列化策略托管模式不同步 [英] gwt serialization policy hosted mode out of sync

查看:19
本文介绍了gwt 序列化策略托管模式不同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在托管模式下运行我的 GWT 应用程序 (gwt 2.0.4) 时,调用在远程 Tomcat 上运行的 RPC 方法时,我收到 GWT 序列化异常:

When running my GWT application (gwt 2.0.4) in hosted mode, calling RPC methods running on remote Tomcat, I get GWT serialization exception:

INFO: GwtRpcEventSrvc: ERROR: The serialization policy file '/84EC7BA65AF8175BAA99B47877FDE163.gwt.rpc' was not found; did you forget to include it in this deployment?

SEVERE: GwtRpcEventSrvc: WARNING: Failed to get the SerializationPolicy '84EC7BA65AF8175BAA99B47877FDE163' for module 'http://host:19980/MYAPP/'; a legacy, 1.3.3 compatible, serialization policy will be used.  Youmay experience SerializationExceptions as a result.

SEVERE: Exception while dispatching incoming RPC call
Throwable occurred: com.google.gwt.user.client.rpc.SerializationException: java.lang.reflect.InvocationTargetException
.at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeWithCustomSerializer(ServerSerializationStreamWriter.java:760)
.at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:723)
.at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:612)
.at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
.at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:152)
...
Caused by: com.google.gwt.user.client.rpc.SerializationException: Type 'com.mypackage.data.MyData' 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.: instance = com.mypackage.data.MyData@1b061b06
.at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:610)
.at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
.at com.google.gwt.user.client.rpc.core.java.util.Collection_CustomFieldSerializerBase.serialize(Collection_CustomFieldSerializerBase.java:43)
.at com.google.gwt.user.client.rpc.core.java.util.LinkedList_CustomFieldSerializer.serialize(LinkedList_CustomFieldSerializer.java:36)
.... 33 more

托管模式生成序列化策略文件 (*.gwt.rpc),其 md5 与 GWT 编译期间创建的 md5 不同 - 这些文件部署在我的服务器上.GWT 缺少托管模式客户端所需的序列化策略文件.

Hosted mode generates serializations policy files (*.gwt.rpc) with different md5 that those that were created during GWT compilation - these are deployed on my server. GWT is missing serialization policy file that hosted mode client wants.

在非托管模式下运行时一切正常.

When running in non-hosted mode everything is fine.

我尝试通过 Ant 或 Eclipse 调试配置启动托管模式,结果相同.GWT 编译类路径和托管模式类路径(包括)相同.

I tried to launch hosted mode via Ant or Eclipse debug configuration with the same results. GWT compilation classpath and hosted mode classpath (including) are the same.

GWT 编译 Ant 脚本:

GWT Compilation Ant script:

<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
  <classpath>
    <pathelement location="${basedir}/src" />
    <pathelement location="${dir.build.root}/ProjectA/src" />
    <pathelement location="${dir.build.root}/ProjectB/src" />
    <pathelement location="${dir.build.root}/ProjectC/src" />
    <pathelement location="${dir.build.root}/ProjectD/src" />
    <pathelement location="${dir.build.root}/ProjectE/src" />
    <pathelement location="${dir.root}/ProjectD/src" />
    <pathelement location="${dir.root}/THIRDPARTY/build/athirdparty.jar" />
    <pathelement location="${dir.commons.gwtcompiler}/gwt-user.jar" />
    <pathelement location="${dir.commons.gwtcompiler}/gwt-dev.jar" />
    <pathelement location="../ExternalLibs/libs/gwt-log-3.0.0.jar" />
<!-- JAXB API sources needed for GWT compilation of JAXB annotated classes -->
    <pathelement location="../ExternalLibs/nonshipjars/jaxb-api-src.zip" />
  </classpath>
  <jvmarg value="-Xmx1g" />
  <jvmarg value="-Dgwt.nowarn.metadata" />
  <arg line="-localWorkers 2 -style OBF" />
  <arg line="-war ${basedir}/www" />
  <arg line="-extra ${basedir}/build" />
  <arg value="com.myapp.Main" />
</java>

托管模式启动 - Ant 脚本:

Hosted mode launch - Ant script:

<target name="hosted" description="Run hosted mode">
  <java failonerror="true" fork="true" classname="com.google.gwt.dev.HostedMode">
    <classpath>
        <pathelement location="${basedir}/src" />
        <pathelement location="${dir.build.root}/ProjectA/src" />
        <pathelement location="${dir.build.root}/ProjectB/src" />
        <pathelement location="${dir.build.root}/ProjectC/src" />
        <pathelement location="${dir.build.root}/ProjectD/src" />
        <pathelement location="${dir.build.root}/ProjectE/src" />
        <pathelement location="${dir.root}/ProjectD/src" />
        <pathelement location="${dir.root}/THIRDPARTY/build/athirdparty.jar" />
        <pathelement location="${dir.commons.gwtcompiler}/gwt-user.jar" />
        <pathelement location="${dir.commons.gwtcompiler}/gwt-dev.jar" />
        <pathelement location="../ExternalLibs/libs/gwt-log-3.0.0.jar" />
    <!-- JAXB API sources needed for GWT compilation of JAXB annotated classes -->
        <pathelement location="../ExternalLibs/nonshipjars/jaxb-api-src.zip" />
    </classpath>
    <jvmarg value="-Xmx1g" />
    <jvmarg value="-Dgwt.nowarn.metadata" />
    <arg line="com.myapp.Main" />
    <arg line="-startupUrl" />
    <arg line=" http://host:19980/MYAPP/Main.html" />
    <arg line="-whitelist" />
    <arg line="^http[:][/][/]host[:]19980" />
    <arg line="-whitelist" />
    <arg line=" ^http[:][/][/]localhost" />
    <arg line="-whitelist" />
    <arg line="^http[:][/][/]127.0.0.1" />
    <arg line="-port" />
    <arg line="8080" />
    <arg line="-noserver" />
    <arg line="-logLevel" />
    <arg line="DEBUG" />
  </java>
</target>

RPC 方法签名:

public List<MyData> getSmpeWorkDddefZonesData(String processId);

MyData 定义(在 ProjectE 中声明为非 GWT 项目 - 数据层):

MyData definition (declared in ProjectE that is non-GWT project - data tier):

package com.mypackage.data;

import java.io.Serializable;

public interface MyData extends Serializable {...

MyData 链接到从另一个 GWT 模块继承的模块中:com.mypackage.Data.gwt.xml:

MyData is linked in module inherited from another GWT module: com.mypackage.Data.gwt.xml:

<module>
  <source path="data" />
</module>

主模块com.myapp.Main.gwt.xml:

...
  <inherits name="com.mypackage.Data" />
...

如何使托管生成相同的序列化策略文件?

How to make hosted generate the same serialization policy files?

推荐答案

我遇到了同样的问题.我看到的唯一解决方案是确保两侧具有相同的 .gwt.rpc 文件.

I've been having the same problem. The only solution I see, is to make sure you have the same .gwt.rpc files on both sides.

这意味着,每次启动或重新加载开发模式时,您都必须用新生成的文件替换部署在 Web 服务器上的旧 .gwt.rpc 文件.

That means, everytime you start or reload Dev Mode, you have to replace the old .gwt.rpc files deployed on your web server with the newly generated ones.

或者您将 Dev Mode war 输出目录指向 Web 服务器上下文.并确保 Web 服务器已打开自动部署.因此,每次 Dev Mode 更改文件时,Web 服务器都会自动重新加载文件.

Or you point the Dev Mode war output directory to the web server context. And make sure the web server has auto-deploy turned on. So every time the files are changed by Dev Mode, the web server automatically reloads the files.

这篇关于gwt 序列化策略托管模式不同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆