The deal with regular casts vs. casts via .narrow() is this:
In EJB 1.0 (and thus, in the first edition of the Monson-Haefal book), RMI
was assumed to be the mechanism by which you communicated with an EJB. So in
this case, you use regular casts on your remote object references.
In EJB 1.1 (the present day, covered in the new second edition of the
Monson-Haefel book), the recommended mechanism by which you communicate with
an EJB became RMI-IIOP instead of regular RMI. With RMI-IIOP, you're
communicating with a remote EJB as if it were a remote CORBA object, so you
need to play in CORBA world, which means that you don't have the luxury of
using ordinary Java casts. Instead, you must use the
javax.rmi.PortableRemoteObject.narrow() method in order to do a CORBA-style
type conversion. In practice, the situation is vendor-specific, because some
vendors present the EJBs as CORBA objects, and some don't. And I believe
that some app servers will allow you to access the EJBs either way (although
I may be wrong about that... can anyone comment on this?).
It may seem like a step backward to lose the flexibility that RMI affords
us, but it really is a step forward, since (a) now any CORBA client (Java or
otherwise) can access the EJBs, (b) using IIOP as a transport mechanism
allows EJB to act as a nice way of implementing CORBA applications, and (c)
standardizing on IIOP as an external transport mechanism will allow for
standardization of communication between app servers from different vendors
(and if you believe THAT, I encourage you to go set up a cluster of app
servers from different vendors... ;-)
KurtC
-----Original Message-----
From: Steve Holder [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 15, 2000 9:53 PM
To: [EMAIL PROTECTED]
Subject: Re: JSP-EJB problem.
When and why should PortableRemoteObject.narrow() be used vs. a standard
cast? I've noticed that in the Monson-Haefal book, he uses standard casts
after doing JNDI lookups. That's the way we've been doing things here, and
it seems to work fine (though we haven't actually deployed any ejbs to
production servers, yet). Most other code snippets I've seen seem to use
.narrow(), but I haven't been able to find any explanation for why... all
the javadocs say for .narrow() is "Checks to ensure that an object of a
remote or abstract interface type can be cast to a desired type.", but we
seem to get the same effect by just trying to cast normally. Is there some
advantage to using .narrow() that I'm not aware of?
Steve Holder
-----Original Message-----
From: Christensen, Kurt [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 15, 2000 12:11 PM
To: [EMAIL PROTECTED]
Subject: Re: JSP-EJB problem.
Probably you need to NOT do an RMI-style (that is, ordinary Java) type cast
and use a CORBA type cast, which will look something like:
MyDesiredType castedObject =
(MyDesiredType)javax.rmi.PortableRemoteObject.narrow( passedObject,
<java.lang.Class object that corresponds to MyDesiredType>)
KurtC
-----Original Message-----
From: Amit Tyagi [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 15, 2000 7:01 PM
To: [EMAIL PROTECTED]
Subject: JSP-EJB problem.
Hi all,
We r using JSP-EJB platform. Application Server we r
using is Silver Stream 3.0. We have deployed JSP and
EJB to App. Server. But we r unable to make JavaBean
(used in JSP) talk to EJB.
We get correct initialContext and lookup is also
successfull. But when we try to type cast object
returned in the lookup to our home interface. it
generates class cast exception. What could be the
reason? Object returned is the stub of home interface.
Does Silverstream 3 supports Javabeans looking up for
EJB?
Thankx in advance
Bye
Amit Tyagi
reply to [EMAIL PROTECTED]
__________________________________________________
Do You Yahoo!?
Yahoo! Photos -- now, 100 FREE prints!
http://photos.yahoo.com
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".