rmi列表引用抛出“invalidclassexception”

o8x7eapl  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(226)

我们目前正在实现一个基于rmi的小型聊天服务器。
我们的客户机获取服务器示例并在服务器上注册它们自己。
服务器应该存储对所有客户机的引用,这就是服务器将它们存储在列表中的原因。
这就是问题所在。。。对于存储在服务器远程对象中的list/set/collection引用,我们总是会收到异常。而是使用原始数组。。。一切正常。
这就是我们的小服务器

public class Main extends UnicastRemoteObject {

    protected Main() throws RemoteException {}

    public static void main(String args[]){

        try {
            LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
            Naming.rebind("ChatServer", new ChatServerImpl());

            while(true){}

        } catch (Exception e){ System.out.println("An Exception occured : "+e.getMessage()); }
    }

下面是我们作为聊天服务器绑定的类。

public class ChatServerImpl implements ChatServer{

    public Set<ClientProxy> test = new HashSet<>(); // Without this it works fine

    @Override
    public boolean subscribeUser(ClientProxy handle) throws RemoteException {

        // add client
        return true;
    }

    @Override
    public boolean unsubscribeUser(ClientProxy handle) throws RemoteException {

        // remove client
        return true;
    }

    protected void sendMessage(String username, String message){
        System.out.println("Message received : "+username+" "+message);
    }
}

这会导致以下异常。。。

An Exception occured : RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.io.InvalidClassException: filter status: REJECTED

Process finished with exit code 0

知道为什么会这样吗?我们如何防止这个问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题