[jboss-user] [Beginner's Corner] - java.lang.ClassCastException when trying to access remote reference
Pasquale Imbemba
do-not-reply at jboss.com
Thu Feb 2 09:49:22 EST 2012
Pasquale Imbemba [https://community.jboss.org/people/pi4630] created the discussion
"java.lang.ClassCastException when trying to access remote reference"
To view the discussion, visit: https://community.jboss.org/message/714061#714061
--------------------------------------------------------------
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!
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/714061#714061]
Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120202/7021ec0d/attachment-0001.html
More information about the jboss-user
mailing list