gwt序列化策略托管模式不同步
当以托管模式运行我的GWT应用程序(gwt 2.0.4),调用在远程Tomcat上运行的RPC方法时,我得到了GWT序列化异常:
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
托管模式会生成具有不同md5的序列化策略文件(* .gwt.rpc),这些文件是在GWT编译过程中创建的 - 这些部署在我的服务器上。 GWT缺少托管模式客户端需要的序列化策略文件。
当在非托管模式下运行时,一切都很好。
我尝试通过Ant或Eclipse调试配置启动托管模式,并获得相同的结果。 GWT编译类路径和托管模式类路径(包括)是相同的。
GWT编译Ant脚本:
<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脚本:
<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项目 - 数据层):
package com.mypackage.data;
import java.io.Serializable;
public interface MyData extends Serializable {...
MyData链接到从另一个GWT模块继承的模块中: com.mypackage.Data.gwt.xml
:
<module>
<source path="data" />
</module>
主要模块com.myapp.Main.gwt.xml
:
...
<inherits name="com.mypackage.Data" />
...
如何使托管生成相同的序列化策略文件?
我一直有同样的问题。 我看到的唯一解决方案是确保两侧都具有相同的.gwt.rpc文件。
这意味着,每次启动或重新加载开发模式时,都必须用新生成的部件替换部署在Web服务器上的旧.gwt.rpc文件。
或者您将Dev Mode war输出目录指向Web服务器上下文。 并确保Web服务器已启用自动部署。 所以每次Dev模式更改文件时,Web服务器都会自动重新加载文件。
根据我在com.google.gwt.user.rebind.rpc.ProxyCreator
看到的内容,GWT通过其内容(md5)生成序列化策略.gwt.rpc文件的名称。
因此,出于某种原因,Super Dev Mode中的序列化策略与正常构建期间生成的策略不同。
以下方法解决了我的问题: