GWT - RPC序列化异常 [英] GWT - RPC SerializationException

查看:275
本文介绍了GWT - RPC序列化异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做GWT已经有一段时间了,我需要快速完成一些小事。我设置了一些东西,现在我有了一个我需要的RPC,但它失败了。



RPC应该给我一个ArrayList,空缺位于#projectname# .client.model。
该调用是在#projectname#.client.model中进行的。


我的服务的接口位于#project#name.client.Service中。


最后,当然是调用#projectname#.server。


空缺实现了IsSerializable。从运行RPC得到的异常如下:

 在端口8888上启动Jetty 
[WARN] Exception while调度传入的RPC调用
com.google.gwt.user.client.rpc.SerializationException:类型'firsteight.client.model.Vacancy'未包含在可由此SerializationPolicy或其Class的序列化类型集合中对象无法加载。为了安全起见,这种类型不会被序列化:实例= firsteight.client.model.Vacancy@15fdd2f
在com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java: 619)
位于com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
位于com.google.gwt.user.client.rpc.core。 java.util.Collection_CustomFieldSerializerBase.serialize(Collection_CustomFieldSerializerBase.java:44)
,位于com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serialize(ArrayList_CustomFieldSerializer.java:39)
,位于com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serializeInstance(ArrayList_CustomFieldSerializer.java:51)
,位于com.google.gwt.user.client.rpc.core.java .util.ArrayList_CustomFieldSerializer.serializeInstance(ArrayList_CustomFieldSerializer.java:28)
,com.google.gwt.user .server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:740)
,位于com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:621)
在com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
位于com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter $ ValueWriter $ 8.write (ServerSerializationStreamWriter.java:153)
,位于com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:539)
位于com.google.gwt.user.server .rpc.RPC.encodeResponse(RPC.java:616)
,位于com.google.gwt.user.server.rpc.RPC.encodeResponseForSuccess(RPC.java:474)
,位于com.google.gwt .user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:571)
,位于com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.ja va:208)
位于com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
位于com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet。 $ javax.servlet.http.HttpServlet.service $(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay .jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler .HandlerWrapper.handle(HandlerWrapper.java:152)
在org.mortbay.jetty .handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle (Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection $ RequestHandler.content(HttpConnection.java:843 )
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org。 (org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool $();
at org.mortbay.thread.QueuedThreadPool $ PoolThread.run(QueuedThreadPool.java:488)

我做的RPC如下:

  void getVacs(){
try {
homeService.getVacancies(new AsyncCallback< ArrayList< Vacancy>&g t;(){
public void onFailure(Throwable caught)
{
RootPanel.get(grayblock).add(new HTML(Failed:+ caught.getMessage()) );

$ b $ public void onSuccess(ArrayList< Vacancy> result)
{
RootPanel.get(grayblock).add(new HTML(result.get 0).getTitle()));
}
});
} catch(IllegalArgumentException e){
// TODO自动生成的catch块
e.printStackTrace();


$ / code $ / pre

我认为我已经完成了所有我需要做的空缺可序列化,以及作为RPC的返回类型的空缺ArrayList作为返回类型的空闲计数。对吧?我在做什么错了?



在此先感谢! 这通常是由于使用不可序列化的类引起的,如果您的类没有实现 com.google.gwt.user.client.rpc.IsSerializable 或者如果您忘记添加一个空的构造函数。



要传递一个bean,您必须满足以下要求(来自GWT站点):


  1. 它可以直接实现Java Serializable或GWT IsSerializable
    接口,也可以从超类
    派生出来。

  2. 它的非最终非瞬时实例字段本身是
    可序列化的它具有一个具有任何访问权限的默认(零参数)构造函数
    修饰符例如private Foo(){}将会工作)

即使您满足这些要求,GWT编译器可能会这样说:


未包含在该类型的集合中s可以是
序列化的SerializationPolicy或其Class对象不能
被加载。出于安全目的,这种类型不会被序列化。:
instance = @


这个问题可能有不同的原因。这里是他的一个完整的检查列表,用于解决问题:


  1. 验证类是否有默认构造函数(不带参数)
  2. >
  3. 确认类实现了Serializable或IsSerializable,或者
    实现了一个接口,该接口扩展了Serializable或扩展了一个实现Serializable的类b $ b

  4. 验证如果类不在客户端中,那么在
    编译GWT xml模块定义时,请验证该类是否在客户端。* package或...
  5. 默认情况下
    存在。如果您的课程在另一个包中,您必须将其添加
    来源。例如,如果你的班级在域名下。*你应该
    将它添加到xml中。请注意,类
    不能属于服务器包!有关GWT页面的更多详情:
    http://code.google .com / webtoolkit / doc / latest / DevGuideOrganizingProjects.html#DevGuideModuleXml
  6. 如果您要包含另一个GWT项目的类,则必须
    将inherits你的xml模块定义。例如,如果您的
    类Foo包含在com.dummy.domain包中,则必须将
    添加到模块定义中。
    更多详情:
    http:// code .google.com / webtoolkit / doc / latest / DevGuideOrganizingProjects.html#DevGuideInheritingModules

  7. 如果您包含另一个以
    a jar发布的GWT项目的类,请验证该jar还包含源代码,因为GWT
    还会重新编译传递给客户端的类的Java源代码。

PS :从 http://isolaso​​ftware.it/2011/03/22复制/ gwt-serialization-policy-error / ,因为该网站目前不可用。如果您想阅读原文,请使用上述网址从谷歌搜索并从谷歌网页缓存中读取它。


It's been a while since I've been doing GWT and I needed something small done quickly. I set things up and now I have a RPC I need, but it fails.

The RPC is supposed to give me a ArrayList, and Vacancy is located in #projectname#.client.model. The call is made in #projectname#.client.model.
The interfaces for my Services are in #project#name.client.Service.
Finally, the calls of course go to #projectname#.server.
Vacancy implements IsSerializable. The Exception I get from running my RPC is the following:

Starting Jetty on port 8888
[WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'firsteight.client.model.Vacancy' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = firsteight.client.model.Vacancy@15fdd2f
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:619)
    at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
    at com.google.gwt.user.client.rpc.core.java.util.Collection_CustomFieldSerializerBase.serialize(Collection_CustomFieldSerializerBase.java:44)
    at com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serialize(ArrayList_CustomFieldSerializer.java:39)
    at com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serializeInstance(ArrayList_CustomFieldSerializer.java:51)
    at com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serializeInstance(ArrayList_CustomFieldSerializer.java:28)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:740)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:621)
    at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:153)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:539)
    at com.google.gwt.user.server.rpc.RPC.encodeResponse(RPC.java:616)
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForSuccess(RPC.java:474)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:571)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

