I'm trying to access a reference (SLSB that implements a remote interface) from a remote client.
try {
Context ctxt = new InitialContext(p);
ArrayList<String> listOfBeans = getBeanNames("Bean", ctxt);
for (int i = 0; i < listOfBeans.size(); i++) {
NamingEnumeration<Binding> b = ctxt.listBindings(listOfBeans.get(i));
while (b.hasMore()) {
Binding bind = b.next();
if (bind.getName().contains(string.toString().subSequence(0, string.toString().length()))) {
Object ref = bind.getObject();
doer = (IDoSmthg) PortableRemoteObject.narrow(ref, IDoSmthg.class);
doer = (IDoSmthg)ref;
return doer;
}
}
}
} catch (NamingException nE) {
nE.printStackTrace();
}
return null;
}
According to JNDI API, getObject() retrieves the object bound to the name of the binding.
From the API book available online:
When you use Context.listBindings(), you get back an enumeration of Binding(in the API reference documentation). You can invoke getObject()(in the API reference documentation) on each
Binding to obtain the object in that binding. The result of getObject() is the same as that obtained by looking up the object by using Context.lookup()(in the API reference documentation).
So I'd expect that the narrowing would have been working. But it can't cast it, I get a javax.naming.Reference cannot be cast to org.omg.CORBA.Object Exception. In Debug, I see that what getObject() returns me, is a javax.naming.Reference.
How do I get this casted correctly, so to make a call on it? I know this is not the documented way to do it, but my approach shall solve: I know the Interface, search the bean on JNDI that implements it, get the reference, make the call.
Thanks in advance!