IIOP impl. export ok but toStub() failed, NoSuchObjectException!!!
My jre version is 1.4.2_05-b04. I'm using IIOP implementation with RMI.
I created my remote service, and then export the service with PortableRemoteObject.exportObject(), everything seemd ok. But when I try to get service stub with PortableRemoteObject.toStub(), I got a NoSuchObjectException indicating my service was not exported!!! But why exportObject() did throw any exception?
Here is my code:
package wuwei.rmi.server;
import java.io.IOException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Enumeration;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import wuwei.rmi.intf.EchoServiceIF;
publicclass Server
{
staticprivatefinal Properties sysProps =new Properties();
static
{
initialization();
}
privatestaticboolean initialization()
{
// 1. load properties from config file
try
{
sysProps.load( ClassLoader.getSystemResourceAsStream("config.ini") );
}
catch (IOException ioe)
{
ioe.printStackTrace();
returnfalse;
}
System.out.println("read properties from config file:");
for (Enumeration names = sysProps.propertyNames();
names.hasMoreElements(); )
{
String prop_name = (String) names.nextElement();
String prop_value = sysProps.getProperty(prop_name);
System.out.println(prop_name +"=" + prop_value);
}
System.out.println("-\n");
// 2. set codebase system property
System.setProperty(
"java.rmi.server.codebase",
sysProps.getProperty("java.rmi.server.codebase")
);
returntrue;
}
publicstaticvoid main(String[] args)
{
// 1. create service object
EchoServiceIF service =new EchoServiceImpl();
System.out.println("create service ok.");
// 2. export to be available for IIOP invocation
Remote _stub =null;
try
{
PortableRemoteObject.exportObject(service);
_stub = (Remote) PortableRemoteObject.toStub(service);
System.out.println("export service ok.");
}
catch (RemoteException re)
{
re.printStackTrace();
return;
}
// 3. bind stub to Registry
Context namingCtx =null;
try
{
namingCtx =new InitialContext(sysProps);
namingCtx.rebind("echo", _stub);
System.out.println("bind service to RMI Registry ok.");
}
catch (NamingException ne)
{
ne.printStackTrace();
}
finally
{
try{
if (namingCtx !=null){
namingCtx.close();
}
}catch (NamingException ne){
ne.printStackTrace();
}
}
}
}
Here is the config file config.ini:
java.rmi.server.codebase=http://192.168.1.66:8080/RMI_codebase/codebase.jar
java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory
java.naming.provider.url=iiop://localhost:1050
Is there anyone who can help me? Thank you very much!

