File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Distributed Java and the fly likes Problem Executing RMI-IIOP Example : Provided by Sun Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Problem Executing RMI-IIOP Example : Provided by Sun" Watch "Problem Executing RMI-IIOP Example : Provided by Sun" New topic
Author

Problem Executing RMI-IIOP Example : Provided by Sun

Ankit Singhal
Greenhorn

Joined: Aug 13, 2004
Posts: 4
Hi

I am having problem executing the RMI-IIOP example as stated in the Getting Started Guide of Java

http://java.sun.com/j2se/1.4.2/docs/guide/rmi-iiop/tutorial.html

Here is the source code that i have writte :

Registry.java (The Server)
==================================================================
import java.rmi.Remote;
import java.rmi.RemoteException;
import javax.rmi.*;
import javax.naming.*;

public class Registry extends PortableRemoteObject implements RegistryIntf{

public Registry() throws RemoteException
{
super();
System.out.println("Inside Constructor");
}

public String sayHello() throws RemoteException
{
return "Hello";
}

public static void main(String arg[])
{


try{
Registry reg = new Registry();
Context initialNamingContext = new InitialContext();
initialNamingContext.rebind("Registry",reg );

System.out.println("The registered properly");
}

catch (Exception ex)
{
ex.printStackTrace();
}
}

}
==================================================================================
RegistryIntf.java (The Remote Interface Class

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface RegistryIntf extends Remote{

public String sayHello() throws RemoteException ;

}
=========================================================

Th client class

==========================================================

import java.rmi.RemoteException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import javax.rmi.*;
import java.util.Vector;
import javax.naming.NamingException;
import javax.naming.InitialContext;
import javax.naming.Context;

public class RegistryClient {

public static void main( String args[] ) {
Context ic;
Object objref;
RegistryIntf hi;

try {
ic = new InitialContext();

// STEP 1: Get the Object reference from the Name Service
// using JNDI call.
objref = ic.lookup("Registry");
System.out.println("Client: Obtained a ref. to Registry.");

// STEP 2: Narrow the object reference to the concrete type and
// invoke the method.
hi = (RegistryIntf) PortableRemoteObject.narrow(
objref, RegistryIntf.class);
hi.sayHello();

} catch( Exception e ) {
System.err.println( "Exception " + e + "Caught" );
e.printStackTrace( );
return;
}
}
}
==================================================

NOw as staed in the Tutorial is compiled all the classes using javac ..

Now I generated the syubs using rmic -iiop

Here first problem came , It didn'nt generated the Tie class , but in the example it is written that the Tie classes will be generrated.

Now I started my orbd with the given option

start orbd -ORBInitialPort 1050

now when i run my Server Program (Registry.java) the following exception is thrown .

java.rmi.StubNotFoundException: Stub class not found: Registry_Stub; nested exce
ption is:
java.lang.ClassNotFoundException: Registry_Stub
java.lang.ClassNotFoundException: Registry_Stub
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.rmi.server.RemoteProxy.loadClassFromClass(Unknown Source)
at sun.rmi.server.RemoteProxy.getStub(Unknown Source)
at sun.rmi.server.RemoteProxy.getStub(Unknown Source)
at sun.rmi.server.UnicastServerRef.setSkeleton(Unknown Source)
at sun.rmi.server.UnicastServerRef.exportObject(Unknown Source)
at sun.rmi.server.UnicastServerRef.exportObject(Unknown Source)
at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.exportObject
(Unknown Source)
at javax.rmi.PortableRemoteObject.exportObject(Unknown Source)
at javax.rmi.PortableRemoteObject.<init>(Unknown Source)
at Registry.<init>(Registry.java:10)
at Registry.main(Registry.java:24)

Now I made the stub by rmic Registry command : (Going against what is given in the Tutorial)

Now I again run the same Registry Program , it is throwing tthe below error:

java.lang.IllegalArgumentException: Only instances of org.omg.CORBA.Object can
e bound
at com.sun.jndi.cosnaming.CNCtx.callBindOrRebind(Unknown Source)
at com.sun.jndi.cosnaming.CNCtx.rebind(Unknown Source)
at com.sun.jndi.cosnaming.CNCtx.rebind(Unknown Source)
at javax.naming.InitialContext.rebind(Unknown Source)
at Registry.main(Registry.java:26)

So can any one help me out to explain why above error's are being thrown : and what is the solution

TIA
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Double check how you're generating the stub and tie with the rmic command... I was able to take the code you posted and generate both the stub and tie from it using "rmic -classpath . -iiop Registry".


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Ankit Singhal
Greenhorn

Joined: Aug 13, 2004
Posts: 4
Hi

I have run the rmic -iiop on the RegistryIntf not Registry class
and one more thing I added following lines

Context rootContext=(Context)initialNamingContext.lookup("");
System.out.println("The Look up suceeded");

to see whether it is able to look up the root context or not.
I saw that it is suceeded in finding the root context and print the message also , but again failed to rebind the object .thrwing following exception


D:\OMC-RAN\Hands On Coding\RMI -IIOP>java -classpath . -Djava.naming.factory.ini
tial=com.sun.jndi.cosnaming.CNCtxFactory -Djava.naming.provider.url=iiop://local
host:1050 Registry
Inside Constructor
The Look up suceeded
java.lang.IllegalArgumentException: Only instances of org.omg.CORBA.Object can b
e bound
at com.sun.jndi.cosnaming.CNCtx.callBindOrRebind(Unknown Source)
at com.sun.jndi.cosnaming.CNCtx.rebind(Unknown Source)
at com.sun.jndi.cosnaming.CNCtx.rebind(Unknown Source)
at javax.naming.InitialContext.rebind(Unknown Source)
at Registry.main(Registry.java:30)
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I was able to get the server to bind correctly using the same command... make sure that all the class files needed (including the tie and the stub) are in the current directory. Make sure the stub isn't the one that you initially built just using rmic (with no -iiop).

As long as Registry still extends PortableRemoteObject and implements RegistryIntf, as long as RegistryIntf still extends Remote, and as long as the tie and the stub are getting built correctly using rmic -iiop, there shouldn't be a problem.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem Executing RMI-IIOP Example : Provided by Sun