i am surprised because i have two ejb on two deifferent server which are communicating together via remote interface and i don't need to use javax.rmi.PortableRemoteObject.narrow to cast the stub after the looking method. I can directly doing that :
(MyRemoteHome)initial.lookup("ejb/nameOfMyEjb"); Idem with ever java client connecting to the server and using the remote EJB. I don't understand because every documents i read explain that it's necessary to use PortableRemoteObject to cast the stub. But it's seem to be not necessary when the remote object is a java object. I woul be very happy to know your point of view about that.
Thank you very much
In most of the casses, the EJBs are remotley exposed through RMI. You can have JRMP RMI and IIOP RMI. For IIOP RMI you need to do the narrowing that marshalls the IDLs (used by the IIOP) to/from java classes. JRMP RMI uses a java native protocol and no marshalling is needed, so you can directly do the casting. The narrowing on JRMP RMI it bassically does nothing, just returns the same object.
Most native Java RMI protocols (JRMP and protocols specifically designed by application servers) make use of Java's dynamic class loading to load the stub of the correct runtime type at runtime, so you can do normal casting. Protocols like IIOP that are designed to support systems with no dynamic class loading do not support this feature. So when an IIOP remote stub is returned it does not have the correct runtime type to begin with. You have to explicitly cast it to the type of stub you want.
Because EJB is designed to support IIOP (as well as JRMP and such native protocols) you have to use PortableRemoteObject.narrow if you want your code to be compliant. If you don't, then if you move to some other application server your application may stop working
In both scenarios you described both JRMP and IIOP (as well as other protocols) can be used by the server for communication. It is up to the server to decide which protocol to use. Whether you make calls from within a server of from a J2EE client, you use the stubs generated by the server. These stubs implement whatever protocol the server wants to use.
In addition, EJB servers must be capable of supporting IIOP requests (even if the server uses JRMP for normal communication) so that EJBs can be invoked by non-Java clients using CORBA.
i have read documentation about rmic compiler. If the option -iiop is chosen then stub using iiop are generated and remote proxy are no more skeleton class but tie class (http://java.sun.com/j2se/1.4.2/docs/guide/rmi-iiop/rmi_iiop_pg.html). Sun one application server uses -iiop options. So how can i cast without javax.rmi.PortableRemoteObject.narrow even if iiop seems to be used ?
thank a lot