Example of RMI-iiopejb Client
A Java RMI-IIOP client with a proprietary EJB server.
Package com. Wiley. compbooks. Roman. CORBA. helloworld;
Import javax. EJB .*;
Import javax. Naming .*;
Import javax. RMI .*;
Import java. util. properties;
Import javax. transaction. usertransaction;
/**
* This class is an example of client code that invokes
* Methods on a simple stateless Session Bean.
*/
Public class rmiclient {
Public static void main (string [] ARGs ){
Try {
/*
* Get System Properties for JNDI Initialization
*/
Properties props = system. getproperties ();
/*
* Use JNDI to look up the home object
*/
Context CTX = new initialcontext (props );
Hellohome home = (hellohome)
Javax. RMI. portableremoteobject. Narrow (
CTX. Lookup ("hellohome "),
Hellohome. Class );
/*
* Use JNDI to look up the JTA
* Usertransaction Interface
Java heaven
*/
Usertransaction usertran = (usertransaction)
CTX. Lookup ("javax. transaction. usertransaction ");
/*
* Start the transaction
*/
Usertran. Begin ();
/*
* Use the home object to create the hello EJB object
*/
Hello = home. Create ();
/*
* Call the hello () method, and print it
*/
System. Out. println (hello. hello ());
/*
* Done with EJB object, so remove it
*/
Hello. Remove ();
/*
* Commit the transaction
*/
Usertran. Commit ();
} Catch (exception e ){
E. printstacktrace ();
}
}
}
Example RMI-IIOP EJB Client
A corba client with a CORBA-based EJB server.
Package com. Wiley. compbooks. Roman. CORBA. helloworld;
Import java. util .*;
Import org. Omg. cosnaming .*;
Import org. Omg. costransactions .*;
Public class corbaclient {
Public static void main (string [] ARGs) throws exception {
/*
* Initialize the orb.
*
* A more portable way to do this is:
*
* Properties P = new properties ();
* P. Put ("org. Omg. CORBA. orbclass", <... orb class...> );
* Org. Omg. CORBA. Orb orb = org. Omg. CORBA. Orb. INIT (ARGs, P );
*/
Org. Omg. CORBA. Orb orb = com. Inprise. EJB. Global. Orb ();
/*
* Get a reference to a naming context
*/
Namingcontext context = namingcontexthelper. Narrow
(ORB. resolve_initial_references ("nameservice "));
/*
* Look up the home object using cos naming
*/
Namecomponent [] names = {New namecomponent ("hellohome ","")};
Hellohome = hellohomehelper. Narrow
(Context. Resolve (names ));
/*
* Get the corba ots current interface
* Controlling transactions
*/
Current currenttx = currenthelper. Narrow
(ORB. resolve_initial_references ("transactioncurrent "));
/*
* Begin the transaction
Java heaven
*/
Currenttx. Begin ();
/*
* Use the home object to create an EJB object
*/
Hello = hellohome. Create ();
/*
* Call a Business Method
*/
System. Out. println (hello. hello ());
/*
* Remove the EJB object
*/
Hello. Remove ();
/*
* Commit the transaction
*/
Currenttx. Commit (true );
}
}