What is going wrong here concerning the "bindings"
Learning server stuff and testing some basic applications from the Corejava II book.
Here is the error code when "Naming.bind" two strings called toaster and microwave:
ProductImpl p1 = new ProductImpl("Blackwell Toaster");
Naming.bind("toaster", p1);
(see the productserver class of the liste code):
Constructing server implementations...
Binding server implementations to registry...
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
Error: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: serverstuff.Product
java.lang.ClassNotFoundException: serverstuff.Product
at sun.rmi.server.UnicastServerRef.oldDispatch(Unicas tServerRef.java:400)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:248)
at sun.rmi.transport.Transport$1.run(Transport.java:1 59)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport. java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)
at sun.rmi.transport.StreamRemoteCall.exceptionReceiv edFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(Str eamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:3 59)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at serverstuff.ProductServer.main(ProductServer.java: 40)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: serverstuff.Product
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknow n Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(Unicas tServerRef.java:390)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:248)
at sun.rmi.transport.Transport$1.run(Transport.java:1 59)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport. java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.ClassNotFoundException: serverstuff.Product
at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 47)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
at sun.rmi.server.LoaderHandler.loadProxyInterfaces(L oaderHandler.java:709)
at sun.rmi.server.LoaderHandler.loadProxyClass(Loader Handler.java:653)
at sun.rmi.server.LoaderHandler.loadProxyClass(Loader Handler.java:590)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(RM IClassLoader.java:628)
at java.rmi.server.RMIClassLoader.loadProxyClass(RMIC lassLoader.java:294)
at sun.rmi.server.MarshalInputStream.resolveProxyClas s(MarshalInputStream.java:242)
at java.io.ObjectInputStream.readProxyDesc(ObjectInpu tStream.java:1535)
at java.io.ObjectInputStream.readClassDesc(ObjectInpu tStream.java:1491)
at java.io.ObjectInputStream.readOrdinaryObject(Objec tInputStream.java:1748)
at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1327)
at java.io.ObjectInputStream.readObject(ObjectInputSt ream.java:349)
... 12 more
package serverstuff; /** * The interface for remote product objects. * Gets the description of this product. * @return the product description * */ import java.rmi.*; public interface Product extends Remote { String getDescription() throws RemoteException; }
package serverstuff; /** * This server program instantiates two remote * objects, registers them with the naming service, * and waits for clients to invoke methods on the * remote objects. * */ /** * @version 1.10 1999-08-21 * @author Cay Horstmann */ import java.rmi.*; import java.rmi.server.*; public class ProductServer { public static void main(String args[]) { try { System.out.println ("Constructing server implementations..."); ProductImpl p1 = new ProductImpl("Blackwell Toaster"); ProductImpl p2 = new ProductImpl("ZapXpress Microwave Oven"); System.out.println ("Binding server implementations to registry..."); Naming.rebind("toaster", p1); Naming.rebind("microwave", p2); System.out.println ("Waiting for invocations from clients..."); } catch(Exception e) { System.out.println("Error: " + e); e.printStackTrace(); } } }
package serverstuff; /** * @version 1.00 1996-09-07 * @author Cay Horstmann * This is the implementation class * for the remote product * Constructs a product implementation * @param n the product name * */ import java.rmi.*; import java.rmi.server.*; public class ProductImpl extends UnicastRemoteObject implements Product { public ProductImpl(String n) throws RemoteException { name = n; } public String getDescription() throws RemoteException { return "I am a " + name + ". Buy me!"; } private String name; }