This is an example of a remote client that calls methods of the Calculator enterprise bean that is part of the Calculator application. For more information about the Calculator application, see Creating Your First J2EE Application.
Implementation consists of two major tasks:
· Obtaining a reference to the Calculator bean by creating an InitialContext.
· Looking up the home interface of the bean and creating a bean instance out of it.
The following code performs these tasks:
//Create initial context properties Properties p = new Properties();
//Specify the type of the initial context factory. Here we specify that //we are using the CORBA naming services. p.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
//Specify the provider URL. p.put(Context.PROVIDER_URL, "<Server_Host>:<p4_port>");
//Specify the security principal (user). p.put(Context.SECURITY_PRINCIPAL, "Administrator");
//Specify the security credentials (password). p.put(Context.SECURITY_CREDENTIALS, "");
// Connect to server by the initial context. Context initialContext = new InitialContext(p);
//Lookup the Calculator bean. //“sap.com” is the provider name. The default provider name for //all examples on the J2EE Engine is “sap.com”. //“Calc” is the display name of the Calculator example. //“Calculator” is the display name of the Calculator bean. CalcHome home = (CalcHome)initialContext.lookup("sap.com/Calc/Calculator");
//Create an instance of the bean from the home interface. CalcBean bean = home.create();
//Then call a method of the Calculator. bean.add(1,1); |