Hello,
I've got a ClassCastException problem when trying to get the correct object
instance using InitialContext.lookup() and PortableRemoteObject.narrow().
The situation is me having two applications, one carrying the SessionBean(s),
the other one a central MessageDrivenBean. While the business objects
repesented by the SessionBean-application might be updated from time to time
the MDB-application should be more or less "final". I therefore decided to
split them into the two applications, especially as further applications which
should be accessed through the MDB might follow, and I don't want to and can't
redeploy *all* Beans whenever a little thing in one business SessionBean
changes.
I therefore do a
| Object objRef;
| InitialContext ctx = new InitialContext();
| objRef = ctx.lookup("ejb/MyBean");
|
and get a "$ProxyXX" object back which is implementing correct remote Home
interface 'MyBeanHome' (I played a little with reflections to gather
information about Interfaces and methods).
Now if I'm trying
| MyBeanHome tmp;
| tmp = (MyBeanHome) PortableRemoteObject.narrow(objRef, MyBeanHome.class);
|
I get a ClassCastException; even wth
| Object tmp;
| tmp = PortableRemoteObject.narrow(objRef, MyBeanHome.class);
|
Using
| Obj tmp;
| tmp = objRef.getClass().getMethod("create", null).invoke(objRef, null);
|
'tmp' contains an object implementing Interface 'MyBean', which indicates
'objRef' in fact contains an object implementing 'MyBeanHome' and it's
'create()' knows what to do.
Sadly I can't cast this 'tmp' to 'MyBean' for invoking my 'dispose(...)' method
on it. I get a ClassCastException then as well.
| String tmp2;
| tmp2 = tmp.getClass().getMethod("dispose", new Class[] {...}).invoke(tmp,
new Object[] {...});
|
Gives me the correct result in 'tmp2', but I can't believe using reflections
all the way along is the way to go; I'd expect 'PortableRemoteObject.narrow()'
and having correctly typed object instances to be the intended solution.
Can anybody help me on this issue and tell my why my $ProxyXX-objects don't
"cooperate" and behave as I'd expect them to do?
Thanks in advance,
Peter
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3910148#3910148
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3910148
---
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
___
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user