传入RPC调用时发出异常

时间:2011-12-30 11:01:27

标签: java gwt serialization gwt-rpc

您好。我是java和GWT的新手。 我有RPC调用从Filenet获取一些值,我使用GWT,在哪里使用RPC调用,

我在FcInterface.java中有3个方法,它们扩展了remoteservices。接口中的2个方法正常工作,从serber返回值到客户端。但是第3种方法存在问题,我无法将服务器端的值返回给客户端。

附加代码n堆栈跟踪。

   Code:
    public class FilenetCmisServiceImpl extends RemoteServiceServlet implements FcInterface { 
    ...
    ...Some codes
    public Map<String, Object> getContentOfRootFolder(String RepositoryId) { 
    Map<String, Object> ContentOfRootFolder = new HashMap<String, Object>(); 
    ItemIterable<CmisObject> children = root.getChildren(); 
    for (CmisObject o : children) { 
       FilenetFolderImpl folder= new FilenetFolderImpl(); 
        folder.setFolderName(o.getName());
        folder.setFolderId(o.getId());
        folder.setFolderModifiedBy(o.getLastModifiedBy());
        folder.setFolderClass(o.getBaseTypeId().toString());
        folder.setFolderModifiedOn(o.getLastModificationDate());
        System.
        out.println("name : " + o.getName()); 
        ContentOfRootFolder.put(o.getName(), folder); 

        }// every thing is fine till here 
          return ContentOfRootFolder; 
      }
    }

FilenetFolderImpl类的代码

       public class FilenetFolderImpl  {

private String FolderName;
private String FolderSize;
private String FolderModifiedBy;
private GregorianCalendar FolderModifiedOn;
Folder root;
private String FolderId;
private String FolderClass;


public FilenetFolderImpl( String Foldername){

    this.FolderName=Foldername;

}
 public FilenetFolderImpl(String name, String id, String baseTypeId,
        GregorianCalendar lastModificationDate, String lastModifiedBy) {
    // TODO Auto-generated constructor stub
     this.FolderName = name;
     this.FolderId = id;
     this.FolderClass = baseTypeId;
     this.FolderModifiedBy = lastModifiedBy;
     this.FolderModifiedOn = lastModificationDate;

}
public FilenetFolderImpl() {
        // TODO Auto-generated constructor stub
}
public String getFolderName() {
    return FolderName;
    } 
    public void setFolderName(String FolderName) {
       this.FolderName=FolderName;
    }       
    public String getFolderId() {
        return FolderId;
    }
    public void setFolderId(String FolderId) {
       this.FolderId=FolderId;
    }       
    public String getFolderClass() {
        return FolderClass;
    }
    public void setFolderClass(String FolderClass){
       this.FolderClass=FolderClass;
    }     
    public String getFolderModifiedBy() {
        return FolderModifiedBy;
    }
    public void setFolderModifiedBy(String FolderModifiedBy) {
       this.FolderModifiedBy=FolderModifiedBy;
    }       
    public GregorianCalendar getFolderModifiedOn() {
        return FolderModifiedOn;
    }

    public void setFolderModifiedOn(GregorianCalendar gregorianCalendar) {
       this.FolderModifiedOn=gregorianCalendar;
    }
    protected Map<String, String> addFolder(){      
        Map<String, String> newFolderProperties = new HashMap<String, String>();
        newFolderProperties.put(PropertyIds.OBJECT_TYPE_ID,"cmis:folder");
        newFolderProperties.put(PropertyIds.NAME,FolderName);
         return newFolderProperties;    
    }       
     }

栈跟踪

      Exception while dispatching incoming RPC call
    Type 'com.filenet.cmis.server.FilenetFolderImpl' 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  =com.filenet.cmis.server.FilenetFolderImpl@eca5f5
      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.Map_CustomFieldSerializerBase.serialize(
   Map_CustomFieldSerializerBase.java:53) 
       at com.google.gwt.user.client.rpc.core.java.util.HashMap_CustomFieldSerializer.serialize(
     HashMap_CustomFieldSerializer.java:39) 
         at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(
RemoteServiceServlet.java:208) 
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(
RemoteServiceServlet.java:248) 

  Type 'com.filenet.cmis.server.FilenetFolderImpl' 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 = com.filenet.cmis.server.FilenetFolderImpl@eca5f5


 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.Map_CustomFieldSerializerBase.serialize(
 Map_CustomFieldSerializerBase.java:53) 
 at com.google.gwt.user.client.rpc.core.java.util.HashMap_CustomFieldSerializer.serialize(
 HashMap_CustomFieldSerializer.java:39) 
 at com.google.gwt.user.client.rpc.core.java.util.HashMap_CustomFieldSerializer.serializeInstance( HashMap_CustomFieldSerializer.java:51) 
 at com.google.gwt.user.client.rpc.core.java.util.HashMap_CustomFieldSerializer.serializeInstance(
 HashMap_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) 

我猜序列化存在问题,或者我无法使用ContentOfRootFolder发送FilenetFolderImpl的对象          Map<String, Object> ContentOfRootFolder = new HashMap<String, Object>(); 在任何情况下,我都需要返回FilenetFolderImpl

的值

请帮我解决这个问题。 谢谢。

2 个答案:

答案 0 :(得分:3)

您不能只在GWT-RPC中通过网络发送任何对象。只能传输GWT仿真库中包含的类和客户端使用的类。您必须创建DTO或将FilenetFolderImpl移动到客户端软件包(但您必须记住,GregorianCalendar也不包含在模拟库中,因此您必须对其进行一些操作)。

答案 1 :(得分:1)

要在客户端代码中使用FilenetFolderImpl类,它必须仅使用由GWT框架模拟的那些类。 GregorianCalendar使用的FilenetFolderImpl不是模拟类。

如果您打算在客户端和服务器之间进行交换,

FilenetFolderImpl需要实施Serializable

另请注意,FilenetFolderImpl必须位于您选择在客户端和服务器代码之间“共享”的包中。