To instantiate a proxy without explicitly using the CORBA Naming Service, you use the String_To_Object function of the JaguarORB object in conjunction with interfaces defined in the SessionManager module. Before using the Manager, Session, and Factory interfaces, you need to use the EAServer Proxy wizard to create a proxy library project for the SessionManager module, build the project, and include the generated proxy library in the library list for the client target.
You use the SessionManager::Manager interface to interact with the server. You can identify the server using its Interoperable Object Reference (IOR) or its URL. The IOR string encodes the server’s host address and the port at which the server accepts IIOP requests. Each time a server is started, it writes a hex-encoded IOR string with standard encoding to two files for each listener, one containing the IOR string by itself, and the other containing the IOR as part of an HTML PARAM definition that can be inserted into an APPLET tag. The files reside in the HTML subdirectory of the EAServer directory. You can code the client to obtain the IOR string from one of these files.
After initializing the ORB and obtaining the IOR or URL of the server, use the String_To_Object function to convert the string to a CORBA object reference that you can convert to a reference to the Manager interface using the _Narrow function. Then use the createSession method of the Manager interface to create an authenticated session between the client application and the server.
Use the session’s lookup method to return a factory for proxy object references to the component you want to call. Then call the create method of the Factory object to obtain proxies for the component. The create method returns a CORBA object reference that you can convert into a reference to the component’s interface using the _Narrow function.
A component’s default name is the package name and the component name, separated by a slash, as in calculator/calc. However, you can specify a different name with the component’s com.sybase.jaguar.component.naming property. For example, you can specify a logical name, such as USA/MyCompany/FinanceServer/Payroll. For more information on configuring the naming service, see the EAServer documentation.
In this example, the first argument to the String_To_Object function includes the URLs for two servers in a cluster:
// PowerBuilder objects JaguarORB my_JaguarORB CORBAObject my_corbaobj n_bank_acct my_acct // Proxy objects Manager my_manager Session my_session Factory my_factory long ll_return my_JaguarORB = CREATE JaguarORB // Initialize the ORB ll_return = my_JaguarORB.init("ORBRetryCount=3, ORBRetryDelay=1000") // Convert a URL string to an object reference ll_return = my_JaguarORB.String_To_Object (''iiop://JagOne:2000;iiop://JagTwo:2000'', my_corbaobj) // Narrow the object reference to the Manager interface ll_return = my_corbaobj._narrow(my_manager, "SessionManager/Manager") // Create a session object reference my_session = my_manager.createSession("admin", "") // Create a Factory for proxy object references to // the remote interface my_corbaobj = my_session.lookup("Bank/n_bank_acct ") my_corbaobj._narrow(my_Factory, "SessionManager/Factory") // Obtain a proxy, narrow it to the remote // interface, and call a method my_corbaobj = my_Factory.create() my_corbaobj._narrow(my_acct, "Bank/n_bank_acct") my_acct.withdraw(1000.0)
In this example, the component is an EJB component. The home interface effectively performs the same role for the EJB that the factory interface does for a CORBA component:
JaguarORB my_orb CORBAObject my_corbaobj Manager my_mgr Session my_session CartHome my_cartHome Cart my_cart my_orb = CREATE JaguarORB my_orb.init("ORBLogFile='c:\temp\orblog'") my_orb.String_to_Object("iiop://svr1:2000", & my_corbaObj) my_corbaObj._narrow(my_mgr, "SessionManager/Manager" ) my_Session = my_mgr.createSession("admin", "") my_corbaObj = my_session.lookup("Cart") my_corbaObj._narrow(my_CartHome, "shopping/CartHome") my_corbaObj = my_CartHome.create() my_Cart.addItem()
Using a Connection object You can use the Lookup function on the Connection object to obtain a reference to the home interface of an EJB component. See “Invoking an EJB component method”.