2014-07-17 43 views
0

我有一個RMI應用程序,它在我的macbook-pro(10.9.2)上運行正常,但是當我在Unix服務器上部署它時,客戶端拋出上述異常。我正在使用codebase屬性來查看遠程機器之間的應用程序。RMI客戶端在查找時拋出「error unmarshalling return」異常

這就是我對服務器端(它啓動罰款):

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 

我知道我可能在做一些愚蠢的錯誤,在客戶端尋求的協議是我設置爲鱈魚服務器端的ebase屬性。我怎樣才能解決這個問題?

回答

0

的文件:代碼URL:

  • 是行不通的,除非客戶端和服務器都在同一臺主機
  • 是完全沒有意義的,如果客戶端和服務器同一主機內。

使用HTTP,或查看是否需要使用代碼庫功能。

相關問題