简体   繁体   English

远程对象不支持RMI方法:java.rmi.UnmarshalException:无法识别的方法哈希

[英]RMI Method not supported by remote object: java.rmi.UnmarshalException: unrecognized method hash

I'm having a weird problem in my Bank - Client (server client via RMI) application. 我的“银行-客户端”(通过RMI的服务器客户端)应用程序出现问题。

I have Bank class that implements IBank extends Remote. 我有实现IBank扩展Remote的Bank类。 This Bank Class has several methods, checkClient, getBankAccount etc. 这个银行类有几种方法,checkClient,getBankAccount等。

The problem is, I can call the method checkClient (boolean) just fine from the clientside, all other methods give the UnmarshalException 问题是,我可以从客户端很好地调用方法checkClient(boolean),所有其他方法都提供UnmarshalException

Bank class on serverside: 服务器端的银行类:

public class Bank extends UnicastRemoteObject implements IBank { 

    private BankName bankName;

    private String URL;

    @Override
    public boolean checkClient(String username, String password) {
        Client client = db.getClient(username, password);

        if(client.getUsername() == null && client.getPassword() == null){
        System.out.println("Client not found in " + getBankName() + "database");
            return false;
        }

        System.out.println(client.toString() + " connected to bank succesfully");

        return true;
    }

    @Override
    public ArrayList<BankAccount> getAccounts(Client c) throws RemoteException {
       System.out.println("WORKED");
       return null;
    }
}

Interface implemented by Bank Class: 银行类实现的接口:

public interface IBank extends Remote{

    String getURL() throws RemoteException;

    String getBankName() throws RemoteException;

    boolean checkClient(String Username, String Password) throws RemoteException;

    ArrayList<BankAccount> getAccounts(Client c) throws RemoteException;
}

Serializable object used by Bankmethod: Bankmethod使用的可序列化对象:

public class BankAccount implements Serializable {

}

*above examples are just pieces of the complete application *以上示例只是完整应用程序的一部分

I can't figure out why the 'checkClient' method works just fine, and the getAccounts (and other methods not included in code above) give the UnmarshalException. 我不知道为什么'checkClient'方法可以正常工作,而getAccounts(以及上面代码中未包括的其他方法)给出了UnmarshalException。

Any help will be greatly appreciated 任何帮助将不胜感激

EXAMPLE

Below you can find the method I use to connect a Client to a Bank: 在下面,您可以找到我用来将客户连接到银行的方法:

@Override
public

ArrayList<BankAccount> connectToBank(Client c) throws RemoteException {
    assert(c != null);

    ArrayList<BankAccount> accounts;        

    if(!Bank.checkClient(c.Username, c.Password)){
        System.out.println("bank.checkclient == false, Client not found");
        return null;
    } else {
        System.out.println("Client found in " + Bank.getBankName() + " database");
    }

    System.out.println("Calling bank.getaccounts");
    accounts = Bank.getAccounts(c);

    if(accounts == null){
        System.out.println("No accounts found for " + c.Username);
    }

    return accounts;        
}

When I use a username and password that doesn't exist, console prints out: 当我使用不存在的用户名和密码时,控制台将输出:

Server IP Address: localhost
Server Port number 9000
Client: Registry located
Client: Bank and Publisher are bound
bank.checkclient == false, Client not found

and returns null; 并返回null;

However when I use a username and password that does exist, console prints out: 但是,当我使用确实存在的用户名和密码时,控制台将输出:

Server IP Address: localhost
Server Port number 9000
Client: Registry located
Client: Bank and Publisher are bound
Client found in RABO database
Calling bank.getaccounts
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Node.fireEvent(Node.java:8411)
    at javafx.scene.control.Button.fire(Button.java:185)
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.keyReleased(ButtonBehavior.java:136)
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.callAction(ButtonBehavior.java:106)
    at com.sun.javafx.scene.control.behavior.BehaviorBase.callActionForEvent(BehaviorBase.java:218)
    at com.sun.javafx.scene.control.behavior.BehaviorBase.lambda$new$74(BehaviorBase.java:135)
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$KeyHandler.process(Scene.java:3964)
    at javafx.scene.Scene$KeyHandler.access$1800(Scene.java:3910)
    at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2040)
    at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2501)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:197)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:147)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$353(GlassViewEventHandler.java:228)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:227)
    at com.sun.glass.ui.View.handleKeyEvent(View.java:546)
    at com.sun.glass.ui.View.notifyKey(View.java:966)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
    ... 49 more
Caused by: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:354)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$256(TCPTransport.java:683)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:276)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:253)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:162)
    at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
    at com.sun.proxy.$Proxy7.getAccounts(Unknown Source)
    at Client.Client.connectToBank(Client.java:240)
    at Client.FXMLClientController.btnLogIn_clicked(FXMLClientController.java:232)
    ... 59 more
Caused by: java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$256(TCPTransport.java:683)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    ... 1 more

So you can see the Bank.checkClient works fine, the Bank.getAccounts causes the problem 这样您就可以看到Bank.checkClient运行正常,Bank.getAccounts导致了问题

You've changed something about the remote interface without recompiling and redeploying everything. 您已经更改了有关远程接口的某些内容,而无需重新编译和重新部署所有内容。 Do a clean build, redeploy, retest. 做一个干净的构建,重新部署,重新测试。

I still haven't figured out the exact problem, however the problem occured exclusively when I was trying to send a custom object via RMI. 我仍然没有弄清楚确切的问题,但是当我试图通过RMI发送自定义对象时,该问题只发生了。 Methods that return String, boolean, int etc. from the Bank worked fine. 从银行返回String,boolean,int等的方法工作正常。 When I tried sendig a BankAccount (customobject) the problem occured. 当我尝试发送一个BankAccount(customobject)时,出现了问题。

I fixed it with merging the Client-project and the Bank-project together, now they use the exact same Interfaces and Classes so the Unmarshal-problem went away 我通过将客户项目和银行项目合并在一起来解决它,现在它们使用完全相同的接口和类,因此解组问题就消失了

hope this helps someone 希望这可以帮助某人

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.rmi.UnmarshalException:无法识别的方法hash:远程对象不支持的方法 - java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object 获取java.rmi.UnmarshalException:无法识别的方法哈希:远程对象不支持的方法 - Getting java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object RMI 调用中的 java.rmi.UnmarshalException - java.rmi.UnmarshalException in RMI call ResultSet错误java.rmi.UnmarshalException - ResultSet Error java.rmi.UnmarshalException RMI客户端无法查找服务器-java.rmi.UnmarshalException - RMI client cannot lookup server - java.rmi.UnmarshalException java.rmi.UnmarshalException:无法通过服务器提取客户端类 - java.rmi.UnmarshalException: unable to pull client classes by server javax.ejb.EJBException:嵌套异常是:java.rmi.UnmarshalException:找不到方法:&#39;helloWorld(Ljava.lang.Long; Ljava.util.List;)&#39; - javax.ejb.EJBException: nested exception is: java.rmi.UnmarshalException: Method not found: 'helloWorld(Ljava.lang.Long;Ljava.util.List;)' 在远程对象上调用方法时获取java.rmi.NoSuchObjectException - Getting java.rmi.NoSuchObjectException while invoking a method on remote object java.rmi.UnmarshalException: 解组参数错误; 嵌套异常是:java.lang.ClassNotFoundException: ServicesTableau - java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: ServicesTableau java.rmi.UnmarshalException:java.lang.ClassNotFoundException。 无法使用RMI从另一个物理JVM访问类 - java.rmi.UnmarshalException: java.lang.ClassNotFoundException. Can't get acces to class from another physical JVM using RMI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM