在托管模式下运行我的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
托管模式生成序列化策略文件(* .gwt.rpc),其中包含与GWT编译期间创建的md5不同的md5 - 这些文件部署在我的服务器上。 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" />
...
如何让托管生成相同的序列化策略文件?
答案 0 :(得分:3)
我一直有同样的问题。我看到的唯一解决方案是确保双方都有相同的 .gwt.rpc 文件。
这意味着,每次启动或重新加载开发模式时,都必须使用新生成的文件替换Web服务器上部署的旧 .gwt.rpc 文件。
或者您将Dev Mode war输出目录指向Web服务器上下文。并确保Web服务器已启用自动部署。因此,每次通过开发模式更改文件时,Web服务器都会自动重新加载文件。
答案 1 :(得分:0)
根据我在com.google.gwt.user.rebind.rpc.ProxyCreator
中看到的内容,GWT按其内容(md5)生成序列化策略 .gwt.rpc 文件的名称。
因此,出于某种原因,超级开发模式中的序列化策略与正常构建期间生成的序列化策略不同。
以下方法为我解决了这个问题: