查找时,RMI客户端抛出“错误解组返回”异常

时间:2014-07-17 17:07:39

标签: rmi

我有一个RMI应用程序在我的macbook-pro(10.9.2)上正常运行但是当我在Unix服务器上部署它时,客户端会抛出上述异常。我正在使用codebase属性,以便在远程计算机之间使用应用程序。

这是我在服务器端所拥有的(启动正常):

package engine;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import compute.Compute;

public class ComputeEngineStarter {

public static void main(String[] args) {
    System.setProperty("java.rmi.server.useCodebaseOnly", "false");       
    System.setProperty("java.rmi.server.codebase", Compute.class.getProtectionDomain().getCodeSource().toString());     
    System.setProperty("java.security.policy", "../security/server.policy");

    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new SecurityManager());
    }

    try {
    String name = "Compute";
        Compute engine = new ComputeEngine();
        Compute stub =
            (Compute) UnicastRemoteObject.exportObject(engine, 0);

    Registry registry = LocateRegistry.createRegistry(1099);           
    registry.rebind(name, stub);
    System.out.println("ComputeEngine bound");
    } catch (Exception e) {
        System.err.println("ComputeEngineStarter exception:");
        e.printStackTrace();
    }
}}

这就是我在客户端所拥有的:

package client;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.math.BigDecimal;

import compute.Compute;

public class ComputePi {

public static void main(String args[]) {        
    System.setProperty("java.rmi.server.useCodebaseOnly", "false");

    System.setProperty("java.rmi.server.codebase", Pi.class.getProtectionDomain().getCodeSource().getLocation().toString());

    System.setProperty("java.security.policy", "../security/clientAllPermission.policy");

    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new SecurityManager());
    }

    try {
        String name = "Compute";
        Registry registry = LocateRegistry.getRegistry();
        Compute comp = (Compute) registry.lookup(name); //this line throws the exception
        Pi task = new Pi(50);
        BigDecimal pi = comp.executeTask(task);
        System.out.println(pi);
    } catch (Exception e) {
        System.err.println("ComputePi exception:");
        e.printStackTrace();
    }
}    
}

完整的例外是:

ComputePi exception:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
    java.net.MalformedURLException: no protocol:               (file:/home/rm950/RMISecurityInvestigation/RMISecurityInvestigation2ServerSide/thirdParty/compute.jar
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at client.ComputePi.main(ComputePi.java:36)
 Caused by: java.net.MalformedURLException: no protocol: (file:/home/rm950/RMISecurityInvestigation/RMISecurityInvestigation2ServerSide/thirdParty/compute.jar
    at java.net.URL.<init>(URL.java:583)
    at java.net.URL.<init>(URL.java:480)
    at java.net.URL.<init>(URL.java:429)
    at sun.rmi.server.LoaderHandler.pathToURLs(LoaderHandler.java:770)
    at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:528)
    at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:646)
    at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:311)
    at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:257)
    at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1549)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1511)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
    ... 2 more

我知道我可能做了一些愚蠢的错误,在客户端寻求的协议就是我在服务器端设置的代码库属性。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

文件:代码库网址:

    除非客户端和服务器位于同一主机,否则
  • 不会起作用 如果客户端和服务器在同一主机中,则
  • 完全没有意义。

使用HTTP,或检查是否需要使用代码库功能。

相关问题