The following topics describe running the sample files delivered with the product and provide examples that illustrate how the connector invokes the services of a JAR file to create business objects.
The sample files are located in the ProductDir\connectors\EJB\samples directory, where ProductDir represents the directory where the connector is installed.
It is a requirement that the WebSphere Application Server Thin Client must be installed for the adapter to remotely access the beans deployed on the server.
The sample files illustrate a simple session bean, MusicCart, that provides a home interface, remote interface, bean and two helper classes, RecordingHelper and CustomerHelper. The sample files also include two connector configuration files: BIA_EJBConnector.cfg, which contains the connector properties settings for the example to run properly; and BIA_PortConnector.cfg, which contains the connector properties for the test connector.
The MusicCart sample bean has methods that take a Java object as an input parameter and return an object as output. It also has methods that take an object array as an input, illustrating how the adapter handles array management. The sample also demonstrates how the adapter performs data handler processing.
Included in the sample files is a business object file (BIA_SampleMusicCartBO.bo) and EJB source files (in ProductDir\connectors\EJB\samples\SampleMusicCartEJB\src), which show how EJB remote and home classes are mapped to business objects using the ODA for EJB. By sending BIA_SampleMusicCartBO.bo from the test connector to the application server, you can see how the addRecording, getFirstRecordInfo, modifyMusicRequestUsingDataHandler, and getAllRecordInfo methods are executed and how the connector handles request processing.
The following steps assume that you are running the connector to exchange business objects with enterprise beans deployed on WebSphere Application Server 5.0.
As the connector runs, you can observe how the enterprise bean methods defined in the sample files are executed from the adapter to invoke services provided by the remote WebSphere Application Server.
The following sample code is an excerpt from the EJB JAR file that defines the methods of the EJB class called MusicCartBean. Notice the method defined at the end of the code sample: getCustomer.
The business object that corresponds to this code is illustrated in Figure 4.
public class MusicCartBean implements SessionBean { CustomerHelper customerHelper; ArrayList shoppingList; RecordingHelper[] recordHelperArr; // EJB Methods public void ejbRemove() {} public void ejbActivate() {} public void ejbPassivate() {} public void setSessionContext (SessionContext ctx) {} public void ejbCreate(String person,String password, String email) throws CreateException { if (person == null || person.equals("")) { throw new CreateException( "Name cannot be null or empty."); } else { customerHelper = new CustomerHelper(person, password, email); customerHelper.setName(person); customerHelper.setEmail(email); customerHelper.setPassword(password); } shoppingList = new ArrayList(); } public void ejbCreate(CustomerHelper customerHelper) throws CreateException { customerHelper.setName(customerHelper.name); customerHelper.setEmail(customerHelper.email); customerHelper.setPassword(customerHelper.password); shoppingList = new ArrayList(); } // Business methods implementation public CustomerHelper getCustomer() { return customerHelper; }
The following sample screen illustrates the business object structure that corresponds to the source code presented in EJB JAR file code. This business object is created by the ODA, which discovers the objects and constructs defined in the original EJB JAR file and generates corresponding business objects. For information about how to use the ODA to generate this example, see Creating and modifying business objects.
Notice the fourth attribute, getCustomer. This attribute contains a complex method object that corresponds to the getCustomer method defined at the end of the sample code for the MusicCartBean class, presented in EJB JAR file code.