Entering content frame

This graphic is explained in the accompanying text Implementing a Client That Invokes an Enterprise JavaBean Locate the document in its SAP Library structure

This is an example of a remote client that looks up the Calculator bean, which is part of the Calculator application, and calls methods of it. The Calculator application is included in the default application of the SAP J2EE Engine.

Implementation consists of two major tasks:

·        Obtaining a reference to the Calculator bean by creating initial context.

·        Looking up the home interface of the bean and creating an instance of it, which allows the client to call methods on it.

The following code performs these tasks:

This graphic is explained in the accompanying text

//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 SAP 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);

 

 

 

Leaving content frame