RMI exception "error marshalling arguments"
Asked Answered
O

3

5

I'm working on a RMI project that has two separated projects for Client and Server. I used start rmiregistry. When I try to run my Server application, I get an exception.

public class Runner extends UnicastRemoteObject {

    public Runner() throws RemoteException {
        try {
            ServerOperations so = new ServerSide();
            Naming.rebind("rmi://localhost:2000/MiveCoffeeService", so);
            System.out.println("Server is online.");

        } catch (RemoteException | MalformedURLException | FileNotFoundException ex) {
            Logger.getLogger(Runner.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void main(String[] args) throws RemoteException {
        new Runner();
    }

}

The exceptions are:

Sep 11, 2015 9:05:51 PM ir.nscogroup.coffeemive.Runner <init>
SEVERE: null
java.rmi.MarshalException: error marshalling arguments; nested exception is: 
    java.io.NotSerializableException: dataaccess.ServerSide
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at java.rmi.Naming.rebind(Naming.java:177)
    at ir.nscogroup.coffeemive.Runner.<init>(Runner.java:29)
    at ir.nscogroup.coffeemive.Runner.main(Runner.java:38)
Caused by: java.io.NotSerializableException: dataaccess.ServerSide
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
    ... 4 more

What is wrong?

Ona answered 11/9, 2015 at 16:52 Comment(0)
O
-1

thank you guys. this sample solved my problem.

package com.javacodegeeks.core.rmi.rminterface;

public class Configuration {

    public static final int REMOTE_PORT = 8888;
    public static final String REMOTE_ID = "RMI_EXAMPLE";
    public static final String REMOTE_HOST = "localhost";

}


package com.javacodegeeks.core.rmi.remoteserver;

import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import com.javacodegeeks.core.rmi.rminterface.Configuration;

public class RemoteServer {

    public static void main(String[] args) throws RemoteException, AlreadyBoundException {

        RMIImplementation rmiImplementation = new RMIImplementation();
        Registry registry = LocateRegistry.createRegistry(Configuration.REMOTE_PORT);
        registry.bind(Configuration.REMOTE_ID, rmiImplementation);
    }
}
Ona answered 11/9, 2015 at 18:23 Comment(1)
This sample doesn't have anything to do with your problem. It's not materially different what you had already posted.Grind
R
7

The exception stacktrace is telling you exactly what is wrong:

java.io.NotSerializableException: dataaccess.ServerSide

You're trying to serialize a non-serializable class, dataaccess.ServerSide. Solution: make your class and all necessary constituent classes implement the Serializable interface.

Retread answered 11/9, 2015 at 16:53 Comment(1)
It is also worth mentioning that if some instance variables of serializable object can not or should not be serialized they should be marked with transient keywordMaugre
G
3

The problem here is that ServerSide is neither an exported remote object nor Serializable. Almost certainly you intended the former, so you must either:

  • make it extend UnicastRemoteObject, or
  • export it manually yourself before binding, via UnicastRemoteObject.exportObject().

NB not both.

Grind answered 28/9, 2015 at 12:26 Comment(0)
O
-1

thank you guys. this sample solved my problem.

package com.javacodegeeks.core.rmi.rminterface;

public class Configuration {

    public static final int REMOTE_PORT = 8888;
    public static final String REMOTE_ID = "RMI_EXAMPLE";
    public static final String REMOTE_HOST = "localhost";

}


package com.javacodegeeks.core.rmi.remoteserver;

import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import com.javacodegeeks.core.rmi.rminterface.Configuration;

public class RemoteServer {

    public static void main(String[] args) throws RemoteException, AlreadyBoundException {

        RMIImplementation rmiImplementation = new RMIImplementation();
        Registry registry = LocateRegistry.createRegistry(Configuration.REMOTE_PORT);
        registry.bind(Configuration.REMOTE_ID, rmiImplementation);
    }
}
Ona answered 11/9, 2015 at 18:23 Comment(1)
This sample doesn't have anything to do with your problem. It's not materially different what you had already posted.Grind

© 2022 - 2024 — McMap. All rights reserved.