The RPC I make is the following:

void getVacs() {
    try {
        homeService.getVacancies(new AsyncCallback<ArrayList<Vacancy>>() {
            public void onFailure(Throwable caught)
            {
                RootPanel.get("grayblock").add(new HTML("Failed:" + caught.getMessage()));
            }

            public void onSuccess(ArrayList<Vacancy> result)
            {
                RootPanel.get("grayblock").add(new HTML(result.get(0).getTitle()));
            }
        });
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

I thought I had done all I needed to make Vacancy Serializable, and an ArrayList of Vacancy as returntype for the RPC counts as having Vacancy as return type.. right? What am I doing wrong?

Thanks in advance!

解决方案

This is normally caused by using a non-serializable class, which can occur if your class does not implement com.google.gwt.user.client.rpc.IsSerializable or if you have forgotten to add an empty constructor.

To pass a bean you have to fulfill the following requirements (from GWT site):

  1. It implements either Java Serializable or GWT IsSerializable interface, either directly, or because it derives from a superclass that does.
  2. Its non-final, non-transient instance fields are themselves serializable
  3. It has a default (zero argument) constructor with any access modifier (e.g. private Foo(){} will work)

Even if you fulfill these requirements may happen that GWT compiler say:

was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = @

The problem may have different causes. Here his a complete check list to use for solving the problem:

  1. Verify that the class has a default constructor (without arguments)
  2. Verify that the class implements Serializable or IsSerializable or implements an Interface that extends Serializable or extends a class that implement Serializable
  3. Verify that the class is in a client.* package or …
  4. Verify, if the class is not in client.* package, that is compiled in your GWT xml module definition. By default is present. If your class is in another package you have to add it to source. For example if your class is under domain.* you should add it to xml as . Be aware that the class cannot belong to server package! More details on GWT page: http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html#DevGuideModuleXml
  5. If you are including the class from another GWT project you have to add the inherits to your xml module definition. For example if your class Foo is in the package com.dummy.domain you have to add to the module definition. More details here: http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html#DevGuideInheritingModules
  6. If you are including the class from another GWT project released as a jar verify that the jar contains also the source code because GWT recompile also the Java source for the classes passed to the Client.

PS:copied from http://isolasoftware.it/2011/03/22/gwt-serialization-policy-error/ because the site is unavailable currently. If you want to read the original article search it from google using the above URL and read it from google web cache.

这篇关于GWT - RPC序列化异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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