简体   繁体   中英

Having trouble coding RMI client callback from server - UnmarshalException ClassNotFoundException

I will try to keep this post as small as possible so I will add more information and code if requested.

Scenario: I am writing a server/client application to track some of our processes here in the company, so the user will create small tags that will go from one user's screen to another (clients written in Swing) according to the workflow.

I am running a local Glasfish 3.1 server (in Eclipse) and MySql. On the server I am running Spring MVC and Spring Data + Hibernate.

A property file holds this information for easy change:

rmi.serverPort = 1971
rmi.clientPort = 2010

During the server start up there's a bean that sets the RMI environment like this:

  @Autowired
  private RmiData rmiData;
  @Autowired
  private DataRequestHandler dataRequestHandler;
  @Autowired
  private ConnectionRequestHandler connectionRequestHandler;
  .
  .
  .

  LocateRegistry.createRegistry(rmiData.getServerPort());
  String rmiUrl = "rmi://" + rmiData.getHost() + ":" + rmiData.getServerPort() + "/";
  Naming.rebind(rmiUrl + "ConnectionRequestHandler", connectionRequestHandler);
  Naming.rebind(rmiUrl + "DataRequestHandler", dataRequestHandler);

This is working with no SecurityManager and no Policy file. Although I had to include the Hibernate jars into the client to solve other exceptions (solution found here on SO).

After making the client connecting to the server and requesting data work, I started to code the callback to the client (the server will have to push data to the client as well). So this is where I am stuck now.

Here is how I am making the callback (the client acts like a server):

  private ClientCallbackHandler clientCallbackHandler = new ClientCallbackHandlerImpl();
  .
  .
  .

  LocateRegistry.createRegistry(rmiData.getClientPort());
  String rmiUrl = "rmi://localhost:" + rmiData.getClientPort() + "/";
  Naming.rebind(rmiUrl + "ClientCallbackHandler", clientCallbackHandler);

So when the server performs

  String rmiUrl = "rmi://" + clientHost + ":" + clientPort + "/";
  clientCallbackHandler = (ClientCallbackHandler)Naming.lookup(rmiUrl + "ClientCallbackHandler");

I get the following exception 收到以下异常

  SEVERE: java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
java.lang.ClassNotFoundException: br.com.affair.socontrol.rmi.ClientCallbackHandlerImpl (no security manager: RMI class loader disabled)

I am avoiding installing the SecurityManager and Policy file (also tried that with no success) and I am stuck right here.

I cannot understand why is the server complaining about the implementation class once all it needs is the interface. Any help is much appreciated. Thanks.

After struggling with this for several hours I finally found the problem.

The ClientCallbackHandlerImpl class WAS NOT extending UnicastRemoteObject . After that the code ran smoothly. Thank you who read the post and thought about something.

PS: I know it looks like a noob's fault but I avoid doing code copy/paste.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM