PortableRemoteObject.narrow() return null when I connect to
wangdongfox Aug 19, 2009 3:29 AMMy environment: JBoss 5.1.0GA, JDK 1.5.0_12(Linux)
Client side environment: JDK1.5.0_12(Windows),Eclipse
I want to connect to an EJB remotely through IIOP, the following is the details:
1. in jboss.xml, I have added the iiop item in it
---------------------------------------------------------------
<?xml version="1.0"?>
<enterprise-beans>
<ejb-name>OTSEjb2StatelessBean</ejb-name>
<jndi-name>OTSEjb2StatelessBean</jndi-name>
<invoker-bindings>
<invoker-proxy-binding-name>iiop</invoker-proxy-binding-name>
</invoker-bindings>
---------------------------------------------------------------
2. The client side program is like the following:
---------------------------------------------------------------
Properties prop = new Properties();
prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.iiop.naming.ORBInitialContextFactory"); prop.setProperty(Context.PROVIDER_URL,"iiop://10.10.135.212:3528");
try {
Context ctx = new InitialContext(prop);
Object obj = ctx.lookup("corbaname:iiop:10.10.135.212:3528#OTSEjb2StatelessBean");
System.out.println(obj.getClass());
if(obj instanceof MyHome){
System.out.println("OK");
}
else{
System.out.println("The classloader of Obj:" + obj.getClass().getClassLoader());
System.out.println("The classloader of MyHome:" + MyHome.class.getClassLoader());
}
MyHome home = (MyHome)PortableRemoteObject.narrow(obj,MyHome.class);
System.out.println(home);
MyRemote remote = home.create();
System.out.println(remote.foo("","",false,args));
}
......
---------------------------------------------------------------
3. I have added all of the jars in the $JBOSS_HOME/client and /common in the client side classpath.
But the result is strange.
I find obj can be found from the jboss, but the result of PortableRemoteObject.narrow() is null, and I find the instance type of obj is "com.sun.corba.se.impl.corba.CORBAObjectImpl", the following is the details:
---------------------------------------------------------------
class com.sun.corba.se.impl.corba.CORBAObjectImpl
The classloader of Obj:null
The classloader of MyHome:sun.misc.Launcher$AppClassLoader@133056f
null
Exception in thread "main" java.lang.NullPointerException
at iets.com.RemoteEJBConnTest.testIIOP(RemoteEJBConnTest.java:90)
at iets.com.RemoteEJBConnTest.main(RemoteEJBConnTest.java:121)
---------------------------------------------------------------
I have struggled about 1 day, but no any progress, any idea about it? Thanks a lot.